refactor: migrate x/staking Params to use collections (#17778)

This commit is contained in:
atheeshp 2023-09-18 21:36:42 +05:30 committed by GitHub
parent a0b39a1d31
commit 28112706b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 70 additions and 107 deletions

View File

@ -69,6 +69,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes
* (x/staking) [#17778](https://github.com/cosmos/cosmos-sdk/pull/17778) Use collections for `Params`
* remove from `Keeper`: `GetParams`, `SetParams`
* (types/simulation) [#17737](https://github.com/cosmos/cosmos-sdk/pull/17737) Remove unused parameter from `RandomFees`
* (x/staking) [#17486](https://github.com/cosmos/cosmos-sdk/pull/17486) Use collections for `RedelegationQueueKey`:
* remove from `types`: `GetRedelegationTimeKey`

View File

@ -75,7 +75,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
ctx = app.BaseApp.NewContext(false)
ctx = ctx.WithHeaderInfo(header.Info{Time: time.Now()})
err = stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams())
err = stakingKeeper.Params.Set(ctx, stakingtypes.DefaultParams())
require.NoError(t, err)
lastAccNum := uint64(1000)
createBaseAccount := func(addr sdk.AccAddress) *authtypes.BaseAccount {

View File

@ -82,7 +82,7 @@ func TestGRPCValidatorOutstandingRewards(t *testing.T) {
assert.NilError(t, f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))
// Set default staking params
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams()))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, stakingtypes.DefaultParams()))
qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
@ -159,7 +159,7 @@ func TestGRPCValidatorCommission(t *testing.T) {
assert.NilError(t, f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))
// Set default staking params
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams()))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, stakingtypes.DefaultParams()))
qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
@ -490,7 +490,7 @@ func TestGRPCDelegationRewards(t *testing.T) {
assert.NilError(t, f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))
// Set default staking params
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams()))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, stakingtypes.DefaultParams()))
qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)

View File

@ -100,6 +100,7 @@ func initFixture(tb testing.TB) *fixture {
)
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
require.NoError(tb, stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams()))
distrKeeper := distrkeeper.NewKeeper(
cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, bankKeeper, stakingKeeper, distrtypes.ModuleName, authority.String(),
@ -896,7 +897,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
require.NoError(t, f.bankKeeper.MintCoins(f.sdkCtx, distrtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))
// Set default staking params
require.NoError(t, f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams()))
require.NoError(t, f.stakingKeeper.Params.Set(f.sdkCtx, stakingtypes.DefaultParams()))
addr := sdk.AccAddress("addr")
addr1 := sdk.AccAddress(PKS[0].Address())

View File

