diff --git a/CHANGELOG.md b/CHANGELOG.md index c5379e185147..05e0c77af62c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -147,6 +147,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (types) [#18695](https://github.com/cosmos/cosmos-sdk/pull/18695) Removed global configuration for txEncoder. * (types) [#18607](https://github.com/cosmos/cosmos-sdk/pull/18607) Removed address verifier from global config, moved verifier function to bech32 codec. * (server) [#18909](https://github.com/cosmos/cosmos-sdk/pull/18909) Remove configuration endpoint on grpc reflection endpoint in favour of auth module bech32prefix endpoint already exposed. +* (crypto) [#19541](https://github.com/cosmos/cosmos-sdk/pull/19541) The deprecated `FromTmProtoPublicKey`, `ToTmProtoPublicKey`, `FromTmPubKeyInterface` and `ToTmPubKeyInterface` functions have been removed. Use their replacements (`Cmt` instead of `Tm`) instead. ### Client Breaking Changes diff --git a/crypto/codec/cmt.go b/crypto/codec/cmt.go index ee8889fd2fcf..c69d416efeac 100644 --- a/crypto/codec/cmt.go +++ b/crypto/codec/cmt.go @@ -68,25 +68,3 @@ func ToCmtPubKeyInterface(pk cryptotypes.PubKey) (cmtcrypto.PubKey, error) { return encoding.PubKeyFromProto(tmProtoPk) } - -// ---------------------- - -// Deprecated: use FromCmtProtoPublicKey instead. -func FromTmProtoPublicKey(protoPk cmtprotocrypto.PublicKey) (cryptotypes.PubKey, error) { - return FromCmtProtoPublicKey(protoPk) -} - -// Deprecated: use ToCmtProtoPublicKey instead. -func ToTmProtoPublicKey(pk cryptotypes.PubKey) (cmtprotocrypto.PublicKey, error) { - return ToCmtProtoPublicKey(pk) -} - -// Deprecated: use FromCmtPubKeyInterface instead. -func FromTmPubKeyInterface(tmPk cmtcrypto.PubKey) (cryptotypes.PubKey, error) { - return FromCmtPubKeyInterface(tmPk) -} - -// Deprecated: use ToCmtPubKeyInterface instead. -func ToTmPubKeyInterface(pk cryptotypes.PubKey) (cmtcrypto.PubKey, error) { - return ToCmtPubKeyInterface(pk) -} diff --git a/runtime/services/autocli.go b/runtime/services/autocli.go index 86354f8e4944..e8a4682e3732 100644 --- a/runtime/services/autocli.go +++ b/runtime/services/autocli.go @@ -25,7 +25,7 @@ type AutoCLIQueryService struct { } // NewAutoCLIQueryService returns a AutoCLIQueryService for the provided modules. -func NewAutoCLIQueryService(appModules map[string]interface{}) *AutoCLIQueryService { +func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService { return &AutoCLIQueryService{ moduleOptions: ExtractAutoCLIOptions(appModules), } @@ -36,7 +36,7 @@ func NewAutoCLIQueryService(appModules map[string]interface{}) *AutoCLIQueryServ // Example Usage: // // ExtractAutoCLIOptions(ModuleManager.Modules) -func ExtractAutoCLIOptions(appModules map[string]interface{}) map[string]*autocliv1.ModuleOptions { +func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) map[string]*autocliv1.ModuleOptions { moduleOptions := map[string]*autocliv1.ModuleOptions{} for modName, mod := range appModules { if autoCliMod, ok := mod.(interface { diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index eabd3384d611..2aac944f3138 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -19,6 +19,79 @@ import ( runtime "github.com/grpc-ecosystem/grpc-gateway/runtime" ) +// MockAppModuleBasic is a mock of AppModuleBasic interface. +type MockAppModuleBasic struct { + ctrl *gomock.Controller + recorder *MockAppModuleBasicMockRecorder +} + +// MockAppModuleBasicMockRecorder is the mock recorder for MockAppModuleBasic. +type MockAppModuleBasicMockRecorder struct { + mock *MockAppModuleBasic +} + +// NewMockAppModuleBasic creates a new mock instance. +func NewMockAppModuleBasic(ctrl *gomock.Controller) *MockAppModuleBasic { + mock := &MockAppModuleBasic{ctrl: ctrl} + mock.recorder = &MockAppModuleBasicMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAppModuleBasic) EXPECT() *MockAppModuleBasicMockRecorder { + return m.recorder +} + +// Name mocks base method. +func (m *MockAppModuleBasic) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockAppModuleBasicMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAppModuleBasic)(nil).Name)) +} + +// RegisterGRPCGatewayRoutes mocks base method. +func (m *MockAppModuleBasic) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) +} + +// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. +func (mr *MockAppModuleBasicMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) +} + +// RegisterInterfaces mocks base method. +func (m *MockAppModuleBasic) RegisterInterfaces(arg0 types0.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces. +func (mr *MockAppModuleBasicMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterInterfaces), arg0) +} + +// RegisterLegacyAminoCodec mocks base method. +func (m *MockAppModuleBasic) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockAppModuleBasicMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterLegacyAminoCodec), arg0) +} + // MockAppModule is a mock of AppModule interface. type MockAppModule struct { ctrl *gomock.Controller diff --git a/types/module/module.go b/types/module/module.go index 640d733fb6a2..7afba9f1211d 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -127,10 +127,6 @@ type HasConsensusVersion interface { ConsensusVersion() uint64 } -// HasABCIEndblock is a released typo of HasABCIEndBlock. -// Deprecated: use HasABCIEndBlock instead. -type HasABCIEndblock HasABCIEndBlock - // HasABCIEndBlock is the interface for modules that need to run code at the end of the block. type HasABCIEndBlock interface { AppModule @@ -140,7 +136,7 @@ type HasABCIEndBlock interface { // Manager defines a module manager that provides the high level utility for managing and executing // operations for a group of modules type Manager struct { - Modules map[string]interface{} // interface{} is used now to support the legacy AppModule as well as new core appmodule.AppModule. + Modules map[string]appmodule.AppModule OrderInitGenesis []string OrderExportGenesis []string OrderPreBlockers []string @@ -153,7 +149,7 @@ type Manager struct { // NewManager creates a new Manager object. func NewManager(modules ...AppModule) *Manager { - moduleMap := make(map[string]interface{}) + moduleMap := make(map[string]appmodule.AppModule) modulesStr := make([]string, 0, len(modules)) preBlockModulesStr := make([]string, 0) for _, module := range modules { @@ -183,7 +179,7 @@ func NewManager(modules ...AppModule) *Manager { // NewManagerFromMap creates a new Manager object from a map of module names to module implementations. // This method should be used for apps and modules which have migrated to the cosmossdk.io/core.appmodule.AppModule API. func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { - simpleModuleMap := make(map[string]interface{}) + simpleModuleMap := make(map[string]appmodule.AppModule) modulesStr := make([]string, 0, len(simpleModuleMap)) preBlockModulesStr := make([]string, 0) for name, module := range moduleMap { @@ -767,12 +763,8 @@ func (m *Manager) EndBlock(ctx sdk.Context) (sdk.EndBlock, error) { return sdk.EndBlock{}, errors.New("validator EndBlock updates already set by a previous module") } - for _, updates := range moduleValUpdates { - validatorUpdates = append(validatorUpdates, abci.ValidatorUpdate{PubKey: updates.PubKey, Power: updates.Power}) - } + validatorUpdates = append(validatorUpdates, moduleValUpdates...) } - } else { - continue } } diff --git a/types/module/module_int_test.go b/types/module/module_int_test.go index 443ee0bbcba2..87fd3ea90131 100644 --- a/types/module/module_int_test.go +++ b/types/module/module_int_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/stretchr/testify/suite" + + "cosmossdk.io/core/appmodule" ) func TestModuleIntSuite(t *testing.T) { @@ -17,7 +19,7 @@ type TestSuite struct { func (s *TestSuite) TestAssertNoForgottenModules() { m := Manager{ - Modules: map[string]interface{}{"a": nil, "b": nil}, + Modules: map[string]appmodule.AppModule{"a": nil, "b": nil}, } tcs := []struct { name string @@ -42,7 +44,7 @@ func (s *TestSuite) TestAssertNoForgottenModules() { func (s *TestSuite) TestModuleNames() { m := Manager{ - Modules: map[string]interface{}{"a": nil, "b": nil}, + Modules: map[string]appmodule.AppModule{"a": nil, "b": nil}, } ms := m.ModuleNames() sort.Strings(ms) diff --git a/types/module/simulation.go b/types/module/simulation.go index 657bbfa2c2eb..32e8f7da8ed4 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -6,6 +6,7 @@ import ( "sort" "time" + "cosmossdk.io/core/appmodule" sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" @@ -61,7 +62,7 @@ func NewSimulationManager(modules ...AppModuleSimulation) *SimulationManager { // with the same moduleName. // Then it attempts to cast every provided AppModule into an AppModuleSimulation. // If the cast succeeds, its included, otherwise it is excluded. -func NewSimulationManagerFromAppModules(modules map[string]interface{}, overrideModules map[string]AppModuleSimulation) *SimulationManager { +func NewSimulationManagerFromAppModules(modules map[string]appmodule.AppModule, overrideModules map[string]AppModuleSimulation) *SimulationManager { simModules := []AppModuleSimulation{} appModuleNamesSorted := make([]string, 0, len(modules)) for moduleName := range modules { diff --git a/x/staking/module.go b/x/staking/module.go index 2e4254133d17..46d3875dd3f8 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -168,8 +168,7 @@ func (am AppModule) BeginBlock(ctx context.Context) error { return am.keeper.BeginBlocker(ctx) } -// EndBlock returns the end blocker for the staking module. It returns no validator -// updates. +// EndBlock returns the end blocker for the staking module. func (am AppModule) EndBlock(ctx context.Context) ([]abci.ValidatorUpdate, error) { return am.keeper.EndBlocker(ctx) } diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index f51d4e3990e7..141e91615040 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -259,7 +259,7 @@ func (d Description) EnsureLength() (Description, error) { // ABCIValidatorUpdate returns an abci.ValidatorUpdate from a staking validator type // with the full validator power func (v Validator) ABCIValidatorUpdate(r math.Int) abci.ValidatorUpdate { - tmProtoPk, err := v.TmConsPublicKey() + tmProtoPk, err := v.CmtConsPublicKey() if err != nil { panic(err) } @@ -273,7 +273,7 @@ func (v Validator) ABCIValidatorUpdate(r math.Int) abci.ValidatorUpdate { // ABCIValidatorUpdateZero returns an abci.ValidatorUpdate from a staking validator type // with zero power used for validator updates. func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate { - tmProtoPk, err := v.TmConsPublicKey() + tmProtoPk, err := v.CmtConsPublicKey() if err != nil { panic(err) } @@ -473,11 +473,6 @@ func (v Validator) ConsPubKey() (cryptotypes.PubKey, error) { return pk, nil } -// Deprecated: use CmtConsPublicKey instead -func (v Validator) TmConsPublicKey() (cmtprotocrypto.PublicKey, error) { - return v.CmtConsPublicKey() -} - // CmtConsPublicKey casts Validator.ConsensusPubkey to cmtprotocrypto.PubKey. func (v Validator) CmtConsPublicKey() (cmtprotocrypto.PublicKey, error) { pk, err := v.ConsPubKey() @@ -493,6 +488,12 @@ func (v Validator) CmtConsPublicKey() (cmtprotocrypto.PublicKey, error) { return tmPk, nil } +// Deprecated: use CmtConsPublicKey instead +// We do not delete this function as it is part of the ValidatorI interface +func (v Validator) TmConsPublicKey() (cmtprotocrypto.PublicKey, error) { + return v.CmtConsPublicKey() +} + // GetConsAddr extracts Consensus key address func (v Validator) GetConsAddr() ([]byte, error) { pk, ok := v.ConsensusPubkey.GetCachedValue().(cryptotypes.PubKey)