diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b0210950097..0511080de717 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -193,6 +193,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/genutil) [#15999](https://github.com/cosmos/cosmos-sdk/pull/15999) Genutil now takes the `GenesisTxHanlder` interface instead of deliverTx. The interface is implemented on baseapp * (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16040) Remove unused aliases in math.go * (x/gov) [#16106](https://github.com/cosmos/cosmos-sdk/pull/16106) Remove gRPC query methods from Keeper +* (x/gov) [#16118](https://github.com/cosmos/cosmos-sdk/pull/16118/) Use collections for constituion and params state management. + ### Client Breaking Changes * (x/staking) [#15701](https://github.com/cosmos/cosmos-sdk/pull/15701) `HistoricalInfoKey` now has a binary format. diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go index 65621bab3330..68821ba65f74 100644 --- a/tests/integration/gov/genesis_test.go +++ b/tests/integration/gov/genesis_test.go @@ -88,7 +88,8 @@ func TestImportExportQueues(t *testing.T) { assert.NilError(t, err) proposalID2 := proposal2.Id - params, _ := s1.GovKeeper.GetParams(ctx) + params, err := s1.GovKeeper.Params.Get(ctx) + assert.NilError(t, err) votingStarted, err := s1.GovKeeper.AddDeposit(ctx, proposalID2, addrs[0], params.MinDeposit) assert.NilError(t, err) assert.Assert(t, votingStarted) @@ -145,7 +146,7 @@ func TestImportExportQueues(t *testing.T) { ctx2 := s2.app.BaseApp.NewContext(false, cmtproto.Header{}) - params, err = s2.GovKeeper.GetParams(ctx2) + params, err = s2.GovKeeper.Params.Get(ctx2) assert.NilError(t, err) // Jump the time forward past the DepositPeriod and VotingPeriod ctx2 = ctx2.WithBlockTime(ctx2.BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(*params.VotingPeriod)) diff --git a/x/gov/abci.go b/x/gov/abci.go index 9d4085d6933d..eb5e4e9c6779 100644 --- a/x/gov/abci.go +++ b/x/gov/abci.go @@ -24,7 +24,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) error { return err } - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return err } @@ -152,7 +152,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) error { // once the regular voting period expires again, the tally is repeated // according to the regular proposal rules. proposal.Expedited = false - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return err } diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index 3c99ab77e9b3..095d12c34508 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -63,7 +63,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) { require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) newHeader = ctx.BlockHeader() newHeader.Time = ctx.BlockHeader().Time.Add(*params.MaxDepositPeriod) ctx = ctx.WithBlockHeader(newHeader) @@ -137,7 +137,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { require.NotNil(t, res) newHeader = ctx.BlockHeader() - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) newHeader.Time = ctx.BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(time.Duration(-1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) @@ -280,7 +280,7 @@ func TestTickPassedVotingPeriod(t *testing.T) { require.NoError(t, err) require.NotNil(t, res1) - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) votingPeriod := params.VotingPeriod if tc.expedited { votingPeriod = params.ExpeditedVotingPeriod @@ -389,7 +389,7 @@ func TestProposalPassedEndblocker(t *testing.T) { require.NoError(t, err) newHeader := ctx.BlockHeader() - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) newHeader.Time = ctx.BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(*params.VotingPeriod) ctx = ctx.WithBlockHeader(newHeader) @@ -435,7 +435,7 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) { err = suite.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "") require.NoError(t, err) - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) newHeader := ctx.BlockHeader() newHeader.Time = ctx.BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(*params.VotingPeriod) ctx = ctx.WithBlockHeader(newHeader) @@ -485,7 +485,7 @@ func TestExpeditedProposal_PassAndConversionToRegular(t *testing.T) { ctx := app.BaseApp.NewContext(false, cmtproto.Header{}) depositMultiplier := getDepositMultiplier(true) addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 3, valTokens.Mul(math.NewInt(depositMultiplier))) - params, err := suite.GovKeeper.GetParams(ctx) + params, err := suite.GovKeeper.Params.Get(ctx) require.NoError(t, err) SortAddresses(addrs) diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 0c0c156f6910..f8cf816f8ba3 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -16,12 +16,12 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k panic(err) } - err = k.SetParams(ctx, *data.Params) + err = k.Params.Set(ctx, *data.Params) if err != nil { panic(err) } - err = k.SetConstitution(ctx, data.Constitution) + err = k.Constitution.Set(ctx, data.Constitution) if err != nil { panic(err) } @@ -76,12 +76,12 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) (*v1.GenesisState, error) return nil, err } - constitution, err := k.GetConstitution(ctx) + constitution, err := k.Constitution.Get(ctx) if err != nil { return nil, err } - params, err := k.GetParams(ctx) + params, err := k.Params.Get(ctx) if err != nil { return nil, err } diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 242e459a74cb..c6738cc66ff5 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + "cosmossdk.io/math" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttime "github.com/cometbft/cometbft/types/time" @@ -102,7 +104,8 @@ func setupGovKeeper(t *testing.T) ( govRouter := v1beta1.NewRouter() // Also register legacy gov handlers to test them too. govRouter.AddRoute(types.RouterKey, v1beta1.ProposalHandler) govKeeper.SetLegacyRouter(govRouter) - govKeeper.SetParams(ctx, v1.DefaultParams()) + err := govKeeper.Params.Set(ctx, v1.DefaultParams()) + require.NoError(t, err) // Register all handlers for the MegServiceRouter. msr.SetInterfaceRegistry(encCfg.InterfaceRegistry) diff --git a/x/gov/keeper/constitution.go b/x/gov/keeper/constitution.go deleted file mode 100644 index 0f791a6f1821..000000000000 --- a/x/gov/keeper/constitution.go +++ /dev/null @@ -1,21 +0,0 @@ -package keeper - -import ( - "context" - - "github.com/cosmos/cosmos-sdk/x/gov/types" -) - -// GetConstitution gets the chain's constitution. -func (keeper Keeper) GetConstitution(ctx context.Context) (string, error) { - store := keeper.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.KeyConstitution) - - return string(bz), err -} - -// GetConstitution sets the chain's constitution. -func (keeper Keeper) SetConstitution(ctx context.Context, constitution string) error { - store := keeper.storeService.OpenKVStore(ctx) - return store.Set(types.KeyConstitution, []byte(constitution)) -} diff --git a/x/gov/keeper/deposit.go b/x/gov/keeper/deposit.go index 7cfebba67efb..d523931fc966 100644 --- a/x/gov/keeper/deposit.go +++ b/x/gov/keeper/deposit.go @@ -180,7 +180,7 @@ func (keeper Keeper) AddDeposit(ctx context.Context, proposalID uint64, deposito // Check if deposit has provided sufficient total funds to transition the proposal into the voting period activatedVotingPeriod := false - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return false, err } @@ -344,7 +344,7 @@ func (keeper Keeper) RefundAndDeleteDeposits(ctx context.Context, proposalID uin // required at the time of proposal submission. This threshold amount is determined by // the deposit parameters. Returns nil on success, error otherwise. func (keeper Keeper) validateInitialDeposit(ctx context.Context, initialDeposit sdk.Coins, expedited bool) error { - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return err } diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index 3b9ce3cf5890..1ef0818f12f7 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -252,7 +252,7 @@ func TestValidateInitialDeposit(t *testing.T) { } params.MinInitialDepositRatio = sdkmath.LegacyNewDec(tc.minInitialDepositPercent).Quo(sdkmath.LegacyNewDec(100)).String() - govKeeper.SetParams(ctx, params) + govKeeper.Params.Set(ctx, params) err := govKeeper.ValidateInitialDeposit(ctx, tc.initialDeposit, tc.expedited) @@ -325,7 +325,7 @@ func TestChargeDeposit(t *testing.T) { params.ProposalCancelDest = authtypes.NewModuleAddress(disttypes.ModuleName).String() } - err := govKeeper.SetParams(ctx, params) + err := govKeeper.Params.Set(ctx, params) require.NoError(t, err) tp := TestProposal diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index 934acc2611e6..ae0b9e57ed61 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -28,7 +28,7 @@ func NewQueryServer(k Keeper) v1.QueryServer { } func (q queryServer) Constitution(ctx context.Context, _ *v1.QueryConstitutionRequest) (*v1.QueryConstitutionResponse, error) { - constitution, err := q.k.GetConstitution(ctx) + constitution, err := q.k.Constitution.Get(ctx) if err != nil { return nil, err } @@ -177,7 +177,7 @@ func (q queryServer) Params(ctx context.Context, req *v1.QueryParamsRequest) (*v return nil, status.Error(codes.InvalidArgument, "invalid request") } - params, err := q.k.GetParams(ctx) + params, err := q.k.Params.Get(ctx) if err != nil { return nil, err } diff --git a/x/gov/keeper/hooks_test.go b/x/gov/keeper/hooks_test.go index 64290f5db3e6..29c5ccd29402 100644 --- a/x/gov/keeper/hooks_test.go +++ b/x/gov/keeper/hooks_test.go @@ -73,7 +73,7 @@ func TestHooks(t *testing.T) { require.NoError(t, err) require.True(t, govHooksReceiver.AfterProposalSubmissionValid) - params, _ := govKeeper.GetParams(ctx) + params, _ := govKeeper.Params.Get(ctx) newHeader := ctx.BlockHeader() newHeader.Time = ctx.BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(time.Duration(1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 26c018ee7e45..60f67e642fb1 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + "cosmossdk.io/collections" + corestoretypes "cosmossdk.io/core/store" "cosmossdk.io/errors" "cosmossdk.io/log" @@ -47,6 +49,10 @@ type Keeper struct { // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string + + Schema collections.Schema + Constitution collections.Item[string] + Params collections.Item[v1.Params] } // GetAuthority returns the x/gov module's authority. @@ -80,7 +86,8 @@ func NewKeeper( config.MaxMetadataLen = types.DefaultConfig().MaxMetadataLen } - return &Keeper{ + sb := collections.NewSchemaBuilder(storeService) + k := &Keeper{ storeService: storeService, authKeeper: authKeeper, bankKeeper: bankKeeper, @@ -90,7 +97,15 @@ func NewKeeper( router: router, config: config, authority: authority, + Constitution: collections.NewItem(sb, types.ConstitutionKey, "constitution", collections.StringValue), + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[v1.Params](cdc)), } + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + return k } // Hooks gets the hooks for governance *Keeper { diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index d37dbb5339d9..39ca9971e818 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -283,7 +283,7 @@ func (k msgServer) UpdateParams(goCtx context.Context, msg *v1.MsgUpdateParams) } ctx := sdk.UnwrapSDKContext(goCtx) - if err := k.SetParams(ctx, msg.Params); err != nil { + if err := k.Params.Set(ctx, msg.Params); err != nil { return nil, err } diff --git a/x/gov/keeper/msg_server_test.go b/x/gov/keeper/msg_server_test.go index e44f4f60be57..9769636a660e 100644 --- a/x/gov/keeper/msg_server_test.go +++ b/x/gov/keeper/msg_server_test.go @@ -34,7 +34,7 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() { coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) initialDeposit := coins - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), @@ -319,7 +319,7 @@ func (suite *KeeperTestSuite) TestVoteReq() { proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), @@ -465,7 +465,7 @@ func (suite *KeeperTestSuite) TestVoteWeightedReq() { proposer := simtestutil.AddTestAddrsIncremental(suite.bankKeeper, suite.stakingKeeper, suite.ctx, 1, sdkmath.NewInt(50000000))[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), @@ -711,7 +711,7 @@ func (suite *KeeperTestSuite) TestDepositReq() { proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), @@ -793,7 +793,7 @@ func (suite *KeeperTestSuite) TestLegacyMsgSubmitProposal() { proposer := simtestutil.AddTestAddrsIncremental(suite.bankKeeper, suite.stakingKeeper, suite.ctx, 1, sdkmath.NewInt(50000000))[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) initialDeposit := coins - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit suite.acctKeeper.EXPECT().StringToBytes("").Return(nil, errors.New(emptyAddressError)) @@ -907,7 +907,7 @@ func (suite *KeeperTestSuite) TestLegacyMsgVote() { proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), @@ -1043,7 +1043,7 @@ func (suite *KeeperTestSuite) TestLegacyVoteWeighted() { proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), @@ -1297,7 +1297,7 @@ func (suite *KeeperTestSuite) TestLegacyMsgDeposit() { proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(100))) - params, _ := suite.govKeeper.GetParams(suite.ctx) + params, _ := suite.govKeeper.Params.Get(suite.ctx) minDeposit := params.MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), @@ -1699,7 +1699,7 @@ func (suite *KeeperTestSuite) TestSubmitProposal_InitialDeposit() { params := v1.DefaultParams() params.MinDeposit = tc.minDeposit params.MinInitialDepositRatio = tc.minInitialDepositRatio.String() - govKeeper.SetParams(ctx, params) + govKeeper.Params.Set(ctx, params) msg, err := v1.NewMsgSubmitProposal(TestProposal, tc.initialDeposit, address.String(), "test", "Proposal", "description of proposal", false) suite.Require().NoError(err) diff --git a/x/gov/keeper/params.go b/x/gov/keeper/params.go deleted file mode 100644 index 4e81c8ea58d3..000000000000 --- a/x/gov/keeper/params.go +++ /dev/null @@ -1,34 +0,0 @@ -package keeper - -import ( - "context" - - "github.com/cosmos/cosmos-sdk/x/gov/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" -) - -// SetParams sets the gov module's parameters. -// CONTRACT: This method performs no validation of the parameters. -func (k Keeper) SetParams(ctx context.Context, params v1.Params) error { - store := k.storeService.OpenKVStore(ctx) - bz, err := k.cdc.Marshal(¶ms) - if err != nil { - return err - } - return store.Set(types.ParamsKey, bz) -} - -// GetParams gets the gov module's parameters. -func (k Keeper) GetParams(ctx context.Context) (params v1.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, ¶ms) - return params, err -} diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index c0163661e707..7548429d978e 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -89,7 +89,7 @@ func (keeper Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, met return v1.Proposal{}, err } - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return v1.Proposal{}, err } @@ -151,7 +151,7 @@ func (keeper Keeper) CancelProposal(ctx context.Context, proposalID uint64, prop // burn the (deposits * proposal_cancel_rate) amount or sent to cancellation destination address. // and deposits * (1 - proposal_cancel_rate) will be sent to depositors. - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return err } @@ -370,7 +370,7 @@ func (keeper Keeper) ActivateVotingPeriod(ctx context.Context, proposal v1.Propo startTime := sdkCtx.BlockHeader().Time proposal.VotingStartTime = &startTime var votingPeriod *time.Duration - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return err } diff --git a/x/gov/keeper/tally.go b/x/gov/keeper/tally.go index ed1084e7038b..e6910c4794e8 100644 --- a/x/gov/keeper/tally.go +++ b/x/gov/keeper/tally.go @@ -99,7 +99,7 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, b totalVotingPower = totalVotingPower.Add(votingPower) } - params, err := keeper.GetParams(ctx) + params, err := keeper.Params.Get(ctx) if err != nil { return false, false, tallyResults, err } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 43ffaa313b9f..33d7d454df13 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -291,7 +291,7 @@ func simulateMsgSubmitProposal( // didntVote := whoVotes[numVotes:] whoVotes = whoVotes[:numVotes] - params, _ := k.GetParams(ctx) + params, _ := k.Params.Get(ctx) votingPeriod := params.VotingPeriod fops := make([]simtypes.FutureOperation, numVotes+1) @@ -557,7 +557,7 @@ func randomDeposit( return nil, true, nil // skip } - params, _ := k.GetParams(ctx) + params, _ := k.Params.Get(ctx) minDeposit := params.MinDeposit if expedited { minDeposit = params.ExpeditedMinDeposit diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index c545c8be8c59..5aeacb5b8f17 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -212,7 +212,7 @@ func TestSimulateMsgCancelProposal(t *testing.T) { require.NoError(t, err) submitTime := ctx.BlockHeader().Time - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) depositPeriod := params.MaxDepositPeriod proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod), "", "title", "summary", proposer, false) @@ -257,7 +257,7 @@ func TestSimulateMsgDeposit(t *testing.T) { require.NoError(t, err) submitTime := ctx.BlockHeader().Time - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) depositPeriod := params.MaxDepositPeriod proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod), "", "text proposal", "description", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), false) @@ -304,7 +304,7 @@ func TestSimulateMsgVote(t *testing.T) { require.NoError(t, err) submitTime := ctx.BlockHeader().Time - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) depositPeriod := params.MaxDepositPeriod proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod), "", "text proposal", "description", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), false) @@ -348,7 +348,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { contentMsg, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Test", "description"), govAcc) require.NoError(t, err) submitTime := ctx.BlockHeader().Time - params, _ := suite.GovKeeper.GetParams(ctx) + params, _ := suite.GovKeeper.Params.Get(ctx) depositPeriod := params.MaxDepositPeriod proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod), "", "text proposal", "test", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), false) diff --git a/x/gov/types/keys.go b/x/gov/types/keys.go index 4725685fbf1c..239cad98deb6 100644 --- a/x/gov/types/keys.go +++ b/x/gov/types/keys.go @@ -4,6 +4,8 @@ import ( "encoding/binary" "time" + "cosmossdk.io/collections" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/kv" @@ -50,10 +52,10 @@ var ( VotesKeyPrefix = []byte{0x20} // ParamsKey is the key to query all gov params - ParamsKey = []byte{0x30} + ParamsKey = collections.NewPrefix(48) - // KeyConstitution is the key string used to store the chain's constitution - KeyConstitution = []byte("constitution") + // ConstitutionKey is the key string used to store the chain's constitution + ConstitutionKey = collections.NewPrefix(49) ) var lenTime = len(sdk.FormatTimeBytes(time.Now()))