@ -154,7 +154,7 @@ func initFixture(tb testing.TB) *fixture {
assert.NilError(tb, slashingKeeper.Params.Set(sdkCtx, testutil.TestParams()))
// set default staking params
assert.NilError(tb, stakingKeeper.SetParams(sdkCtx, stakingtypes.DefaultParams()))
assert.NilError(tb, stakingKeeper.Params.Set(sdkCtx, stakingtypes.DefaultParams()))
return &fixture{
app: integrationApp,
@ -175,7 +175,7 @@ func TestHandleDoubleSign(t *testing.T) {
populateValidators(t, f)
power := int64(100)
stakingParams, err := f.stakingKeeper.GetParams(ctx)
stakingParams, err := f.stakingKeeper.Params.Get(ctx)
assert.NilError(t, err)
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)
@ -267,7 +267,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
populateValidators(t, f)
power := int64(100)
stakingParams, err := f.stakingKeeper.GetParams(ctx)
stakingParams, err := f.stakingKeeper.Params.Get(ctx)
assert.NilError(t, err)
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]

View File

@ -94,7 +94,7 @@ func initFixture(tb testing.TB) *fixture {
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
// set default staking params
err := stakingKeeper.SetParams(newCtx, stakingtypes.DefaultParams())
err := stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams())
assert.NilError(tb, err)
distrKeeper := distrkeeper.NewKeeper(
cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, bankKeeper, stakingKeeper, distrtypes.ModuleName, authority.String(),

View File

@ -112,7 +112,7 @@ func initFixture(tb testing.TB) *fixture {
slashingtypes.RegisterQueryServer(integrationApp.QueryHelper(), slashingkeeper.NewQuerier(slashingKeeper))
// set default staking params
err := stakingKeeper.SetParams(sdkCtx, stakingtypes.DefaultParams())
err := stakingKeeper.Params.Set(sdkCtx, stakingtypes.DefaultParams())
assert.NilError(tb, err)
// TestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500
err = slashingKeeper.Params.Set(sdkCtx, testutil.TestParams())
@ -142,10 +142,10 @@ func TestUnJailNotBonded(t *testing.T) {
t.Parallel()
f := initFixture(t)
p, err := f.stakingKeeper.GetParams(f.ctx)
p, err := f.stakingKeeper.Params.Get(f.ctx)
assert.NilError(t, err)
p.MaxValidators = 5
assert.NilError(t, f.stakingKeeper.SetParams(f.ctx, p))
assert.NilError(t, f.stakingKeeper.Params.Set(f.ctx, p))
pks := simtestutil.CreateTestPubKeys(6)
tstaking := stakingtestutil.NewHelper(t, f.ctx, f.stakingKeeper)
@ -346,10 +346,10 @@ func TestValidatorDippingInAndOut(t *testing.T) {
t.Parallel()
f := initFixture(t)
params, err := f.stakingKeeper.GetParams(f.ctx)
params, err := f.stakingKeeper.Params.Get(f.ctx)
require.NoError(t, err)
params.MaxValidators = 1
err = f.stakingKeeper.SetParams(f.ctx, params)
err = f.stakingKeeper.Params.Set(f.ctx, params)
assert.NilError(t, err)
power := int64(100)

View File

@ -154,7 +154,7 @@ func initFixture(tb testing.TB) *fixture {
types.RegisterQueryServer(integrationApp.QueryHelper(), stakingkeeper.NewQuerier(stakingKeeper))
// set default staking params
assert.NilError(tb, stakingKeeper.SetParams(sdkCtx, types.DefaultParams()))
assert.NilError(tb, stakingKeeper.Params.Set(sdkCtx, types.DefaultParams()))
f := fixture{
app: integrationApp,

View File

@ -126,7 +126,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
stakingtypes.RegisterQueryServer(integrationApp.QueryHelper(), stakingkeeper.NewQuerier(stakingKeeper))
// set default staking params
assert.NilError(t, stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams()))
assert.NilError(t, stakingKeeper.Params.Set(ctx, stakingtypes.DefaultParams()))
// set pools
startTokens := stakingKeeper.TokensFromConsensusPower(ctx, 10)
@ -840,7 +840,7 @@ func TestGRPCParams(t *testing.T) {
MinCommissionRate: math.LegacyNewDecWithPrec(rapid.Int64Range(0, 100).Draw(rt, "commission"), 2),
}
err := f.stakingKeeper.SetParams(f.ctx, params)
err := f.stakingKeeper.Params.Set(f.ctx, params)
assert.NilError(t, err)
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryParamsRequest{}, f.queryClient.Params, 0, true)
@ -855,7 +855,7 @@ func TestGRPCParams(t *testing.T) {
MinCommissionRate: math.LegacyNewDecWithPrec(5, 2),
}
err := f.stakingKeeper.SetParams(f.ctx, params)
err := f.stakingKeeper.Params.Set(f.ctx, params)
assert.NilError(t, err)
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryParamsRequest{}, f.queryClient.Params, 1114, false)

View File

@ -44,7 +44,7 @@ func TestInitGenesis(t *testing.T) {
}
assert.NilError(t, f.stakingKeeper.SetValidator(f.sdkCtx, bondedVal))
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
validators, err := f.stakingKeeper.GetAllValidators(f.sdkCtx)
@ -188,7 +188,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
genesisValidators, err := f.stakingKeeper.GetAllValidators(f.sdkCtx)
assert.NilError(t, err)
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
delegations := []types.Delegation{}
validators := make([]types.Validator, size)

View File

@ -129,7 +129,7 @@ func TestGRPCQueryDelegatorValidators(t *testing.T) {
qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
params, err := f.stakingKeeper.GetParams(ctx)
params, err := f.stakingKeeper.Params.Get(ctx)
assert.NilError(t, err)
delValidators, err := f.stakingKeeper.GetDelegatorValidators(ctx, addrs[0], params.MaxValidators)
assert.NilError(t, err)
@ -717,7 +717,7 @@ func TestGRPCQueryPoolParameters(t *testing.T) {
// Query Params
resp, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
assert.NilError(t, err)
params, err := f.stakingKeeper.GetParams(ctx)
params, err := f.stakingKeeper.Params.Get(ctx)
assert.NilError(t, err)
assert.DeepEqual(t, params, resp.Params)
}

View File

@ -72,10 +72,10 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
// create keeper parameters
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
params.MaxValidators = uint32(maxVals)
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, params))
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
assert.NilError(t, err)
@ -262,10 +262,10 @@ func TestGetValidatorSortingMixed(t *testing.T) {
f.accountKeeper.SetModuleAccount(f.sdkCtx, bondedPool)
// now 2 max resValidators
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
params.MaxValidators = 2
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, params))
// initialize some validators into the state
amts := []math.Int{
@ -317,11 +317,11 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
f, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
// set max validators to 2
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
nMax := uint32(2)
params.MaxValidators = nMax
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, params))
// initialize some validators into the state
powers := []int64{0, 100, 400, 400}
var validators [4]types.Validator
@ -436,10 +436,10 @@ func TestValidatorBondHeight(t *testing.T) {
f, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
// now 2 max resValidators
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
params.MaxValidators = 2
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, params))
// initialize some validators into the state
var validators [3]types.Validator
validators[0] = testutil.NewValidator(t, sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0])
@ -483,11 +483,11 @@ func TestValidatorBondHeight(t *testing.T) {
func TestFullValidatorSetPowerChange(t *testing.T) {
f, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
max := 2
params.MaxValidators = uint32(2)
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, params))
// initialize some validators into the state
powers := []int64{0, 100, 400, 400, 200}
@ -676,7 +676,7 @@ func TestApplyAndReturnValidatorSetUpdatesWithCliffValidator(t *testing.T) {
f, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
params := types.DefaultParams()
params.MaxValidators = 2
err := f.stakingKeeper.SetParams(f.sdkCtx, params)
err := f.stakingKeeper.Params.Set(f.sdkCtx, params)
assert.NilError(t, err)
powers := []int64{10, 20, 5}
var validators [5]types.Validator
@ -712,11 +712,11 @@ func TestApplyAndReturnValidatorSetUpdatesWithCliffValidator(t *testing.T) {
func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
f, _, _ := bootstrapValidatorTest(t, 1000, 20)
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
params.MaxValidators = uint32(3)
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, params))
powers := []int64{100, 100}
var validators [2]types.Validator
@ -798,11 +798,11 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) {
f, _, _ := bootstrapValidatorTest(t, 1000, 20)
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
params, err := f.stakingKeeper.Params.Get(f.sdkCtx)
assert.NilError(t, err)
params.MaxValidators = uint32(2)
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
assert.NilError(t, f.stakingKeeper.Params.Set(f.sdkCtx, params))
powers := []int64{100, 200, 300}
var validators [3]types.Validator

View File

@ -55,21 +55,6 @@ func (mr *MockStakingKeeperMockRecorder) ConsensusAddressCodec() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusAddressCodec", reflect.TypeOf((*MockStakingKeeper)(nil).ConsensusAddressCodec))
}
// GetParams mocks base method.
func (m *MockStakingKeeper) GetParams(ctx context.Context) (types1.Params, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetParams", ctx)
ret0, _ := ret[0].(types1.Params)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetParams indicates an expected call of GetParams.
func (mr *MockStakingKeeperMockRecorder) GetParams(ctx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParams", reflect.TypeOf((*MockStakingKeeper)(nil).GetParams), ctx)
}
// ValidatorByConsAddr mocks base method.
func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types1.ValidatorI, error) {
m.ctrl.T.Helper()

View File

@ -19,7 +19,6 @@ type (
StakingKeeper interface {
ConsensusAddressCodec() address.Codec
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (stakingtypes.ValidatorI, error)
GetParams(ctx context.Context) (params stakingtypes.Params, err error)
}
// SlashingKeeper defines the slashing module interface contract needed by the

View File

@ -500,7 +500,7 @@ func (s *KeeperTestSuite) TestUndelegateFromUnbondingValidator() {
validator, err = keeper.GetValidator(ctx, addrVals[0])
require.NoError(err)
require.Equal(blockHeight, validator.UnbondingHeight)
params, err := keeper.GetParams(ctx)
params, err := keeper.Params.Get(ctx)
require.NoError(err)
require.True(blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
@ -571,7 +571,7 @@ func (s *KeeperTestSuite) TestUndelegateFromUnbondedValidator() {
validator, err = keeper.GetValidator(ctx, addrVals[0])
require.NoError(err)
require.Equal(ctx.BlockHeight(), validator.UnbondingHeight)
params, err := keeper.GetParams(ctx)
params, err := keeper.Params.Get(ctx)
require.NoError(err)
require.True(ctx.HeaderInfo().Time.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
@ -958,7 +958,7 @@ func (s *KeeperTestSuite) TestRedelegateFromUnbondingValidator() {
validator, err = keeper.GetValidator(ctx, addrVals[0])
require.NoError(err)
require.Equal(blockHeight, validator.UnbondingHeight)
params, err := keeper.GetParams(ctx)
params, err := keeper.Params.Get(ctx)
require.NoError(err)
require.True(blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
@ -1036,7 +1036,7 @@ func (s *KeeperTestSuite) TestRedelegateFromUnbondedValidator() {
validator, err = keeper.GetValidator(ctx, addrVals[0])
require.NoError(err)
require.Equal(ctx.HeaderInfo().Height, validator.UnbondingHeight)
params, err := keeper.GetParams(ctx)
params, err := keeper.Params.Get(ctx)
require.NoError(err)
require.True(ctx.HeaderInfo().Time.Add(params.UnbondingTime).Equal(validator.UnbondingTime))

View File

@ -31,7 +31,7 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res
sdkCtx = sdkCtx.WithBlockHeight(1 - sdk.ValidatorUpdateDelay)
ctx = sdkCtx
if err := k.SetParams(ctx, data.Params); err != nil {
if err := k.Params.Set(ctx, data.Params); err != nil {
panic(err)
}
@ -251,7 +251,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
panic(err)
}
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
if err != nil {
panic(err)
}

View File

@ -492,7 +492,7 @@ func (k Querier) Pool(ctx context.Context, _ *types.QueryPoolRequest) (*types.Qu
// Params queries the staking parameters
func (k Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
params, err := k.GetParams(ctx)
params, err := k.Keeper.Params.Get(ctx)
if err != nil {
return nil, err
}

View File

@ -58,7 +58,7 @@ func (s *KeeperTestSuite) TestTrackHistoricalInfo() {
// set historical entries in params to 5
params := stakingtypes.DefaultParams()
params.HistoricalEntries = 5
require.NoError(keeper.SetParams(ctx, params))
require.NoError(keeper.Params.Set(ctx, params))
// set historical info at 5, 4 which should be pruned
// and check that it has been stored

View File

@ -74,6 +74,8 @@ type Keeper struct {
ValidatorQueue collections.Map[collections.Triple[uint64, time.Time, uint64], types.ValAddresses]
// LastValidatorPower key: valAddr | value: power(gogotypes.Int64Value())
LastValidatorPower collections.Map[[]byte, gogotypes.Int64Value]
// Params key: ParamsKeyPrefix | value: Params
Params collections.Item[types.Params]
}
// NewKeeper creates a new staking Keeper instance
@ -205,6 +207,8 @@ func NewKeeper(
),
codec.CollValue[types.ValAddresses](cdc),
),
// key is: 113 (it's a direct prefix)
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
}
schema, err := sb.Build()

View File

@ -76,7 +76,7 @@ func (s *KeeperTestSuite) SetupTest() {
address.NewBech32Codec("cosmosvaloper"),
address.NewBech32Codec("cosmosvalcons"),
)
require.NoError(keeper.SetParams(ctx, stakingtypes.DefaultParams()))
require.NoError(keeper.Params.Set(ctx, stakingtypes.DefaultParams()))
s.ctx = ctx
s.stakingKeeper = keeper
@ -96,14 +96,14 @@ func (s *KeeperTestSuite) TestParams() {
expParams := stakingtypes.DefaultParams()
// check that the empty keeper loads the default
resParams, err := keeper.GetParams(ctx)
resParams, err := keeper.Params.Get(ctx)
require.NoError(err)
require.Equal(expParams, resParams)
expParams.MaxValidators = 555
expParams.MaxEntries = 111
require.NoError(keeper.SetParams(ctx, expParams))
resParams, err = keeper.GetParams(ctx)
require.NoError(keeper.Params.Set(ctx, expParams))
resParams, err = keeper.Params.Get(ctx)
require.NoError(err)
require.True(expParams.Equal(resParams))
}

View File

@ -596,7 +596,7 @@ func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams)
}
// store params
if err := k.SetParams(ctx, msg.Params); err != nil {
if err := k.Params.Set(ctx, msg.Params); err != nil {
return nil, err
}

View File

@ -7,38 +7,37 @@ import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
// UnbondingTime - The time duration for unbonding
func (k Keeper) UnbondingTime(ctx context.Context) (time.Duration, error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
return params.UnbondingTime, err
}
// MaxValidators - Maximum number of validators
func (k Keeper) MaxValidators(ctx context.Context) (uint32, error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
return params.MaxValidators, err
}
// MaxEntries - Maximum number of simultaneous unbonding
// delegations or redelegations (per pair/trio)
func (k Keeper) MaxEntries(ctx context.Context) (uint32, error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
return params.MaxEntries, err
}
// HistoricalEntries = number of historical info entries
// to persist in store
func (k Keeper) HistoricalEntries(ctx context.Context) (uint32, error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
return params.HistoricalEntries, err
}
// BondDenom - Bondable coin denomination
func (k Keeper) BondDenom(ctx context.Context) (string, error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
return params.BondDenom, err
}
@ -52,33 +51,6 @@ func (k Keeper) PowerReduction(ctx context.Context) math.Int {
// MinCommissionRate - Minimum validator commission rate
func (k Keeper) MinCommissionRate(ctx context.Context) (math.LegacyDec, error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
return params.MinCommissionRate, err
}
// SetParams sets the x/staking module parameters.
// CONTRACT: This method performs no validation of the parameters.
func (k Keeper) SetParams(ctx context.Context, params types.Params) error {
store := k.storeService.OpenKVStore(ctx)
bz, err := k.cdc.Marshal(&params)
if err != nil {
return err
}
return store.Set(types.ParamsKey, bz)
}
// GetParams gets the x/staking module parameters.
func (k Keeper) GetParams(ctx context.Context) (params types.Params, err error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.ParamsKey)
if err != nil {
return params, err
}
if bz == nil {
return params, nil
}
err = k.cdc.Unmarshal(bz, &params)
return params, err
}

View File

@ -128,7 +128,7 @@ func (k Keeper) BlockValidatorUpdates(ctx context.Context) ([]abci.ValidatorUpda
// at the previous block height or were removed from the validator set entirely
// are returned to CometBFT.
func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) (updates []abci.ValidatorUpdate, err error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
@ -376,7 +376,7 @@ func (k Keeper) bondValidator(ctx context.Context, validator types.Validator) (t
// BeginUnbondingValidator performs all the store operations for when a validator begins unbonding
func (k Keeper) BeginUnbondingValidator(ctx context.Context, validator types.Validator) (types.Validator, error) {
params, err := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
if err != nil {
return validator, err
}

View File

@ -285,10 +285,10 @@ func (s *KeeperTestSuite) TestUpdateValidatorCommission() {
require := s.Require()
// Set MinCommissionRate to 0.05
params, err := keeper.GetParams(ctx)
params, err := keeper.Params.Get(ctx)
require.NoError(err)
params.MinCommissionRate = math.LegacyNewDecWithPrec(5, 2)
require.NoError(keeper.SetParams(ctx, params))
require.NoError(keeper.Params.Set(ctx, params))
commission1 := stakingtypes.NewCommissionWithTime(
math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDecWithPrec(3, 1),

View File

@ -37,7 +37,7 @@ func migrateParams(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCo
}
bz := cdc.MustMarshal(&legacyParams)
store.Set(types.ParamsKey, bz)
store.Set(ParamsKey, bz)
return nil
}

View File

@ -55,9 +55,9 @@ var (
HistoricalInfoKey = collections.NewPrefix(80) // prefix for the historical info
ValidatorUpdatesKey = collections.NewPrefix(97) // prefix for the end block validator updates key
ParamsKey = []byte{0x51} // prefix for parameters for module x/staking
ParamsKey = collections.NewPrefix(81) // prefix for parameters for module x/staking
DelegationByValIndexKey = []byte{0x71} // key for delegations by a validator
DelegationByValIndexKey = collections.NewPrefix(113) // key for delegations by a validator
)
// UnbondingType defines the type of unbonding operation