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 4af7cc0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 27 deletions.
83 changes: 66 additions & 17 deletions x/ccv/consumer/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (k Keeper) GetConsumerParams(ctx sdk.Context) (ccvtypes.Params, error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.ParametersKey())
if err != nil {
return ccvtypes.Params{}, err
return ccvtypes.Params{}, err //TODO @bermuell: check if default arguments or error handling should be done
}
var params ccvtypes.Params
k.cdc.MustUnmarshal(bz, &params)
Expand All @@ -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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.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 ccvtypes.Params{}.ProviderRewardDenoms
}
return params.ProviderRewardDenoms
}
30 changes: 20 additions & 10 deletions x/ccv/provider/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
func (k Keeper) GetTemplateClient(ctx sdk.Context) *ibctmtypes.ClientState {
params, err := k.GetParams(ctx)
if err != nil {
return nil // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'TemplateClient': %v", err)
return types.Params{}.TemplateClient
}
return params.TemplateClient
}
Expand All @@ -24,7 +25,8 @@ func (k Keeper) GetTemplateClient(ctx sdk.Context) *ibctmtypes.ClientState {
func (k Keeper) GetTrustingPeriodFraction(ctx sdk.Context) string {
params, err := k.GetParams(ctx)
if err != nil {
return "" // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'TrustingPeriodFraction': %v", err)
return types.Params{}.TrustingPeriodFraction
}
return params.TrustingPeriodFraction

Expand All @@ -34,7 +36,8 @@ func (k Keeper) GetTrustingPeriodFraction(ctx sdk.Context) string {
func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration {
params, err := k.GetParams(ctx)
if err != nil {
return types.Params{}.CcvTimeoutPeriod // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'CcvTimeoutPeriod': %v", err)
return types.Params{}.CcvTimeoutPeriod
}
return params.CcvTimeoutPeriod
}
Expand All @@ -43,7 +46,8 @@ func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration {
func (k Keeper) GetInitTimeoutPeriod(ctx sdk.Context) time.Duration {
params, err := k.GetParams(ctx)
if err != nil {
return types.Params{}.InitTimeoutPeriod // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'InitTimeoutPeriod': %v", err)
return types.Params{}.InitTimeoutPeriod
}
return params.InitTimeoutPeriod
}
Expand All @@ -52,7 +56,8 @@ func (k Keeper) GetInitTimeoutPeriod(ctx sdk.Context) time.Duration {
func (k Keeper) GetVscTimeoutPeriod(ctx sdk.Context) time.Duration {
params, err := k.GetParams(ctx)
if err != nil {
return types.Params{}.VscTimeoutPeriod // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'VscTimeoutPeriod': %v", err)
return types.Params{}.VscTimeoutPeriod
}
return params.VscTimeoutPeriod
}
Expand All @@ -61,7 +66,7 @@ func (k Keeper) GetVscTimeoutPeriod(ctx sdk.Context) time.Duration {
func (k Keeper) SetVscTimeoutPeriod(ctx sdk.Context, period time.Duration) {
params, err := k.GetParams(ctx)
if err != nil {
// @bermuell TODO : error handling
k.Logger(ctx).Error("error setting parameter 'VscTimeoutPeriod': %v", err)
return
}
params.VscTimeoutPeriod = period
Expand All @@ -73,7 +78,8 @@ func (k Keeper) SetVscTimeoutPeriod(ctx sdk.Context, period time.Duration) {
func (k Keeper) GetSlashMeterReplenishPeriod(ctx sdk.Context) time.Duration {
params, err := k.GetParams(ctx)
if err != nil {
return types.Params{}.SlashMeterReplenishPeriod // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'SlashMeterReplenishPeriod': %v", err)
return types.Params{}.SlashMeterReplenishPeriod
}
return params.SlashMeterReplenishPeriod
}
Expand All @@ -84,7 +90,8 @@ func (k Keeper) GetSlashMeterReplenishPeriod(ctx sdk.Context) time.Duration {
func (k Keeper) GetSlashMeterReplenishFraction(ctx sdk.Context) string {
params, err := k.GetParams(ctx)
if err != nil {
return types.Params{}.SlashMeterReplenishFraction // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'SlashMeterReplenishFraction': %v", err)
return types.Params{}.SlashMeterReplenishFraction
}
return params.SlashMeterReplenishFraction
}
Expand All @@ -94,7 +101,8 @@ func (k Keeper) GetSlashMeterReplenishFraction(ctx sdk.Context) string {
func (k Keeper) GetMaxThrottledPackets(ctx sdk.Context) int64 {
params, err := k.GetParams(ctx)
if err != nil {
return types.Params{}.MaxThrottledPackets // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'MaxThrottledPackets': %v", err)
return types.Params{}.MaxThrottledPackets
}
return params.MaxThrottledPackets
}
Expand All @@ -105,7 +113,8 @@ func (k Keeper) GetConsumerRewardDenomRegistrationFee(ctx sdk.Context) sdk.Coin
// need to run migrations to add the param. This will allow us to change the fee by governance.
params, err := k.GetParams(ctx)
if err != nil {
return types.Params{}.ConsumerRewardDenomRegistrationFee // @bermuell TODO : error handling... panic or default?
k.Logger(ctx).Error("error getting parameter 'ConsumerRewardDenomRegistrationFee': %v", err)
return types.Params{}.ConsumerRewardDenomRegistrationFee
}
return params.ConsumerRewardDenomRegistrationFee
}
Expand All @@ -115,6 +124,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.ParametersKey())
if err != nil {
k.Logger(ctx).Error("error getting module parameters: %v", err)
return types.Params{}, nil //TODO @bermuell: check if default arguments or error handling should be done
}
var params types.Params
Expand Down

0 comments on commit 4af7cc0

Please sign in to comment.