From c8d33775985e5b911ca44b9ac19dbb09bd0fd108 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 13:10:33 +0200 Subject: [PATCH 01/12] migrate consensus to collections --- baseapp/abci.go | 9 +- baseapp/baseapp.go | 12 +-- baseapp/baseapp_test.go | 10 +- baseapp/params.go | 4 +- baseapp/params_legacy.go | 2 +- baseapp/utils_test.go | 14 +-- server/export_test.go | 4 +- server/types/app.go | 2 +- simapp/app.go | 2 +- simapp/upgrades.go | 2 +- types/context.go | 8 +- types/context_test.go | 2 +- x/consensus/keeper/grpc_query.go | 35 ------- x/consensus/keeper/grpc_query_test.go | 61 ------------- x/consensus/keeper/keeper.go | 78 +++++++++++----- x/consensus/keeper/keeper_test.go | 126 ++++++++++++++++++++++++-- x/consensus/keeper/msg_server.go | 42 --------- x/consensus/keeper/msg_server_test.go | 65 ------------- x/consensus/module.go | 2 +- x/consensus/types/keys.go | 2 - x/evidence/keeper/infraction.go | 2 +- x/genutil/types/genesis.go | 2 +- x/staking/keeper/msg_server.go | 2 +- x/upgrade/abci.go | 2 +- 24 files changed, 214 insertions(+), 276 deletions(-) delete mode 100644 x/consensus/keeper/grpc_query.go delete mode 100644 x/consensus/keeper/grpc_query_test.go delete mode 100644 x/consensus/keeper/msg_server.go delete mode 100644 x/consensus/keeper/msg_server_test.go diff --git a/baseapp/abci.go b/baseapp/abci.go index 09c22b6e3a3e..87991504f91b 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -66,7 +66,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // done after the deliver state and context have been set as it's persisted // to state. if req.ConsensusParams != nil { - err := app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams) + err := app.StoreConsensusParams(app.deliverState.ctx, *req.ConsensusParams) if err != nil { panic(err) } @@ -238,9 +238,8 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc res.Events = sdk.MarkEventsToIndex(res.Events, app.indexEvents) } - if cp := app.GetConsensusParams(app.deliverState.ctx); cp != nil { - res.ConsensusParamUpdates = cp - } + cp := app.GetConsensusParams(app.deliverState.ctx) + res.ConsensusParamUpdates = &cp // call the streaming service hook with the EndBlock messages for _, abciListener := range app.streamingManager.ABCIListeners { @@ -864,7 +863,7 @@ func (app *BaseApp) GetBlockRetentionHeight(commitHeight int64) int64 { // on the unbonding period and block commitment time as the two should be // equivalent. cp := app.GetConsensusParams(app.deliverState.ctx) - if cp != nil && cp.Evidence != nil && cp.Evidence.MaxAgeNumBlocks > 0 { + if cp.Evidence != nil && cp.Evidence.MaxAgeNumBlocks > 0 { retentionHeight = commitHeight - cp.Evidence.MaxAgeNumBlocks } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 1b3f627034a9..7f8440cd0a56 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -434,9 +434,9 @@ func (app *BaseApp) setState(mode runTxMode, header cmtproto.Header) { // GetConsensusParams returns the current consensus parameters from the BaseApp's // ParamStore. If the BaseApp has no ParamStore defined, nil is returned. -func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *cmtproto.ConsensusParams { +func (app *BaseApp) GetConsensusParams(ctx sdk.Context) cmtproto.ConsensusParams { if app.paramStore == nil { - return nil + panic("param store not set") } cp, err := app.paramStore.Get(ctx) @@ -448,15 +448,11 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *cmtproto.ConsensusParam } // StoreConsensusParams sets the consensus parameters to the baseapp's param store. -func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *cmtproto.ConsensusParams) error { +func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp cmtproto.ConsensusParams) error { if app.paramStore == nil { panic("cannot store consensus params with no params store set") } - if cp == nil { - return nil - } - return app.paramStore.Set(ctx, cp) // We're explicitly not storing the CometBFT app_version in the param store. It's // stored instead in the x/upgrade store, with its own bump logic. @@ -474,7 +470,7 @@ func (app *BaseApp) AddRunTxRecoveryHandler(handlers ...RecoveryHandler) { // one. func (app *BaseApp) GetMaximumBlockGas(ctx sdk.Context) uint64 { cp := app.GetConsensusParams(ctx) - if cp == nil || cp.Block == nil { + if cp.Block == nil { return 0 } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 47b06cf5ddf9..5b367c729bda 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -67,7 +67,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite app.SetInterfaceRegistry(cdc.InterfaceRegistry()) app.MsgServiceRouter().SetInterfaceRegistry(cdc.InterfaceRegistry()) app.MountStores(capKey1, capKey2) - app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) + app.SetParamStore(paramStore{db: dbm.NewMemDB()}) app.SetTxDecoder(txConfig.TxDecoder()) app.SetTxEncoder(txConfig.TxEncoder()) @@ -587,16 +587,16 @@ func TestGetMaximumBlockGas(t *testing.T) { suite.baseApp.InitChain(abci.RequestInitChain{}) ctx := suite.baseApp.NewContext(true, cmtproto.Header{}) - suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 0}}) + suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 0}}) require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx)) - suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -1}}) + suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -1}}) require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx)) - suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 5000000}}) + suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 5000000}}) require.Equal(t, uint64(5000000), suite.baseApp.GetMaximumBlockGas(ctx)) - suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -5000000}}) + suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -5000000}}) require.Panics(t, func() { suite.baseApp.GetMaximumBlockGas(ctx) }) } diff --git a/baseapp/params.go b/baseapp/params.go index 35628f5870dc..329ec1255b6f 100644 --- a/baseapp/params.go +++ b/baseapp/params.go @@ -9,7 +9,7 @@ import ( // ParamStore defines the interface the parameter store used by the BaseApp must // fulfill. type ParamStore interface { - Get(ctx context.Context) (*cmtproto.ConsensusParams, error) + Get(ctx context.Context) (cmtproto.ConsensusParams, error) Has(ctx context.Context) (bool, error) - Set(ctx context.Context, cp *cmtproto.ConsensusParams) error + Set(ctx context.Context, cp cmtproto.ConsensusParams) error } diff --git a/baseapp/params_legacy.go b/baseapp/params_legacy.go index c8770cc6c091..4634742e84e6 100644 --- a/baseapp/params_legacy.go +++ b/baseapp/params_legacy.go @@ -140,7 +140,7 @@ func GetConsensusParams(ctx sdk.Context, paramStore LegacyParamStore) *cmtproto. func MigrateParams(ctx sdk.Context, lps LegacyParamStore, ps ParamStore) { if cp := GetConsensusParams(ctx, lps); cp != nil { - ps.Set(ctx, cp) + ps.Set(ctx, *cp) } else { ctx.Logger().Info("warning: consensus parameters are undefined; skipping migration") } diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 385184af5e77..cbdee8a0c347 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -241,7 +241,7 @@ type paramStore struct { var _ baseapp.ParamStore = (*paramStore)(nil) -func (ps *paramStore) Set(_ context.Context, value *cmtproto.ConsensusParams) error { +func (ps paramStore) Set(_ context.Context, value cmtproto.ConsensusParams) error { bz, err := json.Marshal(value) if err != nil { return err @@ -250,26 +250,26 @@ func (ps *paramStore) Set(_ context.Context, value *cmtproto.ConsensusParams) er return ps.db.Set(ParamStoreKey, bz) } -func (ps *paramStore) Has(_ context.Context) (bool, error) { +func (ps paramStore) Has(_ context.Context) (bool, error) { return ps.db.Has(ParamStoreKey) } -func (ps paramStore) Get(ctx context.Context) (*cmtproto.ConsensusParams, error) { +func (ps paramStore) Get(_ context.Context) (cmtproto.ConsensusParams, error) { bz, err := ps.db.Get(ParamStoreKey) if err != nil { - return nil, err + return cmtproto.ConsensusParams{}, err } if len(bz) == 0 { - return nil, errors.New("params not found") + return cmtproto.ConsensusParams{}, errors.New("params not found") } var params cmtproto.ConsensusParams if err := json.Unmarshal(bz, ¶ms); err != nil { - return nil, err + return cmtproto.ConsensusParams{}, err } - return ¶ms, nil + return params, nil } func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) { diff --git a/server/export_test.go b/server/export_test.go index 3ec00032c1c1..6d1886469181 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -101,7 +101,7 @@ func isZeroExportedApp(a types.ExportedApp) bool { return a.AppState == nil && len(a.Validators) == 0 && a.Height == 0 && - a.ConsensusParams == nil + a.ConsensusParams == cmtproto.ConsensusParams{} } // mockExporter provides an Export method matching server/types.AppExporter, @@ -127,7 +127,7 @@ type mockExporter struct { // when e.Export is called. func (e *mockExporter) SetDefaultExportApp() { e.ExportApp = types.ExportedApp{ - ConsensusParams: &cmtproto.ConsensusParams{ + ConsensusParams: cmtproto.ConsensusParams{ Block: &cmtproto.BlockParams{ MaxBytes: 5 * 1024 * 1024, MaxGas: -1, diff --git a/server/types/app.go b/server/types/app.go index 7f47f063e9c7..6b8bf79e118b 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -73,7 +73,7 @@ type ( // Height is the app's latest block height. Height int64 // ConsensusParams are the exported consensus params for ABCI. - ConsensusParams *cmtproto.ConsensusParams + ConsensusParams cmtproto.ConsensusParams } // AppExporter is a function that dumps all app state to diff --git a/simapp/app.go b/simapp/app.go index 61ff5568319d..c262b1c16cf0 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -286,7 +286,7 @@ func NewSimApp( // set the BaseApp's parameter store app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String()) - bApp.SetParamStore(&app.ConsensusParamsKeeper) + bApp.SetParamStore(app.ConsensusParamsKeeper.Params) // add keepers app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, keys[authtypes.StoreKey], authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) diff --git a/simapp/upgrades.go b/simapp/upgrades.go index 891d72d4767a..6d669dbada13 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -64,7 +64,7 @@ func (app SimApp) RegisterUpgradeHandlers() { UpgradeName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // Migrate CometBFT consensus parameters from x/params module to a dedicated x/consensus module. - baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper) + baseapp.MigrateParams(ctx, baseAppLegacySS, app.ConsensusParamsKeeper.Params) // Note: this migration is optional, // You can include x/gov proposal migration documented in [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md) diff --git a/types/context.go b/types/context.go index c4e047dc7272..da17b1881fca 100644 --- a/types/context.go +++ b/types/context.go @@ -35,7 +35,7 @@ type Context struct { checkTx bool recheckTx bool // if recheckTx == true, then checkTx must also be true minGasPrice DecCoins - consParams *cmtproto.ConsensusParams + consParams cmtproto.ConsensusParams eventManager EventManagerI priority int64 // The tx priority, only relevant in CheckTx kvGasConfig storetypes.GasConfig @@ -79,8 +79,8 @@ func (c Context) HeaderHash() []byte { return hash } -func (c Context) ConsensusParams() *cmtproto.ConsensusParams { - return proto.Clone(c.consParams).(*cmtproto.ConsensusParams) +func (c Context) ConsensusParams() cmtproto.ConsensusParams { + return c.consParams } func (c Context) Deadline() (deadline time.Time, ok bool) { @@ -239,7 +239,7 @@ func (c Context) WithMinGasPrices(gasPrices DecCoins) Context { } // WithConsensusParams returns a Context with an updated consensus params -func (c Context) WithConsensusParams(params *cmtproto.ConsensusParams) Context { +func (c Context) WithConsensusParams(params cmtproto.ConsensusParams) Context { c.consParams = params return c } diff --git a/types/context_test.go b/types/context_test.go index fb51ce739f00..ffef7f46132a 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -135,7 +135,7 @@ func (s *contextTestSuite) TestContextWithCustom() { // test consensus param s.Require().Nil(ctx.ConsensusParams()) - cp := &cmtproto.ConsensusParams{} + cp := cmtproto.ConsensusParams{} s.Require().Equal(cp, ctx.WithConsensusParams(cp).ConsensusParams()) // test inner context diff --git a/x/consensus/keeper/grpc_query.go b/x/consensus/keeper/grpc_query.go deleted file mode 100644 index 9477e5951749..000000000000 --- a/x/consensus/keeper/grpc_query.go +++ /dev/null @@ -1,35 +0,0 @@ -package keeper - -import ( - "context" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/consensus/types" -) - -var _ types.QueryServer = Querier{} - -// Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper -type Querier struct { - Keeper -} - -// NewQuerier constructor for the Querier struct -func NewQuerier(keeper Keeper) Querier { - return Querier{Keeper: keeper} -} - -// Params queries params of consensus module -func (k Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - - params, err := k.Keeper.Get(sdkCtx) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - return &types.QueryParamsResponse{Params: params}, nil -} diff --git a/x/consensus/keeper/grpc_query_test.go b/x/consensus/keeper/grpc_query_test.go deleted file mode 100644 index eeee2ccf5cbc..000000000000 --- a/x/consensus/keeper/grpc_query_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package keeper_test - -import ( - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttypes "github.com/cometbft/cometbft/types" - - "github.com/cosmos/cosmos-sdk/x/consensus/types" -) - -func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() { - defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto() - - testCases := []struct { - msg string - req types.QueryParamsRequest - malleate func() - response types.QueryParamsResponse - expPass bool - }{ - { - "success", - types.QueryParamsRequest{}, - func() { - input := &types.MsgUpdateParams{ - Authority: s.consensusParamsKeeper.GetAuthority(), - Block: defaultConsensusParams.Block, - Validator: defaultConsensusParams.Validator, - Evidence: defaultConsensusParams.Evidence, - } - s.msgServer.UpdateParams(s.ctx, input) - }, - types.QueryParamsResponse{ - Params: &cmtproto.ConsensusParams{ - Block: defaultConsensusParams.Block, - Validator: defaultConsensusParams.Validator, - Evidence: defaultConsensusParams.Evidence, - Version: defaultConsensusParams.Version, - }, - }, - true, - }, - } - - for _, tc := range testCases { - s.Run(tc.msg, func() { - s.SetupTest() // reset - - tc.malleate() - res, err := s.queryClient.Params(s.ctx, &tc.req) - - if tc.expPass { - s.Require().NoError(err) - s.Require().NotNil(res) - s.Require().Equal(tc.response.Params, res.Params) - } else { - s.Require().Error(err) - s.Require().Nil(res) - } - }) - } -} diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index d2e9efef6fd3..bd6481ec5491 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -3,29 +3,40 @@ package keeper import ( "context" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - + "cosmossdk.io/collections" storetypes "cosmossdk.io/core/store" + "cosmossdk.io/errors" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmttypes "github.com/cometbft/cometbft/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/consensus/exported" "github.com/cosmos/cosmos-sdk/x/consensus/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -var _ exported.ConsensusParamSetter = (*Keeper)(nil) +var ( + ParamsPrefix = collections.NewPrefix(0) + StoreKey = "consensus" +) type Keeper struct { storeService storetypes.KVStoreService cdc codec.BinaryCodec authority string + Params collections.Item[cmtproto.ConsensusParams] } func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string) Keeper { + sb := collections.NewSchemaBuilder(storeService) return Keeper{ storeService: storeService, cdc: cdc, authority: authority, + + Params: collections.NewItem(sb, ParamsPrefix, StoreKey, codec.CollValue[cmtproto.ConsensusParams](cdc)), } } @@ -33,30 +44,55 @@ func (k *Keeper) GetAuthority() string { return k.authority } -// Get gets the consensus parameters -func (k *Keeper) Get(ctx context.Context) (*cmtproto.ConsensusParams, error) { - store := k.storeService.OpenKVStore(ctx) +// Querier + +var _ types.QueryServer = Querier{} - bz, err := store.Get(types.ParamStoreKeyConsensusParams) +// Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper +type Querier struct { + Keeper +} + +// NewQuerier constructor for the Querier struct +func NewQuerier(keeper Keeper) Querier { + return Querier{Keeper: keeper} +} + +// Params queries params of consensus module +func (k Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + params, err := k.Keeper.Params.Get(ctx) if err != nil { - return nil, err + return nil, status.Error(codes.Internal, err.Error()) } - cp := &cmtproto.ConsensusParams{} - if err := k.cdc.Unmarshal(bz, cp); err != nil { - return nil, err - } + return &types.QueryParamsResponse{Params: ¶ms}, nil +} - return cp, nil +// MsgServer + +type msgServer struct { + Keeper } -func (k *Keeper) Has(ctx context.Context) (bool, error) { - store := k.storeService.OpenKVStore(ctx) - return store.Has(types.ParamStoreKeyConsensusParams) +var _ types.MsgServer = msgServer{} + +// NewMsgServerImpl returns an implementation of the bank MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} } -// Set sets the consensus parameters -func (k *Keeper) Set(ctx context.Context, cp *cmtproto.ConsensusParams) error { - store := k.storeService.OpenKVStore(ctx) - return store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp)) +func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if k.GetAuthority() != req.Authority { + return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + consensusParams := req.ToProtoConsensusParams() + if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil { + return nil, err + } + + k.Params.Set(ctx, consensusParams) + + return &types.MsgUpdateParamsResponse{}, nil } diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 2ac0108c3581..74e7fe13b572 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -4,6 +4,7 @@ import ( "testing" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmttypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/suite" storetypes "cosmossdk.io/store/types" @@ -15,7 +16,7 @@ import ( moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" - consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + "github.com/cosmos/cosmos-sdk/x/consensus/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -24,12 +25,12 @@ type KeeperTestSuite struct { ctx sdk.Context consensusParamsKeeper *consensusparamkeeper.Keeper - queryClient consensusparamtypes.QueryClient - msgServer consensusparamtypes.MsgServer + queryClient types.QueryClient + msgServer types.MsgServer } func (s *KeeperTestSuite) SetupTest() { - key := storetypes.NewKVStoreKey(consensusparamtypes.StoreKey) + key := storetypes.NewKVStoreKey(consensusparamkeeper.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{}) encCfg := moduletestutil.MakeTestEncodingConfig() @@ -40,13 +41,124 @@ func (s *KeeperTestSuite) SetupTest() { s.ctx = ctx s.consensusParamsKeeper = &keeper - consensusparamtypes.RegisterInterfaces(encCfg.InterfaceRegistry) + types.RegisterInterfaces(encCfg.InterfaceRegistry) queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) - consensusparamtypes.RegisterQueryServer(queryHelper, consensusparamkeeper.NewQuerier(keeper)) - s.queryClient = consensusparamtypes.NewQueryClient(queryHelper) + types.RegisterQueryServer(queryHelper, consensusparamkeeper.NewQuerier(keeper)) + s.queryClient = types.NewQueryClient(queryHelper) s.msgServer = consensusparamkeeper.NewMsgServerImpl(keeper) } func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } + +func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() { + defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto() + + testCases := []struct { + msg string + req types.QueryParamsRequest + malleate func() + response types.QueryParamsResponse + expPass bool + }{ + { + "success", + types.QueryParamsRequest{}, + func() { + input := &types.MsgUpdateParams{ + Authority: s.consensusParamsKeeper.GetAuthority(), + Block: defaultConsensusParams.Block, + Validator: defaultConsensusParams.Validator, + Evidence: defaultConsensusParams.Evidence, + } + s.msgServer.UpdateParams(s.ctx, input) + }, + types.QueryParamsResponse{ + Params: &cmtproto.ConsensusParams{ + Block: defaultConsensusParams.Block, + Validator: defaultConsensusParams.Validator, + Evidence: defaultConsensusParams.Evidence, + Version: defaultConsensusParams.Version, + }, + }, + true, + }, + } + + for _, tc := range testCases { + s.Run(tc.msg, func() { + s.SetupTest() // reset + + tc.malleate() + res, err := s.queryClient.Params(s.ctx, &tc.req) + + if tc.expPass { + s.Require().NoError(err) + s.Require().NotNil(res) + s.Require().Equal(tc.response.Params, res.Params) + } else { + s.Require().Error(err) + s.Require().Nil(res) + } + }) + } +} + +func (s *KeeperTestSuite) TestUpdateParams() { + defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto() + testCases := []struct { + name string + input *types.MsgUpdateParams + expErr bool + expErrMsg string + }{ + { + name: "valid params", + input: &types.MsgUpdateParams{ + Authority: s.consensusParamsKeeper.GetAuthority(), + Block: defaultConsensusParams.Block, + Validator: defaultConsensusParams.Validator, + Evidence: defaultConsensusParams.Evidence, + }, + expErr: false, + expErrMsg: "", + }, + { + name: "invalid params", + input: &types.MsgUpdateParams{ + Authority: s.consensusParamsKeeper.GetAuthority(), + Block: &cmtproto.BlockParams{MaxGas: -10, MaxBytes: -10}, + Validator: defaultConsensusParams.Validator, + Evidence: defaultConsensusParams.Evidence, + }, + expErr: true, + expErrMsg: "block.MaxBytes must be greater than 0. Got -10", + }, + { + name: "invalid authority", + input: &types.MsgUpdateParams{ + Authority: "invalid", + Block: defaultConsensusParams.Block, + Validator: defaultConsensusParams.Validator, + Evidence: defaultConsensusParams.Evidence, + }, + expErr: true, + expErrMsg: "invalid authority", + }, + } + + for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { + s.SetupTest() + _, err := s.msgServer.UpdateParams(s.ctx, tc.input) + if tc.expErr { + s.Require().Error(err) + s.Require().Contains(err.Error(), tc.expErrMsg) + } else { + s.Require().NoError(err) + } + }) + } +} diff --git a/x/consensus/keeper/msg_server.go b/x/consensus/keeper/msg_server.go deleted file mode 100644 index ed43cfdf29e5..000000000000 --- a/x/consensus/keeper/msg_server.go +++ /dev/null @@ -1,42 +0,0 @@ -package keeper - -import ( - "context" - - cmttypes "github.com/cometbft/cometbft/types" - - "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/consensus/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" -) - -type msgServer struct { - Keeper -} - -var _ types.MsgServer = msgServer{} - -// NewMsgServerImpl returns an implementation of the bank MsgServer interface -// for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} -} - -func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { - if k.GetAuthority() != req.Authority { - return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) - } - - ctx := sdk.UnwrapSDKContext(goCtx) - - consensusParams := req.ToProtoConsensusParams() - if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil { - return nil, err - } - - k.Set(ctx, &consensusParams) - - return &types.MsgUpdateParamsResponse{}, nil -} diff --git a/x/consensus/keeper/msg_server_test.go b/x/consensus/keeper/msg_server_test.go deleted file mode 100644 index 0de099a83e82..000000000000 --- a/x/consensus/keeper/msg_server_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package keeper_test - -import ( - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttypes "github.com/cometbft/cometbft/types" - "github.com/cosmos/cosmos-sdk/x/consensus/types" -) - -func (s *KeeperTestSuite) TestUpdateParams() { - defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto() - testCases := []struct { - name string - input *types.MsgUpdateParams - expErr bool - expErrMsg string - }{ - { - name: "valid params", - input: &types.MsgUpdateParams{ - Authority: s.consensusParamsKeeper.GetAuthority(), - Block: defaultConsensusParams.Block, - Validator: defaultConsensusParams.Validator, - Evidence: defaultConsensusParams.Evidence, - }, - expErr: false, - expErrMsg: "", - }, - { - name: "invalid params", - input: &types.MsgUpdateParams{ - Authority: s.consensusParamsKeeper.GetAuthority(), - Block: &cmtproto.BlockParams{MaxGas: -10, MaxBytes: -10}, - Validator: defaultConsensusParams.Validator, - Evidence: defaultConsensusParams.Evidence, - }, - expErr: true, - expErrMsg: "block.MaxBytes must be greater than 0. Got -10", - }, - { - name: "invalid authority", - input: &types.MsgUpdateParams{ - Authority: "invalid", - Block: defaultConsensusParams.Block, - Validator: defaultConsensusParams.Validator, - Evidence: defaultConsensusParams.Evidence, - }, - expErr: true, - expErrMsg: "invalid authority", - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - s.SetupTest() - _, err := s.msgServer.UpdateParams(s.ctx, tc.input) - if tc.expErr { - s.Require().Error(err) - s.Require().Contains(err.Error(), tc.expErrMsg) - } else { - s.Require().NoError(err) - } - }) - } -} diff --git a/x/consensus/module.go b/x/consensus/module.go index 8c6f87346daa..b58cea26d02e 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -168,7 +168,7 @@ func ProvideModule(in ConsensusInputs) ConsensusOutputs { k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String()) m := NewAppModule(in.Cdc, k) baseappOpt := func(app *baseapp.BaseApp) { - app.SetParamStore(&k) + app.SetParamStore(k.Params) } return ConsensusOutputs{ diff --git a/x/consensus/types/keys.go b/x/consensus/types/keys.go index 5ce0fc2cbe4a..2bdad4c21dd4 100644 --- a/x/consensus/types/keys.go +++ b/x/consensus/types/keys.go @@ -7,5 +7,3 @@ const ( // StoreKey defines the module's store key. StoreKey = ModuleName ) - -var ParamStoreKeyConsensusParams = []byte("Consensus") diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index b9713c01fc30..9526c0a29ffe 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -50,7 +50,7 @@ func (k Keeper) handleEquivocationEvidence(ctx sdk.Context, evidence *types.Equi // if the difference in time and number of blocks is greater than the allowed // parameters defined. cp := ctx.ConsensusParams() - if cp != nil && cp.Evidence != nil { + if cp.Evidence != nil { if ageDuration > cp.Evidence.MaxAgeDuration && ageBlocks > cp.Evidence.MaxAgeNumBlocks { logger.Info( "ignored equivocation; evidence too old", diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index ffd601d2b703..8b9d55a72b2f 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -142,7 +142,7 @@ type ConsensusGenesis struct { // NewConsensusGenesis returns a ConsensusGenesis with given values. // It takes a proto consensus params so it can called from server export command. -func NewConsensusGenesis(params *cmtproto.ConsensusParams, validators []cmttypes.GenesisValidator) *ConsensusGenesis { +func NewConsensusGenesis(params cmtproto.ConsensusParams, validators []cmttypes.GenesisValidator) *ConsensusGenesis { return &ConsensusGenesis{ Params: &cmttypes.ConsensusParams{ Block: cmttypes.BlockParams{ diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 9d7113113f1b..2f878e7d7487 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -70,7 +70,7 @@ func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateVa } cp := ctx.ConsensusParams() - if cp != nil && cp.Validator != nil { + if cp.Validator != nil { pkType := pk.Type() hasKeyType := false for _, keyType := range cp.Validator.PubKeyTypes { diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index 90eb2962858d..ae72c678edf2 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -38,7 +38,7 @@ func BeginBlocker(k *keeper.Keeper, ctx sdk.Context) { var appVersion uint64 cp := ctx.ConsensusParams() - if cp != nil && cp.Version != nil { + if cp.Version != nil { appVersion = cp.Version.App } From fd46770260e6bd2c5c39a12998d620cb18557fc8 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 13:15:06 +0200 Subject: [PATCH 02/12] fix tests --- types/context_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/context_test.go b/types/context_test.go index ffef7f46132a..e4d7e818e9fb 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -134,7 +134,7 @@ func (s *contextTestSuite) TestContextWithCustom() { s.Require().True(ctx.IsReCheckTx()) // test consensus param - s.Require().Nil(ctx.ConsensusParams()) + s.Require().Equal(cmtproto.ConsensusParams{}, ctx.ConsensusParams()) cp := cmtproto.ConsensusParams{} s.Require().Equal(cp, ctx.WithConsensusParams(cp).ConsensusParams()) From 774c88f3c77f8bfc6945066f9a42c544ba68cab6 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 13:20:31 +0200 Subject: [PATCH 03/12] reduce it all to the keeper --- api/cosmos/consensus/v1/query.pulsar.go | 50 ++++++++++++------------ api/cosmos/consensus/v1/query_grpc.pb.go | 26 ++++++------ proto/cosmos/consensus/v1/query.proto | 2 +- x/consensus/keeper/keeper.go | 30 +++----------- x/consensus/keeper/keeper_test.go | 10 ++--- x/consensus/module.go | 4 +- x/consensus/types/query.pb.go | 42 ++++++++++---------- x/consensus/types/query.pb.gw.go | 24 ++++++------ 8 files changed, 83 insertions(+), 105 deletions(-) diff --git a/api/cosmos/consensus/v1/query.pulsar.go b/api/cosmos/consensus/v1/query.pulsar.go index 2e60bb1777e1..d5b8da7480a9 100644 --- a/api/cosmos/consensus/v1/query.pulsar.go +++ b/api/cosmos/consensus/v1/query.pulsar.go @@ -902,29 +902,29 @@ var file_cosmos_consensus_v1_query_proto_rawDesc = []byte{ 0x12, 0x39, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x50, 0x61, 0x72, - 0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x32, 0x8a, 0x01, 0x0a, 0x05, - 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x80, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, - 0x12, 0x27, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, - 0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x2e, - 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x23, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1d, 0x12, 0x1b, 0x2f, 0x63, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2f, 0x76, - 0x31, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xc5, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, - 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, - 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x50, 0x01, 0x5a, 0x30, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, - 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73, - 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, - 0x75, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e, 0x56, 0x31, - 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, - 0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, - 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, - 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x3a, 0x3a, 0x56, 0x31, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x32, 0x8d, 0x01, 0x0a, 0x05, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x83, 0x01, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x50, 0x61, 0x72, + 0x61, 0x6d, 0x73, 0x12, 0x27, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, + 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, + 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e, + 0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x23, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1d, 0x12, 0x1b, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, + 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xc5, 0x01, 0x0a, 0x17, + 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, + 0x6e, 0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, + 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, + 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, + 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6e, 0x73, + 0x65, 0x6e, 0x73, 0x75, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x13, + 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, + 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x6f, 0x6e, + 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x5c, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0x5c, + 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x15, 0x43, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x3a, + 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -947,8 +947,8 @@ var file_cosmos_consensus_v1_query_proto_goTypes = []interface{}{ } var file_cosmos_consensus_v1_query_proto_depIdxs = []int32{ 2, // 0: cosmos.consensus.v1.QueryParamsResponse.params:type_name -> tendermint.types.ConsensusParams - 0, // 1: cosmos.consensus.v1.Query.Params:input_type -> cosmos.consensus.v1.QueryParamsRequest - 1, // 2: cosmos.consensus.v1.Query.Params:output_type -> cosmos.consensus.v1.QueryParamsResponse + 0, // 1: cosmos.consensus.v1.Query.GetParams:input_type -> cosmos.consensus.v1.QueryParamsRequest + 1, // 2: cosmos.consensus.v1.Query.GetParams:output_type -> cosmos.consensus.v1.QueryParamsResponse 2, // [2:3] is the sub-list for method output_type 1, // [1:2] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name diff --git a/api/cosmos/consensus/v1/query_grpc.pb.go b/api/cosmos/consensus/v1/query_grpc.pb.go index add845baa4a5..456e8d6bfab6 100644 --- a/api/cosmos/consensus/v1/query_grpc.pb.go +++ b/api/cosmos/consensus/v1/query_grpc.pb.go @@ -21,7 +21,7 @@ import ( const _ = grpc.SupportPackageIsVersion7 const ( - Query_Params_FullMethodName = "/cosmos.consensus.v1.Query/Params" + Query_GetParams_FullMethodName = "/cosmos.consensus.v1.Query/GetParams" ) // QueryClient is the client API for Query service. @@ -29,7 +29,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type QueryClient interface { // Params queries the parameters of x/consensus_param module. - Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } type queryClient struct { @@ -40,9 +40,9 @@ func NewQueryClient(cc grpc.ClientConnInterface) QueryClient { return &queryClient{cc} } -func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { +func (c *queryClient) GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, Query_Params_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Query_GetParams_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -54,7 +54,7 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . // for forward compatibility type QueryServer interface { // Params queries the parameters of x/consensus_param module. - Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + GetParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) mustEmbedUnimplementedQueryServer() } @@ -62,8 +62,8 @@ type QueryServer interface { type UnimplementedQueryServer struct { } -func (UnimplementedQueryServer) Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +func (UnimplementedQueryServer) GetParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetParams not implemented") } func (UnimplementedQueryServer) mustEmbedUnimplementedQueryServer() {} @@ -78,20 +78,20 @@ func RegisterQueryServer(s grpc.ServiceRegistrar, srv QueryServer) { s.RegisterService(&Query_ServiceDesc, srv) } -func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Query_GetParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryParamsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).Params(ctx, in) + return srv.(QueryServer).GetParams(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: Query_Params_FullMethodName, + FullMethod: Query_GetParams_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + return srv.(QueryServer).GetParams(ctx, req.(*QueryParamsRequest)) } return interceptor(ctx, in, info, handler) } @@ -104,8 +104,8 @@ var Query_ServiceDesc = grpc.ServiceDesc{ HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Params", - Handler: _Query_Params_Handler, + MethodName: "GetParams", + Handler: _Query_GetParams_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/proto/cosmos/consensus/v1/query.proto b/proto/cosmos/consensus/v1/query.proto index cdcb07ba4100..ffd30cc572a3 100644 --- a/proto/cosmos/consensus/v1/query.proto +++ b/proto/cosmos/consensus/v1/query.proto @@ -10,7 +10,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/consensus/types"; // Query defines the gRPC querier service. service Query { // Params queries the parameters of x/consensus_param module. - rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + rpc GetParams(QueryParamsRequest) returns (QueryParamsResponse) { option (google.api.http).get = "/cosmos/consensus/v1/params"; } } diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index bd6481ec5491..eeee03cb75e1 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -46,21 +46,11 @@ func (k *Keeper) GetAuthority() string { // Querier -var _ types.QueryServer = Querier{} - -// Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper -type Querier struct { - Keeper -} - -// NewQuerier constructor for the Querier struct -func NewQuerier(keeper Keeper) Querier { - return Querier{Keeper: keeper} -} +var _ types.QueryServer = Keeper{} // Params queries params of consensus module -func (k Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - params, err := k.Keeper.Params.Get(ctx) +func (k Keeper) GetParams(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + params, err := k.Params.Get(ctx) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -70,19 +60,9 @@ func (k Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*type // MsgServer -type msgServer struct { - Keeper -} - -var _ types.MsgServer = msgServer{} - -// NewMsgServerImpl returns an implementation of the bank MsgServer interface -// for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} -} +var _ types.MsgServer = Keeper{} -func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { +func (k Keeper) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if k.GetAuthority() != req.Authority { return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) } diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 74e7fe13b572..7e8e2c4c4143 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -26,7 +26,6 @@ type KeeperTestSuite struct { consensusParamsKeeper *consensusparamkeeper.Keeper queryClient types.QueryClient - msgServer types.MsgServer } func (s *KeeperTestSuite) SetupTest() { @@ -43,9 +42,8 @@ func (s *KeeperTestSuite) SetupTest() { types.RegisterInterfaces(encCfg.InterfaceRegistry) queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) - types.RegisterQueryServer(queryHelper, consensusparamkeeper.NewQuerier(keeper)) + types.RegisterQueryServer(queryHelper, keeper) s.queryClient = types.NewQueryClient(queryHelper) - s.msgServer = consensusparamkeeper.NewMsgServerImpl(keeper) } func TestKeeperTestSuite(t *testing.T) { @@ -72,7 +70,7 @@ func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() { Validator: defaultConsensusParams.Validator, Evidence: defaultConsensusParams.Evidence, } - s.msgServer.UpdateParams(s.ctx, input) + s.consensusParamsKeeper.UpdateParams(s.ctx, input) }, types.QueryParamsResponse{ Params: &cmtproto.ConsensusParams{ @@ -91,7 +89,7 @@ func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() { s.SetupTest() // reset tc.malleate() - res, err := s.queryClient.Params(s.ctx, &tc.req) + res, err := s.consensusParamsKeeper.GetParams(s.ctx, &tc.req) if tc.expPass { s.Require().NoError(err) @@ -152,7 +150,7 @@ func (s *KeeperTestSuite) TestUpdateParams() { tc := tc s.Run(tc.name, func() { s.SetupTest() - _, err := s.msgServer.UpdateParams(s.ctx, tc.input) + _, err := s.consensusParamsKeeper.UpdateParams(s.ctx, tc.input) if tc.expErr { s.Require().Error(err) s.Require().Contains(err.Error(), tc.expErrMsg) diff --git a/x/consensus/module.go b/x/consensus/module.go index b58cea26d02e..1e2f5dec4211 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -102,8 +102,8 @@ func (am AppModule) IsAppModule() {} // RegisterServices registers module services. func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { - types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper)) - types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper)) + types.RegisterMsgServer(registrar, am.keeper) + types.RegisterQueryServer(registrar, am.keeper) return nil } diff --git a/x/consensus/types/query.pb.go b/x/consensus/types/query.pb.go index b6f6df03ec71..f2b942f2c2d3 100644 --- a/x/consensus/types/query.pb.go +++ b/x/consensus/types/query.pb.go @@ -122,7 +122,7 @@ func init() { func init() { proto.RegisterFile("cosmos/consensus/v1/query.proto", fileDescriptor_bf54d1e5df04cee9) } var fileDescriptor_bf54d1e5df04cee9 = []byte{ - // 279 bytes of a gzipped FileDescriptorProto + // 282 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0xce, 0xcf, 0x2b, 0x4e, 0xcd, 0x2b, 0x2e, 0x2d, 0xd6, 0x2f, 0x33, 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0x28, 0xd0, @@ -133,14 +133,14 @@ var fileDescriptor_bf54d1e5df04cee9 = []byte{ 0x08, 0x00, 0x0b, 0x06, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x28, 0x05, 0x70, 0x09, 0xa3, 0x88, 0x16, 0x17, 0x80, 0x2c, 0x14, 0xb2, 0xe4, 0x62, 0x83, 0x68, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd4, 0x43, 0x18, 0xae, 0x07, 0x36, 0x5c, 0xcf, 0x19, 0xe6, 0x32, 0xa8, 0x56, 0xa8, - 0x06, 0xa3, 0x2e, 0x46, 0x2e, 0x56, 0xb0, 0x91, 0x42, 0x0d, 0x8c, 0x5c, 0x6c, 0x10, 0x49, 0x21, - 0x75, 0x3d, 0x2c, 0xfe, 0xd1, 0xc3, 0x74, 0x8f, 0x94, 0x06, 0x61, 0x85, 0x10, 0x27, 0x2a, 0x29, - 0x37, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x56, 0x48, 0x5a, 0x1f, 0x5b, 0x58, 0x42, 0x1c, 0xe3, 0xe4, - 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, - 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x7a, 0xe9, 0x99, 0x25, 0x19, - 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0x08, 0x03, 0x40, 0x94, 0x6e, 0x71, 0x4a, 0xb6, 0x7e, 0x05, - 0x92, 0x69, 0x60, 0xef, 0x26, 0xb1, 0x81, 0x43, 0xd1, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x1b, - 0xa2, 0x35, 0xa1, 0xba, 0x01, 0x00, 0x00, + 0x06, 0xa3, 0x5e, 0x46, 0x2e, 0x56, 0xb0, 0x91, 0x42, 0xcd, 0x8c, 0x5c, 0x9c, 0xee, 0xa9, 0x25, + 0x10, 0x79, 0x21, 0x75, 0x3d, 0x2c, 0x5e, 0xd2, 0xc3, 0x74, 0x92, 0x94, 0x06, 0x61, 0x85, 0x10, + 0x57, 0x2a, 0x29, 0x37, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x56, 0x48, 0x5a, 0x1f, 0x5b, 0x70, 0x42, + 0xdc, 0xe3, 0xe4, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, + 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x7a, 0xe9, + 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0x08, 0x03, 0x40, 0x94, 0x6e, 0x71, 0x4a, + 0xb6, 0x7e, 0x05, 0x92, 0x69, 0x60, 0x1f, 0x27, 0xb1, 0x81, 0x03, 0xd2, 0x18, 0x10, 0x00, 0x00, + 0xff, 0xff, 0xbd, 0x10, 0x4d, 0x37, 0xbd, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -156,7 +156,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { // Params queries the parameters of x/consensus_param module. - Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } type queryClient struct { @@ -167,9 +167,9 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { +func (c *queryClient) GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, "/cosmos.consensus.v1.Query/Params", in, out, opts...) + err := c.cc.Invoke(ctx, "/cosmos.consensus.v1.Query/GetParams", in, out, opts...) if err != nil { return nil, err } @@ -179,35 +179,35 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . // QueryServer is the server API for Query service. type QueryServer interface { // Params queries the parameters of x/consensus_param module. - Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + GetParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +func (*UnimplementedQueryServer) GetParams(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetParams not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Query_GetParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryParamsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).Params(ctx, in) + return srv.(QueryServer).GetParams(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.consensus.v1.Query/Params", + FullMethod: "/cosmos.consensus.v1.Query/GetParams", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + return srv.(QueryServer).GetParams(ctx, req.(*QueryParamsRequest)) } return interceptor(ctx, in, info, handler) } @@ -217,8 +217,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{ HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Params", - Handler: _Query_Params_Handler, + MethodName: "GetParams", + Handler: _Query_GetParams_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/x/consensus/types/query.pb.gw.go b/x/consensus/types/query.pb.gw.go index c2bd4deb378f..d80f6893dbc1 100644 --- a/x/consensus/types/query.pb.gw.go +++ b/x/consensus/types/query.pb.gw.go @@ -33,20 +33,20 @@ var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage var _ = metadata.Join -func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_Query_GetParams_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest var metadata runtime.ServerMetadata - msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetParams(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_Query_GetParams_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest var metadata runtime.ServerMetadata - msg, err := server.Params(ctx, &protoReq) + msg, err := server.GetParams(ctx, &protoReq) return msg, metadata, err } @@ -57,7 +57,7 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -68,7 +68,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetParams_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -76,7 +76,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -121,7 +121,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -130,14 +130,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetParams_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -145,9 +145,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "consensus", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetParams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "consensus", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Query_Params_0 = runtime.ForwardResponseMessage + forward_Query_GetParams_0 = runtime.ForwardResponseMessage ) From 5c373d52fc7dd091ea775ad9848c5c30d0cec2ce Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 13:22:47 +0200 Subject: [PATCH 04/12] []byte{} to test --- x/consensus/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index eeee03cb75e1..4ad307bd11d6 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -17,7 +17,7 @@ import ( ) var ( - ParamsPrefix = collections.NewPrefix(0) + ParamsPrefix = collections.NewPrefix([]byte{}) StoreKey = "consensus" ) From d1b4cc40bc4427f68e2c7f65b243586d782e80b3 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 13:31:13 +0200 Subject: [PATCH 05/12] fix error check --- x/consensus/keeper/keeper.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 4ad307bd11d6..d0902eae68cb 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -72,7 +72,9 @@ func (k Keeper) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (* return nil, err } - k.Params.Set(ctx, consensusParams) + if err := k.Params.Set(ctx, consensusParams); err != nil { + return nil, err + } return &types.MsgUpdateParamsResponse{}, nil } From 0179f1586831dff901470ec19eb4a1bf6bbef193 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 13:51:23 +0200 Subject: [PATCH 06/12] minor cleanup --- x/consensus/keeper/keeper.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index d0902eae68cb..9d02b09efdd9 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -23,7 +23,6 @@ var ( type Keeper struct { storeService storetypes.KVStoreService - cdc codec.BinaryCodec authority string Params collections.Item[cmtproto.ConsensusParams] @@ -33,10 +32,8 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, au sb := collections.NewSchemaBuilder(storeService) return Keeper{ storeService: storeService, - cdc: cdc, authority: authority, - - Params: collections.NewItem(sb, ParamsPrefix, StoreKey, codec.CollValue[cmtproto.ConsensusParams](cdc)), + Params: collections.NewItem(sb, ParamsPrefix, StoreKey, codec.CollValue[cmtproto.ConsensusParams](cdc)), } } From 8304b8abc9800827ef6c98120fcfb7c4df187549 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 21:21:26 +0200 Subject: [PATCH 07/12] fix store key --- baseapp/baseapp.go | 2 +- x/consensus/keeper/keeper.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 7f8440cd0a56..a83d372ec738 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -441,7 +441,7 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) cmtproto.ConsensusParams cp, err := app.paramStore.Get(ctx) if err != nil { - panic(err) + panic(fmt.Errorf("consensus key is nil: %w", err)) } return cp diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 9d02b09efdd9..d9440884ffad 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -17,8 +17,9 @@ import ( ) var ( - ParamsPrefix = collections.NewPrefix([]byte{}) - StoreKey = "consensus" + // ParamsPrefix = collections.NewPrefix([]byte{}) + ParamsPrefix = collections.NewPrefix("Consensus") + StoreKey = "Consensus" ) type Keeper struct { @@ -33,7 +34,7 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, au return Keeper{ storeService: storeService, authority: authority, - Params: collections.NewItem(sb, ParamsPrefix, StoreKey, codec.CollValue[cmtproto.ConsensusParams](cdc)), + Params: collections.NewItem(sb, ParamsPrefix, "Consensus", codec.CollValue[cmtproto.ConsensusParams](cdc)), } } From fd01db1e6bf906b0831047f479dc8c4b25d20648 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 21:23:10 +0200 Subject: [PATCH 08/12] return error up the stack --- baseapp/params_legacy.go | 7 +++++-- simapp/upgrades.go | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/baseapp/params_legacy.go b/baseapp/params_legacy.go index 4634742e84e6..13fd34add70e 100644 --- a/baseapp/params_legacy.go +++ b/baseapp/params_legacy.go @@ -138,10 +138,13 @@ func GetConsensusParams(ctx sdk.Context, paramStore LegacyParamStore) *cmtproto. return cp } -func MigrateParams(ctx sdk.Context, lps LegacyParamStore, ps ParamStore) { +func MigrateParams(ctx sdk.Context, lps LegacyParamStore, ps ParamStore) error { if cp := GetConsensusParams(ctx, lps); cp != nil { - ps.Set(ctx, *cp) + if err := ps.Set(ctx, *cp); err != nil { + return err + } } else { ctx.Logger().Info("warning: consensus parameters are undefined; skipping migration") } + return nil } diff --git a/simapp/upgrades.go b/simapp/upgrades.go index 6d669dbada13..fac518315d08 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -64,7 +64,9 @@ func (app SimApp) RegisterUpgradeHandlers() { UpgradeName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // Migrate CometBFT consensus parameters from x/params module to a dedicated x/consensus module. - baseapp.MigrateParams(ctx, baseAppLegacySS, app.ConsensusParamsKeeper.Params) + if err := baseapp.MigrateParams(ctx, baseAppLegacySS, app.ConsensusParamsKeeper.Params); err != nil { + return nil, err + } // Note: this migration is optional, // You can include x/gov proposal migration documented in [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md) From 05fecfa4ec47c59d84087893ef2842c576ce94a6 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 27 Mar 2023 21:24:37 +0200 Subject: [PATCH 09/12] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6fec52e63c8..87c03799b6a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (baseapp) [#15023](https://github.com/cosmos/cosmos-sdk/pull/15023) & [#15213](https://github.com/cosmos/cosmos-sdk/pull/15213) Add `MessageRouter` interface to baseapp and pass it to authz, gov and groups instead of concrete type. * (simtestutil) [#15305](https://github.com/cosmos/cosmos-sdk/pull/15305) Add `AppStateFnWithExtendedCb` with callback function to extend rawState. * (x/distribution) [#15462](https://github.com/cosmos/cosmos-sdk/pull/15462) Add delegator address to the event for withdrawing delegation rewards +* (x/consensus) [#15553](https://github.com/cosmos/cosmos-sdk/pull/15553) Migrate consensus module to use collections ### State Machine Breaking From 52f8f0637f34ebca023214300f88dc0e221993c2 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 28 Mar 2023 10:18:44 +0200 Subject: [PATCH 10/12] dont panic if no paramstore is set --- baseapp/baseapp.go | 2 +- server/mock/app_test.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index a83d372ec738..cba39a846944 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -436,7 +436,7 @@ func (app *BaseApp) setState(mode runTxMode, header cmtproto.Header) { // ParamStore. If the BaseApp has no ParamStore defined, nil is returned. func (app *BaseApp) GetConsensusParams(ctx sdk.Context) cmtproto.ConsensusParams { if app.paramStore == nil { - panic("param store not set") + return cmtproto.ConsensusParams{} } cp, err := app.paramStore.Get(ctx) diff --git a/server/mock/app_test.go b/server/mock/app_test.go index c3fcd15b4ec7..c40dbf67b7c4 100644 --- a/server/mock/app_test.go +++ b/server/mock/app_test.go @@ -5,12 +5,11 @@ import ( "testing" "time" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" - "cosmossdk.io/log" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) From 8f27bd53eab9af352c1edd3aa1081a387f01b113 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 28 Mar 2023 10:23:48 +0200 Subject: [PATCH 11/12] fix proto linting --- proto/cosmos/consensus/v1/query.proto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proto/cosmos/consensus/v1/query.proto b/proto/cosmos/consensus/v1/query.proto index ffd30cc572a3..08884ea1450b 100644 --- a/proto/cosmos/consensus/v1/query.proto +++ b/proto/cosmos/consensus/v1/query.proto @@ -10,16 +10,16 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/consensus/types"; // Query defines the gRPC querier service. service Query { // Params queries the parameters of x/consensus_param module. - rpc GetParams(QueryParamsRequest) returns (QueryParamsResponse) { + rpc GetParams(QueryGetParamsRequest) returns (QueryGetParamsResponse) { option (google.api.http).get = "/cosmos/consensus/v1/params"; } } // QueryParamsRequest defines the request type for querying x/consensus parameters. -message QueryParamsRequest {} +message QueryGetParamsRequest {} // QueryParamsResponse defines the response type for querying x/consensus parameters. -message QueryParamsResponse { +message QueryGetParamsResponse { // params are the tendermint consensus params stored in the consensus module. // Please note that `params.version` is not populated in this response, it is // tracked separately in the x/upgrade module. From dca8d4e9a8a8a8ad23c6ac59b73eeaa6b3413c07 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 28 Mar 2023 15:05:20 +0200 Subject: [PATCH 12/12] address comments --- x/consensus/keeper/keeper.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index d9440884ffad..4e5c8e30b670 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -16,11 +16,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -var ( - // ParamsPrefix = collections.NewPrefix([]byte{}) - ParamsPrefix = collections.NewPrefix("Consensus") - StoreKey = "Consensus" -) +var StoreKey = "Consensus" type Keeper struct { storeService storetypes.KVStoreService @@ -34,7 +30,7 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, au return Keeper{ storeService: storeService, authority: authority, - Params: collections.NewItem(sb, ParamsPrefix, "Consensus", codec.CollValue[cmtproto.ConsensusParams](cdc)), + Params: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)), } }