From 43d90e9eabe2dc786f38edf5b208c4f10a4de6f7 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Sun, 3 Sep 2023 17:44:51 -0400 Subject: [PATCH] add: support for legacy params query --- x/distribution/keeper/keeper.go | 10 +++++++++- x/distribution/keeper/params.go | 8 ++++++++ x/staking/keeper/keeper.go | 9 +++++++++ x/staking/keeper/params.go | 9 ++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 807dea8a49d7..941c82429e01 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -10,6 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/distribution/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Keeper of the distribution store @@ -22,6 +23,7 @@ type Keeper struct { // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string + ss paramstypes.Subspace feeCollectorName string // name of the FeeCollector ModuleAccount } @@ -30,13 +32,18 @@ type Keeper struct { func NewKeeper( cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, - feeCollectorName string, authority string, + feeCollectorName string, authority string, ss ...paramstypes.Subspace, ) Keeper { // ensure distribution module account is set if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) } + // ensure that a param subspace is provided + if len(ss) != 1 { + panic("must provide a param subspace") + } + return Keeper{ storeKey: key, cdc: cdc, @@ -45,6 +52,7 @@ func NewKeeper( stakingKeeper: sk, feeCollectorName: feeCollectorName, authority: authority, + ss: ss[0], } } diff --git a/x/distribution/keeper/params.go b/x/distribution/keeper/params.go index f5c18602d533..3c0afbac3043 100644 --- a/x/distribution/keeper/params.go +++ b/x/distribution/keeper/params.go @@ -45,3 +45,11 @@ func (k Keeper) GetCommunityTax(ctx sdk.Context) math.LegacyDec { func (k Keeper) GetWithdrawAddrEnabled(ctx sdk.Context) (enabled bool) { return k.GetParams(ctx).WithdrawAddrEnabled } + + +// GetLegacyParams returns param set for version before migrate +func (k Keeper) getLegacyParams(ctx sdk.Context) types.Params { + var params types.Params + k.ss.GetParamSetIfExists(ctx, ¶ms) + return params +} diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index d261ce3fc866..9a7d7304011c 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -28,6 +29,7 @@ type Keeper struct { bankKeeper types.BankKeeper hooks types.StakingHooks authority string + ss paramstypes.Subspace } // NewKeeper creates a new staking Keeper instance @@ -37,6 +39,7 @@ func NewKeeper( ak types.AccountKeeper, bk types.BankKeeper, authority string, + ss ...paramstypes.Subspace, ) *Keeper { // ensure bonded and not bonded module accounts are set if addr := ak.GetModuleAddress(types.BondedPoolName); addr == nil { @@ -52,6 +55,11 @@ func NewKeeper( panic("authority is not a valid acc address") } + // ensure that a param subspace is provided + if len(ss) != 1 { + panic("must provide a param subspace") + } + return &Keeper{ storeKey: key, cdc: cdc, @@ -59,6 +67,7 @@ func NewKeeper( bankKeeper: bk, hooks: nil, authority: authority, + ss: ss[0], } } diff --git a/x/staking/keeper/params.go b/x/staking/keeper/params.go index 3e1bb083916e..e754d360c6a8 100644 --- a/x/staking/keeper/params.go +++ b/x/staking/keeper/params.go @@ -70,9 +70,16 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.ParamsKey) if bz == nil { - return params + return k.getLegacyParams(ctx) } k.cdc.MustUnmarshal(bz, ¶ms) return params } + +// GetLegacyParams returns param set for version before migrate +func (k Keeper) getLegacyParams(ctx sdk.Context) types.Params { + var params types.Params + k.ss.GetParamSetIfExists(ctx, ¶ms) + return params +}