diff --git a/x/ccv/consumer/keeper/params.go b/x/ccv/consumer/keeper/params.go index 8ec4e76104..7950efc8bf 100644 --- a/x/ccv/consumer/keeper/params.go +++ b/x/ccv/consumer/keeper/params.go @@ -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, ¶ms) @@ -44,19 +44,28 @@ 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 @@ -64,22 +73,30 @@ func (k Keeper) SetBlocksPerDistributionTransmission(ctx sdk.Context, bpdt int64 } 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 } @@ -87,7 +104,7 @@ func (k Keeper) GetProviderFeePoolAddrStr(ctx sdk.Context) string { 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 @@ -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 } @@ -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 } @@ -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 @@ -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 } diff --git a/x/ccv/provider/keeper/params.go b/x/ccv/provider/keeper/params.go index c8514131dd..f15ab5ffe4 100644 --- a/x/ccv/provider/keeper/params.go +++ b/x/ccv/provider/keeper/params.go @@ -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 } @@ -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 @@ -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 } @@ -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 } @@ -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 } @@ -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 @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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