From cdc329189b0fa11c13b36faf27d7f5bf96a19ff4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Mar 2024 06:43:24 +0100 Subject: [PATCH] refactor(types): align genesis api (#19735) --- CHANGELOG.md | 10 +- UPGRADING.md | 11 ++- core/appmodule/environment.go | 2 +- core/appmodule/migrations.go | 3 + runtime/app.go | 4 +- simapp/app.go | 15 +-- simapp/app_test.go | 2 +- simapp/sim_test.go | 2 +- testutil/mock/types_mock_appmodule.go | 27 +++--- testutil/mock/types_module_module.go | 58 +++--------- types/module/core_module.go | 34 ++++--- types/module/mock_appmodule_test.go | 6 +- types/module/module.go | 131 ++++++++++++++++++-------- types/module/module_test.go | 30 +++--- x/accounts/module.go | 17 ++-- x/auth/module.go | 3 +- x/authz/module/module.go | 21 ++--- x/bank/module.go | 21 ++--- x/circuit/module.go | 13 ++- x/consensus/module.go | 10 +- x/counter/module.go | 6 +- x/crisis/module.go | 17 ++-- x/distribution/module.go | 23 +++-- x/evidence/module.go | 17 ++-- x/feegrant/module/module.go | 21 ++--- x/genutil/module.go | 34 +++++-- x/gov/module.go | 23 +++-- x/group/module/module.go | 23 +++-- x/mint/module.go | 21 ++--- x/nft/module/module.go | 13 ++- x/params/module.go | 14 +-- x/protocolpool/module.go | 20 ++-- x/slashing/module.go | 23 +++-- x/staking/CHANGELOG.md | 3 +- x/staking/module.go | 84 ++++++++++++----- x/upgrade/module.go | 21 ++--- 36 files changed, 420 insertions(+), 363 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a073a86882cd..4886f460ef5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,9 +59,10 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (types) [#19672](https://github.com/cosmos/cosmos-sdk/pull/19672) `PreBlock` now returns only an error for consistency with server/v2. The SDK has upgraded x/upgrade accordingly. `ResponsePreBlock` hence has been removed. * (server) [#19455](https://github.com/cosmos/cosmos-sdk/pull/19455) Allow calling back into the application struct in PostSetup. -* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) The notion of basic manager does not exist anymore. +* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) The notion of basic manager does not exist anymore (and all related helpers). * The module manager now can do everything that the basic manager was doing. - * `AppModuleBasic` has been deprecated for extension interfaces. Modules can now implement `HasRegisterInterfaces`, `HasGRPCGateway` and `HasAminoCodec` when relevant. + * `AppModuleBasic` has been deprecated for extension interfaces. + * Modules can now implement `appmodule.HasRegisterInterfaces`, `modue.HasGRPCGateway` and `module.HasAminoCodec` when relevant. * SDK modules now directly implement those extension interfaces on `AppModule` instead of `AppModuleBasic`. * (client/keys) [#18950](https://github.com/cosmos/cosmos-sdk/pull/18950) Improve ` keys add`, ` keys import` and ` keys rename` by checking name validation. * (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. @@ -82,6 +83,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle. * (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding * (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. +* (x/genutil) [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) Update genesis api to match new `appmodule.HasGenesis` interface. ### Bug Fixes @@ -144,7 +146,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652) * Moved`types/module.HasRegisterInterfaces` to `cosmossdk.io/core`. * Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.LegacyRegistry` interface. -* (types) [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) All genesis interfaces now don't take `codec.JsonCodec`. Every module has the codec already, passing it created an unneeded dependency. Additionally, to reflect this change, the module manager does not take a codec either. +* (types) [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) and [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) All genesis interfaces now don't take `codec.JsonCodec`. + * Every module has the codec already, passing it created an unneeded dependency. + * Additionally, to reflect this change, the module manager does not take a codec either. ### Client Breaking Changes diff --git a/UPGRADING.md b/UPGRADING.md index 1519b8f80efc..3a21dee49158 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -52,6 +52,8 @@ For non depinject users, simply call `RegisterLegacyAminoCodec` and `RegisterInt +app.ModuleManager.RegisterInterfaces(interfaceRegistry) ``` +Additionally, thanks to the genesis simplification, as explained in [the genesis interface update](#genesis-interface), the module manager `InitGenesis` and `ExportGenesis` methods do not require the codec anymore. + ##### AnteHandlers The `GasConsumptionDecorator` and `IncreaseSequenceDecorator` have been merged with the SigVerificationDecorator, so you'll @@ -182,15 +184,16 @@ Previous module migrations have been removed. It is required to migrate to v0.50 ##### Genesis Interface -All genesis interfaces have been migrated to take context.Context instead of sdk.Context. Secondly, the codec is no longer passed in by the framework. The codec is now passed in by the module. +All genesis interfaces have been migrated to take `context.Context` instead of `sdk.Context`. +Secondly, the codec is no longer passed in by the framework. The codec is now passed in by the module. +Lastly, all InitGenesis and ExportGenesis functions now return an error. ```go -// InitGenesis performs genesis initialization for the authz module. +// InitGenesis performs genesis initialization for the module. func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { } -// ExportGenesis returns the exported genesis state as raw bytes for the authz -// module. +// ExportGenesis returns the exported genesis state as raw bytes for the module. func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { } ``` diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go index 93778e9e9bbe..d65c32a5f83f 100644 --- a/core/appmodule/environment.go +++ b/core/appmodule/environment.go @@ -1,7 +1,7 @@ package appmodule import ( - appmodule "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/appmodule/v2" ) // Environment is used to get all services to their respective module diff --git a/core/appmodule/migrations.go b/core/appmodule/migrations.go index e5fe6fbcfaf1..8c4ec594f6de 100644 --- a/core/appmodule/migrations.go +++ b/core/appmodule/migrations.go @@ -15,3 +15,6 @@ type MigrationRegistrar = appmodule.MigrationRegistrar // MigrationHandler is the migration function that each module registers. type MigrationHandler = appmodule.MigrationHandler + +// VersionMap is a map of moduleName -> version +type VersionMap = appmodule.VersionMap diff --git a/runtime/app.go b/runtime/app.go index 6fdfe08ca1f0..ced302636a9e 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -187,9 +187,9 @@ func (a *App) PrepareCheckStater(ctx sdk.Context) { func (a *App) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { var genesisState map[string]json.RawMessage if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil { - panic(err) + return nil, err } - return a.ModuleManager.InitGenesis(ctx, a.cdc, genesisState) + return a.ModuleManager.InitGenesis(ctx, genesisState) } // RegisterAPIRoutes registers all application module routes with the provided diff --git a/simapp/app.go b/simapp/app.go index 3304c335b4ec..6c265cc1148f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -17,7 +17,6 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/client/v2/autocli" - "cosmossdk.io/core/appmodule" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/accounts" @@ -644,7 +643,7 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*ab if err != nil { return nil, err } - return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState) + return app.ModuleManager.InitGenesis(ctx, genesisState) } // LoadHeight loads a particular height @@ -680,18 +679,8 @@ func (app *SimApp) TxConfig() client.TxConfig { // AutoCliOpts returns the autocli options for the app. func (app *SimApp) AutoCliOpts() autocli.AppOptions { - modules := make(map[string]appmodule.AppModule, 0) - for _, m := range app.ModuleManager.Modules { - if moduleWithName, ok := m.(module.HasName); ok { - moduleName := moduleWithName.Name() - if appModule, ok := moduleWithName.(appmodule.AppModule); ok { - modules[moduleName] = appModule - } - } - } - return autocli.AppOptions{ - Modules: modules, + Modules: app.ModuleManager.Modules, ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules), } } diff --git a/simapp/app_test.go b/simapp/app_test.go index 8c1c5a8d8ef3..406017291cd3 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -278,7 +278,7 @@ func TestUpgradeStateOnGenesis(t *testing.T) { vm, err := app.UpgradeKeeper.GetModuleVersionMap(ctx) require.NoError(t, err) for v, i := range app.ModuleManager.Modules { - if i, ok := i.(module.HasConsensusVersion); ok { + if i, ok := i.(appmodule.HasConsensusVersion); ok { require.Equal(t, vm[v], i.ConsensusVersion()) } } diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 8001d48d0749..960490f168bd 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -175,7 +175,7 @@ func TestAppImportExport(t *testing.T) { ctxA := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) ctxB := newApp.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) - _, err = newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState) + _, err = newApp.ModuleManager.InitGenesis(ctxB, genesisState) if err != nil { if strings.Contains(err.Error(), "validator set is empty after InitGenesis") { logger.Info("Skipping simulation as all validators have been unbonded") diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index 6118f774fd9f..0d668299abfa 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -11,8 +11,7 @@ import ( appmodule "cosmossdk.io/core/appmodule" registry "cosmossdk.io/core/registry" - types "github.com/cometbft/cometbft/abci/types" - types0 "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" module "github.com/cosmos/cosmos-sdk/types/module" gomock "github.com/golang/mock/gomock" ) @@ -69,10 +68,10 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) DefaultGenesis() *gomock.C } // EndBlock mocks base method. -func (m *MockAppModuleWithAllExtensions) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) { +func (m *MockAppModuleWithAllExtensions) EndBlock(arg0 context.Context) ([]module.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EndBlock", arg0) - ret0, _ := ret[0].([]types.ValidatorUpdate) + ret0, _ := ret[0].([]module.ValidatorUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -163,7 +162,7 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterInterfaces(arg0 in } // RegisterInvariants mocks base method. -func (m *MockAppModuleWithAllExtensions) RegisterInvariants(arg0 types0.InvariantRegistry) { +func (m *MockAppModuleWithAllExtensions) RegisterInvariants(arg0 types.InvariantRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInvariants", arg0) } @@ -252,10 +251,10 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) DefaultGenesis() *gomo } // EndBlock mocks base method. -func (m *MockAppModuleWithAllExtensionsABCI) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) { +func (m *MockAppModuleWithAllExtensionsABCI) EndBlock(arg0 context.Context) ([]module.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EndBlock", arg0) - ret0, _ := ret[0].([]types.ValidatorUpdate) + ret0, _ := ret[0].([]module.ValidatorUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -267,11 +266,12 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) EndBlock(arg0 interfac } // ExportGenesis mocks base method. -func (m *MockAppModuleWithAllExtensionsABCI) ExportGenesis(arg0 context.Context) json.RawMessage { +func (m *MockAppModuleWithAllExtensionsABCI) ExportGenesis(arg0 context.Context) (json.RawMessage, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0) ret0, _ := ret[0].(json.RawMessage) - return ret0 + ret1, _ := ret[1].(error) + return ret0, ret1 } // ExportGenesis indicates an expected call of ExportGenesis. @@ -281,11 +281,12 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) ExportGenesis(arg0 int } // InitGenesis mocks base method. -func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(arg0 context.Context, arg1 json.RawMessage) []types.ValidatorUpdate { +func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(arg0 context.Context, arg1 json.RawMessage) ([]module.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) - ret0, _ := ret[0].([]types.ValidatorUpdate) - return ret0 + ret0, _ := ret[0].([]module.ValidatorUpdate) + ret1, _ := ret[1].(error) + return ret0, ret1 } // InitGenesis indicates an expected call of InitGenesis. @@ -345,7 +346,7 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) RegisterInterfaces(arg } // RegisterInvariants mocks base method. -func (m *MockAppModuleWithAllExtensionsABCI) RegisterInvariants(arg0 types0.InvariantRegistry) { +func (m *MockAppModuleWithAllExtensionsABCI) RegisterInvariants(arg0 types.InvariantRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInvariants", arg0) } diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index b3e6283f509b..01a7e3219496 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -10,10 +10,9 @@ import ( reflect "reflect" registry "cosmossdk.io/core/registry" - types "github.com/cometbft/cometbft/abci/types" client "github.com/cosmos/cosmos-sdk/client" codec "github.com/cosmos/cosmos-sdk/codec" - types0 "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" module "github.com/cosmos/cosmos-sdk/types/module" gomock "github.com/golang/mock/gomock" runtime "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -375,11 +374,12 @@ func (mr *MockHasABCIGenesisMockRecorder) DefaultGenesis() *gomock.Call { } // ExportGenesis mocks base method. -func (m *MockHasABCIGenesis) ExportGenesis(arg0 context.Context) json.RawMessage { +func (m *MockHasABCIGenesis) ExportGenesis(arg0 context.Context) (json.RawMessage, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0) ret0, _ := ret[0].(json.RawMessage) - return ret0 + ret1, _ := ret[1].(error) + return ret0, ret1 } // ExportGenesis indicates an expected call of ExportGenesis. @@ -389,11 +389,12 @@ func (mr *MockHasABCIGenesisMockRecorder) ExportGenesis(arg0 interface{}) *gomoc } // InitGenesis mocks base method. -func (m *MockHasABCIGenesis) InitGenesis(arg0 context.Context, arg1 json.RawMessage) []types.ValidatorUpdate { +func (m *MockHasABCIGenesis) InitGenesis(arg0 context.Context, arg1 json.RawMessage) ([]module.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) - ret0, _ := ret[0].([]types.ValidatorUpdate) - return ret0 + ret0, _ := ret[0].([]module.ValidatorUpdate) + ret1, _ := ret[1].(error) + return ret0, ret1 } // InitGenesis indicates an expected call of InitGenesis. @@ -454,7 +455,7 @@ func (m *MockHasInvariants) EXPECT() *MockHasInvariantsMockRecorder { } // RegisterInvariants mocks base method. -func (m *MockHasInvariants) RegisterInvariants(arg0 types0.InvariantRegistry) { +func (m *MockHasInvariants) RegisterInvariants(arg0 types.InvariantRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInvariants", arg0) } @@ -500,43 +501,6 @@ func (mr *MockHasServicesMockRecorder) RegisterServices(arg0 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockHasServices)(nil).RegisterServices), arg0) } -// MockHasConsensusVersion is a mock of HasConsensusVersion interface. -type MockHasConsensusVersion struct { - ctrl *gomock.Controller - recorder *MockHasConsensusVersionMockRecorder -} - -// MockHasConsensusVersionMockRecorder is the mock recorder for MockHasConsensusVersion. -type MockHasConsensusVersionMockRecorder struct { - mock *MockHasConsensusVersion -} - -// NewMockHasConsensusVersion creates a new mock instance. -func NewMockHasConsensusVersion(ctrl *gomock.Controller) *MockHasConsensusVersion { - mock := &MockHasConsensusVersion{ctrl: ctrl} - mock.recorder = &MockHasConsensusVersionMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHasConsensusVersion) EXPECT() *MockHasConsensusVersionMockRecorder { - return m.recorder -} - -// ConsensusVersion mocks base method. -func (m *MockHasConsensusVersion) ConsensusVersion() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConsensusVersion") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// ConsensusVersion indicates an expected call of ConsensusVersion. -func (mr *MockHasConsensusVersionMockRecorder) ConsensusVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockHasConsensusVersion)(nil).ConsensusVersion)) -} - // MockHasABCIEndBlock is a mock of HasABCIEndBlock interface. type MockHasABCIEndBlock struct { ctrl *gomock.Controller @@ -561,10 +525,10 @@ func (m *MockHasABCIEndBlock) EXPECT() *MockHasABCIEndBlockMockRecorder { } // EndBlock mocks base method. -func (m *MockHasABCIEndBlock) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) { +func (m *MockHasABCIEndBlock) EndBlock(arg0 context.Context) ([]module.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EndBlock", arg0) - ret0, _ := ret[0].([]types.ValidatorUpdate) + ret0, _ := ret[0].([]module.ValidatorUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/types/module/core_module.go b/types/module/core_module.go index 7b59b430c019..398800f0fcb0 100644 --- a/types/module/core_module.go +++ b/types/module/core_module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" - abci "github.com/cometbft/cometbft/abci/types" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -95,21 +94,21 @@ func (c coreAppModuleAdaptor) ValidateGenesis(bz json.RawMessage) error { } // ExportGenesis implements HasGenesis -func (c coreAppModuleAdaptor) ExportGenesis(ctx context.Context) json.RawMessage { +func (c coreAppModuleAdaptor) ExportGenesis(ctx context.Context) (json.RawMessage, error) { if module, ok := c.module.(appmodule.HasGenesisAuto); ok { ctx := sdk.UnwrapSDKContext(ctx).WithGasMeter(storetypes.NewInfiniteGasMeter()) // avoid race conditions target := genesis.RawJSONTarget{} err := module.ExportGenesis(ctx, target.Target()) if err != nil { - panic(err) + return nil, err } rawJSON, err := target.JSON() if err != nil { - panic(err) + return nil, err } - return rawJSON + return rawJSON, nil } if mod, ok := c.module.(HasABCIGenesis); ok { @@ -119,26 +118,26 @@ func (c coreAppModuleAdaptor) ExportGenesis(ctx context.Context) json.RawMessage if mod, ok := c.module.(HasGenesis); ok { eg, err := mod.ExportGenesis(ctx) if err != nil { - panic(err) + return nil, err } - return eg + + return eg, nil } - return nil + return nil, nil } // InitGenesis implements HasGenesis -func (c coreAppModuleAdaptor) InitGenesis(ctx context.Context, bz json.RawMessage) []abci.ValidatorUpdate { +func (c coreAppModuleAdaptor) InitGenesis(ctx context.Context, bz json.RawMessage) ([]ValidatorUpdate, error) { if module, ok := c.module.(appmodule.HasGenesisAuto); ok { // core API genesis source, err := genesis.SourceFromRawJSON(bz) if err != nil { - panic(err) + return nil, err } - err = module.InitGenesis(ctx, source) - if err != nil { - panic(err) + if err = module.InitGenesis(ctx, source); err != nil { + return nil, err } } @@ -147,13 +146,12 @@ func (c coreAppModuleAdaptor) InitGenesis(ctx context.Context, bz json.RawMessag } if mod, ok := c.module.(HasGenesis); ok { - err := mod.InitGenesis(ctx, bz) - if err != nil { - panic(err) + if err := mod.InitGenesis(ctx, bz); err != nil { + return nil, err } - } - return nil + + return nil, nil } // Name implements HasName diff --git a/types/module/mock_appmodule_test.go b/types/module/mock_appmodule_test.go index 6d470b7d64a6..1be48c882264 100644 --- a/types/module/mock_appmodule_test.go +++ b/types/module/mock_appmodule_test.go @@ -14,9 +14,9 @@ import ( type AppModuleWithAllExtensions interface { module.AppModule module.HasServices - appmodulev2.HasGenesis module.HasInvariants - module.HasConsensusVersion + appmodulev2.HasConsensusVersion + appmodulev2.HasGenesis module.HasABCIEndBlock module.HasName } @@ -27,7 +27,7 @@ type AppModuleWithAllExtensionsABCI interface { module.HasServices module.HasABCIGenesis module.HasInvariants - module.HasConsensusVersion + appmodulev2.HasConsensusVersion module.HasABCIEndBlock module.HasName } diff --git a/types/module/module.go b/types/module/module.go index 6dd626f7cd20..fba59b89ea05 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -27,6 +27,7 @@ import ( "sort" abci "github.com/cometbft/cometbft/abci/types" + cmtcryptoproto "github.com/cometbft/cometbft/proto/tendermint/crypto" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "golang.org/x/exp/maps" @@ -46,11 +47,11 @@ import ( // Deprecated: use the embed extension interfaces instead, when needed. type AppModuleBasic interface { - appmodulev2.HasRegisterInterfaces - HasName HasGRPCGateway HasAminoCodec + + appmodulev2.HasRegisterInterfaces } // AppModule is the form for an application module. Most of @@ -84,22 +85,20 @@ type HasAminoCodec interface { RegisterLegacyAminoCodec(*codec.LegacyAmino) } -// HasRegisterInterfaces is the interface for modules to register their msg types. -type HasRegisterInterfaces appmodulev2.HasRegisterInterfaces - // HasGRPCGateway is the interface for modules to register their gRPC gateway routes. type HasGRPCGateway interface { RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) } // HasGenesis is the extension interface for stateful genesis methods. +// Prefer directly importing appmodulev2 or appmodule instead of using this alias. type HasGenesis = appmodulev2.HasGenesis // HasABCIGenesis is the extension interface for stateful genesis methods which returns validator updates. type HasABCIGenesis interface { HasGenesisBasics - InitGenesis(context.Context, json.RawMessage) []abci.ValidatorUpdate - ExportGenesis(context.Context) json.RawMessage + InitGenesis(context.Context, json.RawMessage) ([]ValidatorUpdate, error) + ExportGenesis(context.Context) (json.RawMessage, error) } // HasInvariants is the interface for registering invariants. @@ -114,19 +113,19 @@ type HasServices interface { RegisterServices(Configurator) } -// HasConsensusVersion is the interface for declaring a module consensus version. -type HasConsensusVersion interface { - // ConsensusVersion is a sequence number for state-breaking change of the - // module. It should be incremented on each consensus-breaking change - // introduced by the module. To avoid wrong/empty versions, the initial version - // should be set to 1. - ConsensusVersion() uint64 -} +// MigrationHandler is the migration function that each module registers. +type MigrationHandler func(sdk.Context) error + +// VersionMap is a map of moduleName -> version +type VersionMap appmodule.VersionMap + +// ValidatorUpdate is the type for validator updates. +type ValidatorUpdate = appmodulev2.ValidatorUpdate // HasABCIEndBlock is the interface for modules that need to run code at the end of the block. type HasABCIEndBlock interface { AppModule - EndBlock(context.Context) ([]abci.ValidatorUpdate, error) + EndBlock(context.Context) ([]ValidatorUpdate, error) } // Manager defines a module manager that provides the high level utility for managing and executing @@ -324,11 +323,13 @@ func (m *Manager) RegisterInterfaces(registry registry.LegacyRegistry) { // DefaultGenesis provides default genesis information for all modules func (m *Manager) DefaultGenesis() map[string]json.RawMessage { genesisData := make(map[string]json.RawMessage) - for _, b := range m.Modules { + for name, b := range m.Modules { if mod, ok := b.(HasGenesisBasics); ok { genesisData[mod.Name()] = mod.DefaultGenesis() - } else if mod, ok := b.(HasName); ok { - genesisData[mod.Name()] = []byte("{}") + } else if mod, ok := b.(appmodule.HasGenesis); ok { + genesisData[name] = mod.DefaultGenesis() + } else { + genesisData[name] = []byte("{}") } } @@ -337,12 +338,15 @@ func (m *Manager) DefaultGenesis() map[string]json.RawMessage { // ValidateGenesis performs genesis state validation for all modules func (m *Manager) ValidateGenesis(genesisData map[string]json.RawMessage) error { - for _, b := range m.Modules { - // first check if the module is an adapted Core API Module + for name, b := range m.Modules { if mod, ok := b.(HasGenesisBasics); ok { if err := mod.ValidateGenesis(genesisData[mod.Name()]); err != nil { return err } + } else if mod, ok := b.(appmodule.HasGenesis); ok { + if err := mod.ValidateGenesis(genesisData[name]); err != nil { + return err + } } } @@ -425,8 +429,8 @@ func (m *Manager) RegisterServices(cfg Configurator) error { // InitGenesis performs init genesis functionality for modules. Exactly one // module must return a non-empty validator set update to correctly initialize // the chain. -func (m *Manager) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, genesisData map[string]json.RawMessage) (*abci.ResponseInitChain, error) { - var validatorUpdates []abci.ValidatorUpdate +func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage) (*abci.ResponseInitChain, error) { + var validatorUpdates []ValidatorUpdate ctx.Logger().Info("initializing blockchain state from genesis.json") for _, moduleName := range m.OrderInitGenesis { if genesisData[moduleName] == nil { @@ -454,7 +458,10 @@ func (m *Manager) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, genesisData ma } } else if module, ok := mod.(HasABCIGenesis); ok { ctx.Logger().Debug("running initialization for module", "module", moduleName) - moduleValUpdates := module.InitGenesis(ctx, genesisData[moduleName]) + moduleValUpdates, err := module.InitGenesis(ctx, genesisData[moduleName]) + if err != nil { + return &abci.ResponseInitChain{}, err + } // use these validator updates if provided, the module manager assumes // only one module will update the validator set @@ -472,8 +479,32 @@ func (m *Manager) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, genesisData ma return &abci.ResponseInitChain{}, fmt.Errorf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction) } + cometValidatorUpdates := make([]abci.ValidatorUpdate, len(validatorUpdates)) + for i, v := range validatorUpdates { + var pubkey cmtcryptoproto.PublicKey + switch v.PubKeyType { + case "ed25519": + pubkey = cmtcryptoproto.PublicKey{ + Sum: &cmtcryptoproto.PublicKey_Ed25519{ + Ed25519: v.PubKey, + }, + } + case "secp256k1": + pubkey = cmtcryptoproto.PublicKey{ + Sum: &cmtcryptoproto.PublicKey_Secp256K1{ + Secp256K1: v.PubKey, + }, + } + } + + cometValidatorUpdates[i] = abci.ValidatorUpdate{ + PubKey: pubkey, + Power: v.Power, + } + } + return &abci.ResponseInitChain{ - Validators: validatorUpdates, + Validators: cometValidatorUpdates, }, nil } @@ -535,7 +566,11 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, modulesToExport []str channels[moduleName] = make(chan genesisResult) go func(module HasABCIGenesis, ch chan genesisResult) { ctx := ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) // avoid race conditions - ch <- genesisResult{module.ExportGenesis(ctx), nil} + jm, err := module.ExportGenesis(ctx) + if err != nil { + ch <- genesisResult{nil, err} + } + ch <- genesisResult{jm, nil} }(module, channels[moduleName]) } } @@ -590,12 +625,6 @@ func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames [] } } -// MigrationHandler is the migration function that each module registers. -type MigrationHandler func(sdk.Context) error - -// VersionMap is a map of moduleName -> version -type VersionMap map[string]uint64 - // RunMigrations performs in-place store migrations for all modules. This // function MUST be called inside an x/upgrade UpgradeHandler. // @@ -663,7 +692,7 @@ func (m Manager) RunMigrations(ctx context.Context, cfg Configurator, fromVM Ver module := m.Modules[moduleName] fromVersion, exists := fromVM[moduleName] toVersion := uint64(0) - if module, ok := module.(HasConsensusVersion); ok { + if module, ok := module.(appmodule.HasConsensusVersion); ok { toVersion = module.ConsensusVersion() } @@ -688,7 +717,11 @@ func (m Manager) RunMigrations(ctx context.Context, cfg Configurator, fromVM Ver } } if module, ok := m.Modules[moduleName].(HasABCIGenesis); ok { - moduleValUpdates := module.InitGenesis(sdkCtx, module.DefaultGenesis()) + moduleValUpdates, err := module.InitGenesis(sdkCtx, module.DefaultGenesis()) + if err != nil { + return nil, err + } + // The module manager assumes only one module will update the // validator set, and it can't be a new module. if len(moduleValUpdates) > 0 { @@ -741,7 +774,7 @@ func (m *Manager) BeginBlock(ctx sdk.Context) (sdk.BeginBlock, error) { // modules. func (m *Manager) EndBlock(ctx sdk.Context) (sdk.EndBlock, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) - validatorUpdates := []abci.ValidatorUpdate{} + validatorUpdates := []ValidatorUpdate{} for _, moduleName := range m.OrderEndBlockers { if module, ok := m.Modules[moduleName].(appmodule.HasEndBlocker); ok { @@ -766,8 +799,32 @@ func (m *Manager) EndBlock(ctx sdk.Context) (sdk.EndBlock, error) { } } + cometValidatorUpdates := make([]abci.ValidatorUpdate, len(validatorUpdates)) + for i, v := range validatorUpdates { + var pubkey cmtcryptoproto.PublicKey + switch v.PubKeyType { + case "ed25519": + pubkey = cmtcryptoproto.PublicKey{ + Sum: &cmtcryptoproto.PublicKey_Ed25519{ + Ed25519: v.PubKey, + }, + } + case "secp256k1": + pubkey = cmtcryptoproto.PublicKey{ + Sum: &cmtcryptoproto.PublicKey_Secp256K1{ + Secp256K1: v.PubKey, + }, + } + } + + cometValidatorUpdates[i] = abci.ValidatorUpdate{ + PubKey: pubkey, + Power: v.Power, + } + } + return sdk.EndBlock{ - ValidatorUpdates: validatorUpdates, + ValidatorUpdates: cometValidatorUpdates, Events: ctx.EventManager().ABCIEvents(), }, nil } @@ -805,7 +862,7 @@ func (m *Manager) GetVersionMap() VersionMap { vermap := make(VersionMap) for name, v := range m.Modules { version := uint64(0) - if v, ok := v.(HasConsensusVersion); ok { + if v, ok := v.(appmodule.HasConsensusVersion); ok { version = v.ConsensusVersion() } name := name diff --git a/types/module/module_test.go b/types/module/module_test.go index 670b088d5366..635b1ebe1d5e 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -172,16 +172,14 @@ func TestManager_InitGenesis(t *testing.T) { require.Equal(t, 3, len(mm.Modules)) ctx := sdk.NewContext(nil, false, log.NewNopLogger()) - interfaceRegistry := types.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(interfaceRegistry) genesisData := map[string]json.RawMessage{"module1": json.RawMessage(`{"key": "value"}`)} - // this should panic since the validator set is empty even after init genesis + // this should error since the validator set is empty even after init genesis mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module1"])).Times(1) - _, err := mm.InitGenesis(ctx, cdc, genesisData) + _, err := mm.InitGenesis(ctx, genesisData) require.ErrorContains(t, err, "validator set is empty after InitGenesis") - // test panic + // test error genesisData = map[string]json.RawMessage{ "module1": json.RawMessage(`{"key": "value"}`), "module2": json.RawMessage(`{"key": "value"}`), @@ -193,19 +191,19 @@ func TestManager_InitGenesis(t *testing.T) { mockAppModuleABCI1.EXPECT().Name().Times(4).Return("module1") mockAppModuleABCI2.EXPECT().Name().Times(2).Return("module2") mmABCI := module.NewManager(mockAppModuleABCI1, mockAppModuleABCI2) - // panic because more than one module returns validator set updates - mockAppModuleABCI1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{{}}) - mockAppModuleABCI2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module2"])).Times(1).Return([]abci.ValidatorUpdate{{}}) - _, err = mmABCI.InitGenesis(ctx, cdc, genesisData) + // errors because more than one module returns validator set updates + mockAppModuleABCI1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module1"])).Times(1).Return([]module.ValidatorUpdate{{}}, nil) + mockAppModuleABCI2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module2"])).Times(1).Return([]module.ValidatorUpdate{{}}, nil) + _, err = mmABCI.InitGenesis(ctx, genesisData) require.ErrorContains(t, err, "validator InitGenesis updates already set by a previous module") // happy path mm2 := module.NewManager(mockAppModuleABCI1, mockAppModule2, module.CoreAppModuleAdaptor("module3", mockAppModule3)) - mockAppModuleABCI1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{{}}) + mockAppModuleABCI1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module1"])).Times(1).Return([]module.ValidatorUpdate{{}}, nil) mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genesisData["module2"])).Times(1) mockAppModule3.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Any()).Times(1).Return(nil) - _, err = mm2.InitGenesis(ctx, cdc, genesisData) + _, err = mm2.InitGenesis(ctx, genesisData) require.NoError(t, err) } @@ -268,15 +266,15 @@ func TestManager_EndBlock(t *testing.T) { require.NotNil(t, mm) require.Equal(t, 3, len(mm.Modules)) - mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]abci.ValidatorUpdate{{}}, nil) + mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]module.ValidatorUpdate{{}}, nil) mockAppModule2.EXPECT().EndBlock(gomock.Any()).Times(1) ret, err := mm.EndBlock(sdk.Context{}) require.NoError(t, err) require.Equal(t, []abci.ValidatorUpdate{{}}, ret.ValidatorUpdates) // test panic - mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]abci.ValidatorUpdate{{}}, nil) - mockAppModule2.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]abci.ValidatorUpdate{{}}, nil) + mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]module.ValidatorUpdate{{}}, nil) + mockAppModule2.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]module.ValidatorUpdate{{}}, nil) _, err = mm.EndBlock(sdk.Context{}) require.Error(t, err) } @@ -307,13 +305,11 @@ func TestCoreAPIManager_InitGenesis(t *testing.T) { require.Equal(t, 1, len(mm.Modules)) ctx := sdk.NewContext(nil, false, log.NewNopLogger()) - interfaceRegistry := types.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(interfaceRegistry) genesisData := map[string]json.RawMessage{"module1": json.RawMessage(`{"key": "value"}`)} // this should panic since the validator set is empty even after init genesis mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Any()).Times(1).Return(nil) - _, err := mm.InitGenesis(ctx, cdc, genesisData) + _, err := mm.InitGenesis(ctx, genesisData) require.ErrorContains(t, err, "validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction") // TODO: add happy path test. We are not returning any validator updates, this will come with the services. diff --git a/x/accounts/module.go b/x/accounts/module.go index 71a16cff195a..6d19dde0a5ca 100644 --- a/x/accounts/module.go +++ b/x/accounts/module.go @@ -8,7 +8,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/accounts/cli" v1 "cosmossdk.io/x/accounts/v1" @@ -22,22 +21,20 @@ import ( const ( ModuleName = "accounts" StoreKey = "_" + ModuleName // unfortunately accounts collides with auth store key + + ConsensusVersion = 1 ) // ModuleAccountAddress defines the x/accounts module address. var ModuleAccountAddress = address.Module(ModuleName) -const ( - ConsensusVersion = 1 -) - var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} + _ module.HasName = AppModule{} - _ module.HasName = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - _ module.HasConsensusVersion = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasGenesis = AppModule{} + _ appmodule.HasConsensusVersion = AppModule{} ) func NewAppModule(cdc codec.Codec, k Keeper) AppModule { diff --git a/x/auth/module.go b/x/auth/module.go index d92176043dfb..e46711451a7b 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/auth/keeper" "cosmossdk.io/x/auth/simulation" @@ -30,8 +29,8 @@ const ( var ( _ module.AppModuleSimulation = AppModule{} _ module.HasName = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} + _ appmodule.HasGenesis = AppModule{} _ appmodule.AppModule = AppModule{} _ appmodule.HasServices = AppModule{} _ appmodule.HasMigrations = AppModule{} diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 65a9d00a97e5..9eb34ac5fd06 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/errors" "cosmossdk.io/x/authz" @@ -28,17 +27,17 @@ import ( const ConsensusVersion = 2 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} + _ appmodule.HasGenesis = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} ) // AppModule implements the sdk.AppModule interface diff --git a/x/bank/module.go b/x/bank/module.go index cee6253cd31a..62bafcb41778 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/bank/client/cli" "cosmossdk.io/x/bank/keeper" @@ -28,17 +27,17 @@ import ( const ConsensusVersion = 4 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - _ module.HasInvariants = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} ) // AppModule implements an application module for the bank module. diff --git a/x/circuit/module.go b/x/circuit/module.go index 71dc7ca417dc..c33d1c69e8c8 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/circuit/keeper" "cosmossdk.io/x/circuit/types" @@ -25,13 +24,13 @@ import ( const ConsensusVersion = 1 var ( - _ module.HasName = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} + _ module.HasName = AppModule{} + _ module.HasGRPCGateway = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasGenesis = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) // AppModule implements an application module for the circuit module. diff --git a/x/consensus/module.go b/x/consensus/module.go index 107ac6431b3c..c77502cc5ee3 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -20,12 +20,12 @@ import ( const ConsensusVersion = 1 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) // AppModule implements an application module diff --git a/x/counter/module.go b/x/counter/module.go index 5f4ea4312498..314db6ebefed 100644 --- a/x/counter/module.go +++ b/x/counter/module.go @@ -12,10 +12,10 @@ import ( ) var ( - _ module.HasName = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} + _ module.HasName = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) // AppModule implements an application module diff --git a/x/crisis/module.go b/x/crisis/module.go index 3773561197aa..bc981e86cea2 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "github.com/cosmos/cosmos-sdk/codec" @@ -24,15 +23,15 @@ import ( const ConsensusVersion = 2 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} + _ appmodule.HasGenesis = AppModule{} ) // Module init related flags diff --git a/x/distribution/module.go b/x/distribution/module.go index 116c613190ed..0d61ce1c47a1 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/distribution/client/cli" "cosmossdk.io/x/distribution/keeper" @@ -28,18 +27,18 @@ import ( const ConsensusVersion = 4 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - _ module.HasInvariants = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} ) // AppModule implements an application module for the distribution module. diff --git a/x/evidence/module.go b/x/evidence/module.go index 85ae9866b078..54d0ded5353b 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" eviclient "cosmossdk.io/x/evidence/client" "cosmossdk.io/x/evidence/client/cli" @@ -25,15 +24,15 @@ import ( ) var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} + _ appmodule.HasGenesis = AppModule{} ) const ConsensusVersion = 1 diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 42edb16f1ded..4f4ce2f29da3 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/errors" "cosmossdk.io/x/feegrant" @@ -24,17 +23,17 @@ import ( ) var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} ) // AppModule implements an application module for the feegrant module. diff --git a/x/genutil/module.go b/x/genutil/module.go index b16694ec2f6e..a37b7f021d3e 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" - abci "github.com/cometbft/cometbft/abci/types" - "cosmossdk.io/core/appmodule" "cosmossdk.io/core/genesis" "cosmossdk.io/core/registry" @@ -77,19 +75,39 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { } // InitGenesis performs genesis initialization for the genutil module. -func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) ([]module.ValidatorUpdate, error) { var genesisState types.GenesisState am.cdc.MustUnmarshalJSON(data, &genesisState) - validators, err := InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig) + cometValidatorUpdates, err := InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig) if err != nil { - panic(err) + return nil, err + } + + validatorUpdates := make([]module.ValidatorUpdate, len(cometValidatorUpdates)) + for i, v := range cometValidatorUpdates { + if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: ed25519, + PubKeyType: "ed25519", + Power: v.Power, + } + } else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: secp256k1, + PubKeyType: "secp256k1", + Power: v.Power, + } + } else { + return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey) + } } - return validators + + return validatorUpdates, nil } // ExportGenesis returns the exported genesis state as raw bytes for the genutil module. -func (am AppModule) ExportGenesis(_ context.Context) json.RawMessage { - return am.DefaultGenesis() +func (am AppModule) ExportGenesis(_ context.Context) (json.RawMessage, error) { + return am.DefaultGenesis(), nil } // GenTxValidator returns the genutil module's genesis transaction validator. diff --git a/x/gov/module.go b/x/gov/module.go index aa5069183b86..d36627293a2c 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" govclient "cosmossdk.io/x/gov/client" "cosmossdk.io/x/gov/client/cli" @@ -30,18 +29,18 @@ import ( const ConsensusVersion = 6 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - _ module.HasInvariants = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} ) // AppModule implements an application module for the gov module. diff --git a/x/group/module/module.go b/x/group/module/module.go index ab323da0b01f..a1f00cd9f1fa 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/group" "cosmossdk.io/x/group/client/cli" @@ -29,18 +28,18 @@ import ( const ConsensusVersion = 2 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - _ module.HasInvariants = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} ) type AppModule struct { diff --git a/x/mint/module.go b/x/mint/module.go index 2336c6306ef0..49192c2230a8 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/mint/keeper" "cosmossdk.io/x/mint/simulation" @@ -25,17 +24,17 @@ import ( const ConsensusVersion = 2 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} ) // AppModule implements an application module for the mint module. diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 9a5ca47effa0..c9a8e8b5b484 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -8,7 +8,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/errors" "cosmossdk.io/x/nft" @@ -23,13 +22,13 @@ import ( ) var ( - _ module.HasName = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} + _ module.HasName = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} - _ appmodule.AppModule = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasGenesis = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) const ConsensusVersion = 1 diff --git a/x/params/module.go b/x/params/module.go index 5cd796cc867c..6622e045a2e8 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -18,14 +18,14 @@ import ( ) var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) // ConsensusVersion defines the current x/params module consensus version. diff --git a/x/protocolpool/module.go b/x/protocolpool/module.go index 4539e9b1ab28..c9683d2fa570 100644 --- a/x/protocolpool/module.go +++ b/x/protocolpool/module.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/protocolpool/keeper" "cosmossdk.io/x/protocolpool/types" @@ -23,16 +22,15 @@ import ( const ConsensusVersion = 1 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ module.HasRegisterInterfaces = AppModule{} - _ module.AppModule = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasGenesis = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) // AppModule implements an application module for the pool module diff --git a/x/slashing/module.go b/x/slashing/module.go index 875727d62c0b..7d8499629a3c 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/slashing/keeper" "cosmossdk.io/x/slashing/simulation" @@ -26,17 +25,17 @@ import ( const ConsensusVersion = 4 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ module.HasRegisterInterfaces = AppModule{} - _ module.AppModuleSimulation = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) // AppModule implements an application module for the slashing module. diff --git a/x/staking/CHANGELOG.md b/x/staking/CHANGELOG.md index 4e635690e03c..522fc2dce0e3 100644 --- a/x/staking/CHANGELOG.md +++ b/x/staking/CHANGELOG.md @@ -41,7 +41,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* [#18198](https://github.com/cosmos/cosmos-sdk/pull/18198): `Validator` and `Delegator` interfaces were moved to `github.com/cosmos/cosmos-sdk/types` to avoid interface dependency on staking in other modules. +* [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) Update genesis api to match new `appmodule.HasGenesis` interface. +* [#18198](https://github.com/cosmos/cosmos-sdk/pull/18198) `Validator` and `Delegator` interfaces were moved to `github.com/cosmos/cosmos-sdk/types` to avoid interface dependency on staking in other modules. * [#17778](https://github.com/cosmos/cosmos-sdk/pull/17778) Use collections for `Params` * remove from `Keeper`: `GetParams`, `SetParams` * [#17486](https://github.com/cosmos/cosmos-sdk/pull/17486) Use collections for `RedelegationQueueKey`: diff --git a/x/staking/module.go b/x/staking/module.go index bbeefee67e85..c841b70546f3 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "google.golang.org/grpc" @@ -28,19 +27,19 @@ const ( ) var ( - _ module.AppModuleSimulation = AppModule{} - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} + _ module.AppModuleSimulation = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + _ module.HasInvariants = AppModule{} + _ module.HasABCIGenesis = AppModule{} + _ module.HasABCIEndBlock = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} - _ module.HasInvariants = AppModule{} - _ module.HasABCIGenesis = AppModule{} - _ module.HasABCIEndBlock = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} _ depinject.OnePerModuleType = AppModule{} ) @@ -146,18 +145,37 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { } // InitGenesis performs genesis initialization for the staking module. -func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) ([]module.ValidatorUpdate, error) { var genesisState types.GenesisState am.cdc.MustUnmarshalJSON(data, &genesisState) - return am.keeper.InitGenesis(ctx, &genesisState) + cometValidatorUpdates := am.keeper.InitGenesis(ctx, &genesisState) // TODO: refactor to return ValidatorUpdate higher up the stack + validatorUpdates := make([]module.ValidatorUpdate, len(cometValidatorUpdates)) + for i, v := range cometValidatorUpdates { + if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: ed25519, + PubKeyType: "ed25519", + Power: v.Power, + } + } else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: secp256k1, + PubKeyType: "secp256k1", + Power: v.Power, + } + } else { + return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey) + } + } + + return validatorUpdates, nil } -// ExportGenesis returns the exported genesis state as raw bytes for the staking -// module. -func (am AppModule) ExportGenesis(ctx context.Context) json.RawMessage { - return am.cdc.MustMarshalJSON(am.keeper.ExportGenesis(ctx)) +// ExportGenesis returns the exported genesis state as raw bytes for the staking module. +func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { + return am.cdc.MarshalJSON(am.keeper.ExportGenesis(ctx)) } // ConsensusVersion implements HasConsensusVersion @@ -169,6 +187,30 @@ func (am AppModule) BeginBlock(ctx context.Context) error { } // EndBlock returns the end blocker for the staking module. -func (am AppModule) EndBlock(ctx context.Context) ([]abci.ValidatorUpdate, error) { - return am.keeper.EndBlocker(ctx) +func (am AppModule) EndBlock(ctx context.Context) ([]module.ValidatorUpdate, error) { + cometValidatorUpdates, err := am.keeper.EndBlocker(ctx) // TODO: refactor to return appmodule.ValidatorUpdate higher up the stack + if err != nil { + return nil, err + } + + validatorUpdates := make([]module.ValidatorUpdate, len(cometValidatorUpdates)) + for i, v := range cometValidatorUpdates { + if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: ed25519, + PubKeyType: "ed25519", + Power: v.Power, + } + } else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: secp256k1, + PubKeyType: "secp256k1", + Power: v.Power, + } + } else { + return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey) + } + } + + return validatorUpdates, nil } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 7b7dbc50ec4d..8f011f79449a 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/x/upgrade/client/cli" "cosmossdk.io/x/upgrade/keeper" @@ -29,16 +28,16 @@ func init() { const ConsensusVersion uint64 = 3 var ( - _ module.HasName = AppModule{} - _ module.HasAminoCodec = AppModule{} - _ module.HasGRPCGateway = AppModule{} - _ module.HasRegisterInterfaces = AppModule{} - _ appmodulev2.HasGenesis = AppModule{} - - _ appmodule.AppModule = AppModule{} - _ appmodule.HasPreBlocker = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ module.HasName = AppModule{} + _ module.HasAminoCodec = AppModule{} + _ module.HasGRPCGateway = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasPreBlocker = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} + _ appmodule.HasGenesis = AppModule{} + _ appmodule.HasRegisterInterfaces = AppModule{} ) // AppModule implements the sdk.AppModule interface