From 573a53ed48941671ee3d5a151fe60f3131457333 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 22 Mar 2023 16:20:37 -0300 Subject: [PATCH 01/12] refactor!: use KVStoreService in x/consensus --- client/v2/autocli/app.go | 8 +++++--- runtime/module.go | 3 ++- x/consensus/keeper/keeper.go | 33 +++++++++++++++++++++---------- x/consensus/keeper/keeper_test.go | 4 +++- x/consensus/module.go | 10 +++++----- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 32f22afcaec3..b8db2627f2aa 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -1,14 +1,16 @@ package autocli import ( + "fmt" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" - "fmt" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/spf13/cobra" "google.golang.org/grpc" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" ) // AppOptions are autocli options for an app. These options can be built via depinject based on an app config. Ex: diff --git a/runtime/module.go b/runtime/module.go index 30556ba050a6..9f96f662734c 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -17,13 +17,14 @@ import ( storetypes "cosmossdk.io/store/types" + "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/msgservice" - "github.com/cosmos/gogoproto/proto" ) type appModule struct { diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 2702f49abc91..df9b71124b59 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -3,7 +3,7 @@ package keeper import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - storetypes "cosmossdk.io/store/types" + storetypes "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,15 +14,15 @@ import ( var _ exported.ConsensusParamSetter = (*Keeper)(nil) type Keeper struct { - storeKey storetypes.StoreKey + storeSvc storetypes.KVStoreService cdc codec.BinaryCodec authority string } -func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, authority string) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeSvc storetypes.KVStoreService, authority string) Keeper { return Keeper{ - storeKey: storeKey, + storeSvc: storeSvc, cdc: cdc, authority: authority, } @@ -34,10 +34,14 @@ func (k *Keeper) GetAuthority() string { // Get gets the consensus parameters func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { - store := ctx.KVStore(k.storeKey) + store := k.storeSvc.OpenKVStore(ctx) cp := &cmtproto.ConsensusParams{} - bz := store.Get(types.ParamStoreKeyConsensusParams) + bz, err := store.Get(types.ParamStoreKeyConsensusParams) + + if err != nil { + return nil, err + } if err := k.cdc.Unmarshal(bz, cp); err != nil { return nil, err @@ -47,13 +51,22 @@ func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { } func (k *Keeper) Has(ctx sdk.Context) bool { - store := ctx.KVStore(k.storeKey) + store := k.storeSvc.OpenKVStore(ctx) - return store.Has(types.ParamStoreKeyConsensusParams) + has, err := store.Has(types.ParamStoreKeyConsensusParams) + // should never panic given that key is hardcoded + if err != nil { + panic(err) + } + + return has } // Set sets the consensus parameters func (k *Keeper) Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) { - store := ctx.KVStore(k.storeKey) - store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp)) + store := k.storeSvc.OpenKVStore(ctx) + err := store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp)) + if err != nil { + panic(err) + } } diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index e7d4dc1ed44b..c987222634d3 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -32,8 +33,9 @@ func (s *KeeperTestSuite) SetupTest() { testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{}) encCfg := moduletestutil.MakeTestEncodingConfig() + storeSvc := runtime.NewKVStoreService(key) - keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, key, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, storeSvc, authtypes.NewModuleAddress(govtypes.ModuleName).String()) s.ctx = ctx s.consensusParamsKeeper = &keeper diff --git a/x/consensus/module.go b/x/consensus/module.go index 3dd825782ed1..d6af0aa6edf7 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -11,7 +11,7 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" - store "cosmossdk.io/store/types" + storetypes "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -139,9 +139,9 @@ func init() { type ConsensusInputs struct { depinject.In - Config *modulev1.Module - Cdc codec.Codec - Key *store.KVStoreKey + Config *modulev1.Module + Cdc codec.Codec + StoreSvc storetypes.KVStoreService } //nolint:revive @@ -160,7 +160,7 @@ func ProvideModule(in ConsensusInputs) ConsensusOutputs { authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) } - k := keeper.NewKeeper(in.Cdc, in.Key, authority.String()) + k := keeper.NewKeeper(in.Cdc, in.StoreSvc, authority.String()) m := NewAppModule(in.Cdc, k) baseappOpt := func(app *baseapp.BaseApp) { app.SetParamStore(&k) From b3b74d94475f9b90349f189d7b2d1e9d52988fab Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 22 Mar 2023 16:32:05 -0300 Subject: [PATCH 02/12] gpfumpt --- x/consensus/keeper/keeper.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index df9b71124b59..375e4532296d 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -38,7 +38,6 @@ func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { cp := &cmtproto.ConsensusParams{} bz, err := store.Get(types.ParamStoreKeyConsensusParams) - if err != nil { return nil, err } From 13149c6f6881040075681107eca8fda06f672b73 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 22 Mar 2023 16:41:01 -0300 Subject: [PATCH 03/12] revert some unrelated changes --- client/v2/autocli/app.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index b8db2627f2aa..32f22afcaec3 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -1,16 +1,14 @@ package autocli import ( - "fmt" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" - "github.com/spf13/cobra" - "google.golang.org/grpc" - + "fmt" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + "google.golang.org/grpc" ) // AppOptions are autocli options for an app. These options can be built via depinject based on an app config. Ex: From 3ccdc64df48c04276ac9ac085ac811abb57a6a73 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 22 Mar 2023 16:42:19 -0300 Subject: [PATCH 04/12] revert some unrelated changes --- runtime/module.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/module.go b/runtime/module.go index 9f96f662734c..30556ba050a6 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -17,14 +17,13 @@ import ( storetypes "cosmossdk.io/store/types" - "github.com/cosmos/gogoproto/proto" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/cosmos/gogoproto/proto" ) type appModule struct { From 51d3ba24f040464f89a3dc9e23cc9dc96c5e8287 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 22 Mar 2023 16:52:14 -0300 Subject: [PATCH 05/12] fix legacy app --- simapp/app.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 1f6447054ce4..61ff5568319d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -285,7 +285,7 @@ func NewSimApp( app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) // set the BaseApp's parameter store - app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String()) bApp.SetParamStore(&app.ConsensusParamsKeeper) // add keepers @@ -433,7 +433,8 @@ func NewSimApp( // NOTE: The genutils module must occur after staking so that pools are // properly initialized with tokens from genesis accounts. // NOTE: The genutils module must also occur after auth so that it can access the params from auth. - genesisModuleOrder := []string{authtypes.ModuleName, banktypes.ModuleName, + genesisModuleOrder := []string{ + authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, From b0a47717335574a3fa1b01e3520f9dac3f355e86 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 22 Mar 2023 17:23:39 -0300 Subject: [PATCH 06/12] do not panic! --- baseapp/abci.go | 5 ++++- baseapp/baseapp.go | 6 +++--- baseapp/params.go | 4 ++-- x/consensus/exported/exported.go | 4 ++-- x/consensus/keeper/keeper.go | 20 +++++--------------- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index dc89c364c12d..09c22b6e3a3e 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -66,7 +66,10 @@ 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 { - app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams) + err := app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams) + if err != nil { + panic(err) + } } if app.initChainer == nil { diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 5cff5a206b2c..1b3f627034a9 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -448,16 +448,16 @@ 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) { +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 + return nil } - app.paramStore.Set(ctx, cp) + 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. } diff --git a/baseapp/params.go b/baseapp/params.go index 1ac07da3668e..77d3df8bcf57 100644 --- a/baseapp/params.go +++ b/baseapp/params.go @@ -10,6 +10,6 @@ import ( // fulfill. type ParamStore interface { Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) - Has(ctx sdk.Context) bool - Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) + Has(ctx sdk.Context) (bool, error) + Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) error } diff --git a/x/consensus/exported/exported.go b/x/consensus/exported/exported.go index 1e0a138e95a7..38e525ee2618 100644 --- a/x/consensus/exported/exported.go +++ b/x/consensus/exported/exported.go @@ -19,7 +19,7 @@ type ( // ParamStore which allows setting its appVersion field. ConsensusParamSetter interface { Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) - Has(ctx sdk.Context) bool - Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) + Has(ctx sdk.Context) (bool, error) + Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) error } ) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 375e4532296d..76b12a94e69d 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -36,12 +36,12 @@ func (k *Keeper) GetAuthority() string { func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { store := k.storeSvc.OpenKVStore(ctx) - cp := &cmtproto.ConsensusParams{} bz, err := store.Get(types.ParamStoreKeyConsensusParams) if err != nil { return nil, err } + cp := &cmtproto.ConsensusParams{} if err := k.cdc.Unmarshal(bz, cp); err != nil { return nil, err } @@ -49,23 +49,13 @@ func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { return cp, nil } -func (k *Keeper) Has(ctx sdk.Context) bool { +func (k *Keeper) Has(ctx sdk.Context) (bool, error) { store := k.storeSvc.OpenKVStore(ctx) - - has, err := store.Has(types.ParamStoreKeyConsensusParams) - // should never panic given that key is hardcoded - if err != nil { - panic(err) - } - - return has + return store.Has(types.ParamStoreKeyConsensusParams) } // Set sets the consensus parameters -func (k *Keeper) Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) { +func (k *Keeper) Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) error { store := k.storeSvc.OpenKVStore(ctx) - err := store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp)) - if err != nil { - panic(err) - } + return store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp)) } From 3461218d54e6ccc6c45da5c64a4ed0a928202239 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 22 Mar 2023 17:34:38 -0300 Subject: [PATCH 07/12] fix test --- baseapp/utils_test.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 7184506895f8..f9cec1f940f7 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -239,28 +239,25 @@ type paramStore struct { db *dbm.MemDB } -func (ps *paramStore) Set(_ sdk.Context, value *cmtproto.ConsensusParams) { +var _ baseapp.ParamStore = (*paramStore)(nil) + +func (ps *paramStore) Set(_ sdk.Context, value *cmtproto.ConsensusParams) error { bz, err := json.Marshal(value) if err != nil { - panic(err) + return err } - ps.db.Set(ParamStoreKey, bz) + return ps.db.Set(ParamStoreKey, bz) } -func (ps *paramStore) Has(_ sdk.Context) bool { - ok, err := ps.db.Has(ParamStoreKey) - if err != nil { - panic(err) - } - - return ok +func (ps *paramStore) Has(_ sdk.Context) (bool, error) { + return ps.db.Has(ParamStoreKey) } func (ps paramStore) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { bz, err := ps.db.Get(ParamStoreKey) if err != nil { - panic(err) + return nil, err } if len(bz) == 0 { @@ -269,7 +266,7 @@ func (ps paramStore) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { var params cmtproto.ConsensusParams if err := json.Unmarshal(bz, ¶ms); err != nil { - panic(err) + return nil, err } return ¶ms, nil From 1af56ea7127ded79ff4e4b53b149a494ae5723d6 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 23 Mar 2023 09:00:08 -0300 Subject: [PATCH 08/12] storeSvc -> storeService --- x/consensus/keeper/keeper.go | 18 +++++++++--------- x/consensus/keeper/keeper_test.go | 4 ++-- x/consensus/module.go | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 76b12a94e69d..46c00f2d4134 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -14,17 +14,17 @@ import ( var _ exported.ConsensusParamSetter = (*Keeper)(nil) type Keeper struct { - storeSvc storetypes.KVStoreService - cdc codec.BinaryCodec + storeService storetypes.KVStoreService + cdc codec.BinaryCodec authority string } -func NewKeeper(cdc codec.BinaryCodec, storeSvc storetypes.KVStoreService, authority string) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string) Keeper { return Keeper{ - storeSvc: storeSvc, - cdc: cdc, - authority: authority, + storeService: storeService, + cdc: cdc, + authority: authority, } } @@ -34,7 +34,7 @@ func (k *Keeper) GetAuthority() string { // Get gets the consensus parameters func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { - store := k.storeSvc.OpenKVStore(ctx) + store := k.storeService.OpenKVStore(ctx) bz, err := store.Get(types.ParamStoreKeyConsensusParams) if err != nil { @@ -50,12 +50,12 @@ func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { } func (k *Keeper) Has(ctx sdk.Context) (bool, error) { - store := k.storeSvc.OpenKVStore(ctx) + store := k.storeService.OpenKVStore(ctx) return store.Has(types.ParamStoreKeyConsensusParams) } // Set sets the consensus parameters func (k *Keeper) Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) error { - store := k.storeSvc.OpenKVStore(ctx) + store := k.storeService.OpenKVStore(ctx) return store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp)) } diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index c987222634d3..2ac0108c3581 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -33,9 +33,9 @@ func (s *KeeperTestSuite) SetupTest() { testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{}) encCfg := moduletestutil.MakeTestEncodingConfig() - storeSvc := runtime.NewKVStoreService(key) + storeService := runtime.NewKVStoreService(key) - keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, storeSvc, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, storeService, authtypes.NewModuleAddress(govtypes.ModuleName).String()) s.ctx = ctx s.consensusParamsKeeper = &keeper diff --git a/x/consensus/module.go b/x/consensus/module.go index d6af0aa6edf7..a640d2ea44d6 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -139,9 +139,9 @@ func init() { type ConsensusInputs struct { depinject.In - Config *modulev1.Module - Cdc codec.Codec - StoreSvc storetypes.KVStoreService + Config *modulev1.Module + Cdc codec.Codec + storeService storetypes.KVStoreService } //nolint:revive @@ -160,7 +160,7 @@ func ProvideModule(in ConsensusInputs) ConsensusOutputs { authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) } - k := keeper.NewKeeper(in.Cdc, in.StoreSvc, authority.String()) + k := keeper.NewKeeper(in.Cdc, in.storeService, authority.String()) m := NewAppModule(in.Cdc, k) baseappOpt := func(app *baseapp.BaseApp) { app.SetParamStore(&k) From 8a8888ed94fca39f893de3d405d67724760e33d4 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 23 Mar 2023 09:02:21 -0300 Subject: [PATCH 09/12] replace sdk.Context with context.Context --- baseapp/params.go | 10 +++++----- x/consensus/exported/exported.go | 8 +++++--- x/consensus/keeper/keeper.go | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/baseapp/params.go b/baseapp/params.go index 77d3df8bcf57..35628f5870dc 100644 --- a/baseapp/params.go +++ b/baseapp/params.go @@ -1,15 +1,15 @@ package baseapp import ( - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + "context" - sdk "github.com/cosmos/cosmos-sdk/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" ) // ParamStore defines the interface the parameter store used by the BaseApp must // fulfill. type ParamStore interface { - Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) - Has(ctx sdk.Context) (bool, error) - Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) error + Get(ctx context.Context) (*cmtproto.ConsensusParams, error) + Has(ctx context.Context) (bool, error) + Set(ctx context.Context, cp *cmtproto.ConsensusParams) error } diff --git a/x/consensus/exported/exported.go b/x/consensus/exported/exported.go index 38e525ee2618..7baa5b1a6d5a 100644 --- a/x/consensus/exported/exported.go +++ b/x/consensus/exported/exported.go @@ -1,6 +1,8 @@ package exported import ( + "context" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,8 +20,8 @@ type ( // ConsensusParamSetter defines the interface fulfilled by BaseApp's // ParamStore which allows setting its appVersion field. ConsensusParamSetter interface { - Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) - Has(ctx sdk.Context) (bool, error) - Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) error + Get(ctx context.Context) (*cmtproto.ConsensusParams, error) + Has(ctx context.Context) (bool, error) + Set(ctx context.Context, cp *cmtproto.ConsensusParams) error } ) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 46c00f2d4134..d2e9efef6fd3 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -1,12 +1,13 @@ package keeper import ( + "context" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" storetypes "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/consensus/exported" "github.com/cosmos/cosmos-sdk/x/consensus/types" ) @@ -33,7 +34,7 @@ func (k *Keeper) GetAuthority() string { } // Get gets the consensus parameters -func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { +func (k *Keeper) Get(ctx context.Context) (*cmtproto.ConsensusParams, error) { store := k.storeService.OpenKVStore(ctx) bz, err := store.Get(types.ParamStoreKeyConsensusParams) @@ -49,13 +50,13 @@ func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { return cp, nil } -func (k *Keeper) Has(ctx sdk.Context) (bool, error) { +func (k *Keeper) Has(ctx context.Context) (bool, error) { store := k.storeService.OpenKVStore(ctx) return store.Has(types.ParamStoreKeyConsensusParams) } // Set sets the consensus parameters -func (k *Keeper) Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) error { +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)) } From 54fb52297e2561a8095482149f048f781b963600 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 23 Mar 2023 09:05:22 -0300 Subject: [PATCH 10/12] replace sdk.Context with context.Context --- baseapp/utils_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index f9cec1f940f7..385184af5e77 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(_ sdk.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,11 +250,11 @@ func (ps *paramStore) Set(_ sdk.Context, value *cmtproto.ConsensusParams) error return ps.db.Set(ParamStoreKey, bz) } -func (ps *paramStore) Has(_ sdk.Context) (bool, error) { +func (ps *paramStore) Has(_ context.Context) (bool, error) { return ps.db.Has(ParamStoreKey) } -func (ps paramStore) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) { +func (ps paramStore) Get(ctx context.Context) (*cmtproto.ConsensusParams, error) { bz, err := ps.db.Get(ParamStoreKey) if err != nil { return nil, err From 34b92e14d1d86f5e7db627ee7c4495c0c420806e Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 23 Mar 2023 11:12:19 -0300 Subject: [PATCH 11/12] fix --- x/consensus/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/consensus/module.go b/x/consensus/module.go index a640d2ea44d6..5cf7693c346c 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -141,7 +141,7 @@ type ConsensusInputs struct { Config *modulev1.Module Cdc codec.Codec - storeService storetypes.KVStoreService + StoreService storetypes.KVStoreService } //nolint:revive @@ -160,7 +160,7 @@ func ProvideModule(in ConsensusInputs) ConsensusOutputs { authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) } - k := keeper.NewKeeper(in.Cdc, in.storeService, authority.String()) + k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String()) m := NewAppModule(in.Cdc, k) baseappOpt := func(app *baseapp.BaseApp) { app.SetParamStore(&k) From 7132bb6694095f06ff0a616d57dc76c481fbe14c Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 23 Mar 2023 11:50:16 -0300 Subject: [PATCH 12/12] upgrading and cl --- CHANGELOG.md | 1 + UPGRADING.md | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c439ec69a2df..a6fec52e63c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/consensus) [#15517](https://github.com/cosmos/cosmos-sdk/pull/15517) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey`. * (x/bank) [#15477](https://github.com/cosmos/cosmos-sdk/pull/15477) `banktypes.NewMsgMultiSend` and `keeper.InputOutputCoins` only accept one input. * (mempool) [#15328](https://github.com/cosmos/cosmos-sdk/pull/15328) The `PriorityNonceMempool` is now generic over type `C comparable` and takes a single `PriorityNonceMempoolConfig[C]` argument. See `DefaultPriorityNonceMempoolConfig` for how to construct the configuration and a `TxPriority` type. * (server) [#15358](https://github.com/cosmos/cosmos-sdk/pull/15358) Remove `server.ErrorCode` that was not used anywhere. diff --git a/UPGRADING.md b/UPGRADING.md index aa57db85f8e3..19da06f04ccd 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -79,6 +79,15 @@ All the store imports are now renamed to use `cosmossdk.io/store` instead of `gi Capability was moved to [IBC-GO](https://github.com/cosmos/ibc-go). IBC V8 will contain the necessary changes to incorporate the new module location +#### `x/consensus` + +The `NewKeeper` method now takes a `KVStoreService` instead of a `StoreKey`. When not using depinject, the `runtime.NewKVStoreService` method can be used to create a `KVStoreService` from a `StoreKey`. + +```diff +- app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) ++ app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String()) +``` + #### `x/gov` ##### Expedited Proposals