Skip to content

Commit

Permalink
Error handling for getting and setting parameter values
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Nov 13, 2023
1 parent 9470c0b commit 5ec7e3d
Showing 1 changed file with 65 additions and 16 deletions.
81 changes: 65 additions & 16 deletions x/ccv/consumer/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,67 @@ func (k Keeper) GetParams(context.Context) (stakingtypes.Params, error) {

// GetEnabled returns the enabled flag for the consumer module
func (k Keeper) GetEnabled(ctx sdk.Context) bool {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'enabled': %v", err)
return params.Enabled
}
return params.Enabled
}

func (k Keeper) GetBlocksPerDistributionTransmission(ctx sdk.Context) int64 {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'BlocksPerDistributionTransmission': %v", err)
return params.BlocksPerDistributionTransmission
}

return params.BlocksPerDistributionTransmission
}

func (k Keeper) SetBlocksPerDistributionTransmission(ctx sdk.Context, bpdt int64) {
params, err := k.GetConsumerParams(ctx)
if err != nil {
//TODO @bermuell: Check behaviour for error case
k.Logger(ctx).Error("error setting parameter 'BlocksPerDistributionTransmission': %v", err)
return
}
params.BlocksPerDistributionTransmission = bpdt
k.SetParams(ctx, params)
}

func (k Keeper) GetDistributionTransmissionChannel(ctx sdk.Context) string {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'DistributionTransmissionChannel': %v", err)
return params.DistributionTransmissionChannel
}
return params.DistributionTransmissionChannel
}

func (k Keeper) SetDistributionTransmissionChannel(ctx sdk.Context, channel string) {
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error setting parameter 'DistributionTransmissionChannel': %v", err)
return
//TODO @bermuell: Check behaviour for error case
}
params.DistributionTransmissionChannel = channel
k.SetParams(ctx, params)
}

func (k Keeper) GetProviderFeePoolAddrStr(ctx sdk.Context) string {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'ProviderFeePoolAddrStr': %v", err)
return params.ProviderFeePoolAddrStr
}
return params.ProviderFeePoolAddrStr

}

func (k Keeper) SetProviderFeePoolAddrStr(ctx sdk.Context, addr string) {
params, err := k.GetConsumerParams(ctx)
if err != nil {
//TODO @bermuell: Check behaviour for error case
k.Logger(ctx).Error("error setting parameter 'ProviderFeePoolAddrStr': %v", err)
return
}
params.ProviderFeePoolAddrStr = addr
Expand All @@ -96,13 +113,21 @@ func (k Keeper) SetProviderFeePoolAddrStr(ctx sdk.Context, addr string) {

// GetCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets
func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'CcvTimeoutPeriod': %v", err)
return params.CcvTimeoutPeriod
}
return params.CcvTimeoutPeriod
}

// GetTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets
func (k Keeper) GetTransferTimeoutPeriod(ctx sdk.Context) time.Duration {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'TransferTimeoutPeriod': %v", err)
return params.TransferTimeoutPeriod
}
return params.TransferTimeoutPeriod

}
Expand All @@ -111,14 +136,22 @@ func (k Keeper) GetTransferTimeoutPeriod(ctx sdk.Context) time.Duration {
// address during distribution events. The fraction is a string representing a
// decimal number. For example "0.75" would represent 75%.
func (k Keeper) GetConsumerRedistributionFrac(ctx sdk.Context) string {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'ConsumerRedistributionFraction': %v", err)
return params.ConsumerRedistributionFraction
}
return params.ConsumerRedistributionFraction

}

// GetHistoricalEntries returns the number of historical info entries to persist in store
func (k Keeper) GetHistoricalEntries(ctx sdk.Context) int64 {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'HistoricalEntries': %v", err)
return params.HistoricalEntries
}
return params.HistoricalEntries
}

Expand All @@ -127,7 +160,7 @@ func (k Keeper) GetHistoricalEntries(ctx sdk.Context) int64 {
func (k Keeper) SetUnbondingPeriod(ctx sdk.Context, period time.Duration) {
params, err := k.GetConsumerParams(ctx)
if err != nil {
//TODO @bermuell: Check behaviour for error case
k.Logger(ctx).Error("error setting parameter 'UnbondingPeriod': %v", err)
return
}
params.UnbondingPeriod = period
Expand All @@ -136,23 +169,39 @@ func (k Keeper) SetUnbondingPeriod(ctx sdk.Context, period time.Duration) {

// GetUnbondingPeriod returns the unbonding period of the consumer
func (k Keeper) GetUnbondingPeriod(ctx sdk.Context) time.Duration {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'UnbondingPeriod': %v", err)
return params.UnbondingPeriod
}
return params.UnbondingPeriod
}

// GetSoftOptOutThreshold returns the percentage of validators at the bottom of the set
// that can opt out of running the consumer chain
func (k Keeper) GetSoftOptOutThreshold(ctx sdk.Context) string {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'SoftOptOutThreshold': %v", err)
return params.SoftOptOutThreshold
}
return params.SoftOptOutThreshold
}

func (k Keeper) GetRewardDenoms(ctx sdk.Context) []string {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'RewardDenoms': %v", err)
return params.RewardDenoms
}
return params.RewardDenoms
}

func (k Keeper) GetProviderRewardDenoms(ctx sdk.Context) []string {
params, _ := k.GetConsumerParams(ctx) //TODO @bermuell: Check behaviour for error case
params, err := k.GetConsumerParams(ctx)
if err != nil {
k.Logger(ctx).Error("error getting parameter 'UnbondingPeriod': %v", err)
return params.ProviderRewardDenoms
}
return params.ProviderRewardDenoms
}

0 comments on commit 5ec7e3d

Please sign in to comment.