Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: api cleanups #19541

Merged
merged 6 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 0 additions & 22 deletions crypto/codec/cmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions runtime/services/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand All @@ -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 {
Expand Down
73 changes: 73 additions & 0 deletions testutil/mock/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down
5 changes: 3 additions & 2 deletions types/module/module_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"sort"
"testing"

"cosmossdk.io/core/appmodule"
"github.com/stretchr/testify/suite"
)

Expand All @@ -17,7 +18,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
Expand All @@ -42,7 +43,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)
Expand Down
3 changes: 2 additions & 1 deletion types/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"time"

"cosmossdk.io/core/appmodule"
sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
15 changes: 8 additions & 7 deletions x/staking/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
Loading