feat(x/consensus): Add env bundler to x/consensus module (#19488)

This commit is contained in:
Likhita Polavarapu 2024-02-20 15:38:56 +05:30 committed by GitHub
parent 8acade49db
commit b0db3ea299
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 21 deletions

View File

@ -96,6 +96,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
### API Breaking Changes
* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services.
* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does.
* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration.
* (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration.

View File

@ -280,7 +280,7 @@ func NewSimApp(
}
// set the BaseApp's parameter store
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), runtime.EventService{})
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger), authtypes.NewModuleAddress(govtypes.ModuleName).String())
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)
addressCodec := authcodec.NewBech32Codec(sdk.Bech32MainPrefix)

View File

@ -82,7 +82,7 @@ func NewIntegrationApp(
if keys[consensusparamtypes.StoreKey] != nil {
// set baseApp param store
consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress("gov").String(), runtime.EventService{})
consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger()), authtypes.NewModuleAddress("gov").String())
bApp.SetParamStore(consensusParamsKeeper.ParamsStore)
if err := bApp.LoadLatestVersion(); err != nil {

View File

@ -3,8 +3,6 @@ package consensus
import (
modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
authtypes "cosmossdk.io/x/auth/types"
@ -30,10 +28,9 @@ func init() {
type ModuleInputs struct {
depinject.In
Config *modulev1.Module
Cdc codec.Codec
StoreService storetypes.KVStoreService
EventManager event.Service
Config *modulev1.Module
Cdc codec.Codec
Environment appmodule.Environment
}
type ModuleOutputs struct {
@ -51,7 +48,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String(), in.EventManager)
k := keeper.NewKeeper(in.Cdc, in.Environment, authority.String())
m := NewAppModule(in.Cdc, k)
baseappOpt := func(app *baseapp.BaseApp) {
app.SetParamStore(k.ParamsStore)

View File

@ -10,8 +10,8 @@ import (
"google.golang.org/grpc/status"
"cosmossdk.io/collections"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
storetypes "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/consensus/exported"
@ -21,8 +21,7 @@ import (
var StoreKey = "Consensus"
type Keeper struct {
storeService storetypes.KVStoreService
event event.Service
environment appmodule.Environment
authority string
ParamsStore collections.Item[cmtproto.ConsensusParams]
@ -30,13 +29,12 @@ type Keeper struct {
var _ exported.ConsensusParamSetter = Keeper{}.ParamsStore
func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string, em event.Service) Keeper {
sb := collections.NewSchemaBuilder(storeService)
func NewKeeper(cdc codec.BinaryCodec, env appmodule.Environment, authority string) Keeper {
sb := collections.NewSchemaBuilder(env.KVStoreService)
return Keeper{
storeService: storeService,
authority: authority,
event: em,
ParamsStore: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
environment: env,
authority: authority,
ParamsStore: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
}
}
@ -79,7 +77,7 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*
return nil, err
}
if err := k.event.EventManager(ctx).EmitKV(
if err := k.environment.EventService.EventManager(ctx).EmitKV(
"update_consensus_params",
event.NewAttribute("authority", msg.Authority),
event.NewAttribute("parameters", consensusParams.String())); err != nil {

View File

@ -7,6 +7,7 @@ import (
cmttypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/suite"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
authtypes "cosmossdk.io/x/auth/types"
@ -32,9 +33,9 @@ func (s *KeeperTestSuite) SetupTest() {
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
ctx := testCtx.Ctx
encCfg := moduletestutil.MakeTestEncodingConfig()
storeService := runtime.NewKVStoreService(key)
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())
keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, storeService, authtypes.NewModuleAddress("gov").String(), runtime.EventService{})
keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, env, authtypes.NewModuleAddress("gov").String())
s.ctx = ctx
s.consensusParamsKeeper = &keeper