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

refactor: rename core.registry.LegacyRegistry -> core.registry.InterfaceRegistrar #19758

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (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.
* (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652)
* (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652) and [#19758](https://github.com/cosmos/cosmos-sdk/pull/19758)
* Moved`types/module.HasRegisterInterfaces` to `cosmossdk.io/core`.
* Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.LegacyRegistry` interface.
* Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.InterfaceRegistrar` interface.
Comment on lines +147 to +149
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a minor typographical error in the changelog entry. A space is missing after "Moved". Correcting this will improve the readability of the document.

- Moved`types/module.HasRegisterInterfaces` to `cosmossdk.io/core`.
+ Moved `types/module.HasRegisterInterfaces` to `cosmossdk.io/core`.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652) and [#19758](https://github.com/cosmos/cosmos-sdk/pull/19758)
* Moved`types/module.HasRegisterInterfaces` to `cosmossdk.io/core`.
* Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.LegacyRegistry` interface.
* Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.InterfaceRegistrar` interface.
* (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652) and [#19758](https://github.com/cosmos/cosmos-sdk/pull/19758)
* Moved `types/module.HasRegisterInterfaces` to `cosmossdk.io/core`.
* Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.InterfaceRegistrar` interface.

* (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.
Expand Down
4 changes: 2 additions & 2 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ If your module requires a message server or query server, it should be passed in
+govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger, runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String())
```

The signature of the extension interface `HasRegisterInterfaces` has been changed to accept a `cosmossdk.io/core/registry.LegacyRegistry` instead of a `codec.InterfaceRegistry`. `HasRegisterInterfaces` is now a part of `cosmossdk.io/core/appmodule`. Modules should update their `HasRegisterInterfaces` implementation to accept a `cosmossdk.io/core/registry.LegacyRegistry` interface.
The signature of the extension interface `HasRegisterInterfaces` has been changed to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` instead of a `codec.InterfaceRegistry`. `HasRegisterInterfaces` is now a part of `cosmossdk.io/core/appmodule`. Modules should update their `HasRegisterInterfaces` implementation to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` interface.

```diff
-func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
+func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
+func (AppModule) RegisterInterfaces(registry registry.InterfaceRegistrar) {
```

##### Dependency Injection
Expand Down
2 changes: 1 addition & 1 deletion codec/types/interface_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type AnyUnpacker interface {
type InterfaceRegistry interface {
AnyUnpacker
jsonpb.AnyResolver
registry.LegacyRegistry
registry.InterfaceRegistrar

// ListAllInterfaces list the type URLs of all registered interfaces.
ListAllInterfaces() []string
Expand Down
2 changes: 1 addition & 1 deletion core/appmodule/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ type ValidatorUpdate struct {

// HasRegisterInterfaces is the interface for modules to register their msg types.
type HasRegisterInterfaces interface {
RegisterInterfaces(registry.LegacyRegistry)
RegisterInterfaces(registry.InterfaceRegistrar)
}
2 changes: 1 addition & 1 deletion core/registry/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"google.golang.org/protobuf/runtime/protoiface"
)

type LegacyRegistry interface {
type InterfaceRegistrar interface {
// RegisterInterface associates protoName as the public name for the
// interface passed in as iface. This is to be used primarily to create
// a public facing registry of interface implementations for clients.
Expand Down
4 changes: 2 additions & 2 deletions testutil/mock/types_mock_appmodule.go

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

6 changes: 3 additions & 3 deletions testutil/mock/types_module_module.go

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

4 changes: 2 additions & 2 deletions types/module/core_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ func (c coreAppModuleAdaptor) RegisterGRPCGatewayRoutes(ctx client.Context, mux
}

// RegisterInterfaces implements HasRegisterInterfaces
func (c coreAppModuleAdaptor) RegisterInterfaces(reg registry.LegacyRegistry) {
func (c coreAppModuleAdaptor) RegisterInterfaces(reg registry.InterfaceRegistrar) {
if mod, ok := c.module.(interface {
RegisterInterfaces(registry.LegacyRegistry)
RegisterInterfaces(registry.InterfaceRegistrar)
}); ok {
mod.RegisterInterfaces(reg)
}
Expand Down
4 changes: 2 additions & 2 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ func (m *Manager) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
}

// RegisterInterfaces registers all module interface types
func (m *Manager) RegisterInterfaces(registry registry.LegacyRegistry) {
func (m *Manager) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
for _, b := range m.Modules {
if mod, ok := b.(appmodule.HasRegisterInterfaces); ok {
mod.RegisterInterfaces(registry)
mod.RegisterInterfaces(registrar)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions types/msgservice/msg_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// RegisterMsgServiceDesc registers all type_urls from Msg services described
// in `sd` into the registry.
func RegisterMsgServiceDesc(registry registry.LegacyRegistry, sd *grpc.ServiceDesc) {
func RegisterMsgServiceDesc(registrar registry.InterfaceRegistrar, sd *grpc.ServiceDesc) {
fdBytesUnzipped := unzip(proto.FileDescriptor(sd.Metadata.(string)))
if fdBytesUnzipped == nil {
panic(fmt.Errorf("error unzipping file description for MsgService %s", sd.ServiceName))
Expand Down Expand Up @@ -51,8 +51,8 @@ func RegisterMsgServiceDesc(registry registry.LegacyRegistry, sd *grpc.ServiceDe
respTyp := proto.MessageType(string(responseDesc.FullName()))

// Register sdk.Msg and sdk.MsgResponse to the registry.
registry.RegisterImplementations((*sdk.Msg)(nil), reflect.New(reqTyp).Elem().Interface().(proto.Message))
registry.RegisterImplementations((*tx.MsgResponse)(nil), reflect.New(respTyp).Elem().Interface().(proto.Message))
registrar.RegisterImplementations((*sdk.Msg)(nil), reflect.New(reqTyp).Elem().Interface().(proto.Message))
registrar.RegisterImplementations((*tx.MsgResponse)(nil), reflect.New(respTyp).Elem().Interface().(proto.Message))
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (m AppModule) IsAppModule() {}

func (AppModule) Name() string { return ModuleName }

func (m AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
msgservice.RegisterMsgServiceDesc(registry, v1.MsgServiceDesc())
func (m AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
msgservice.RegisterMsgServiceDesc(registrar, v1.MsgServiceDesc())
}

// App module services
Expand Down
4 changes: 2 additions & 2 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwrunt
}

// RegisterInterfaces registers interfaces and implementations of the auth module.
func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
types.RegisterInterfaces(registry)
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
types.RegisterInterfaces(registrar)
}

// RegisterServices registers module services.
Expand Down
12 changes: 6 additions & 6 deletions x/auth/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

// RegisterInterfaces associates protoName with AccountI interface
// and creates a registry of it's concrete implementations
func RegisterInterfaces(registry registry.LegacyRegistry) {
registry.RegisterInterface(
func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
registrar.RegisterInterface(
"cosmos.auth.v1beta1.AccountI",
(*AccountI)(nil),
&BaseAccount{},
&ModuleAccount{},
)

registry.RegisterInterface(
registrar.RegisterInterface(
"cosmos.auth.v1beta1.AccountI",
(*sdk.AccountI)(nil),
&BaseAccount{},
&ModuleAccount{},
)

registry.RegisterInterface(
registrar.RegisterInterface(
"cosmos.auth.v1beta1.GenesisAccount",
(*GenesisAccount)(nil),
&BaseAccount{},
&ModuleAccount{},
)

registry.RegisterInterface(
registrar.RegisterInterface(
"cosmos.auth.v1.ModuleCredential",
(*cryptotypes.PubKey)(nil),
&ModuleCredential{},
)

registry.RegisterImplementations((*sdk.Msg)(nil),
registrar.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateParams{},
)
}
4 changes: 2 additions & 2 deletions x/auth/vesting/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

// RegisterInterfaces registers the module's interfaces and implementations with
// the given interface registry.
func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
types.RegisterInterfaces(registry)
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
types.RegisterInterfaces(registrar)
}

// ConsensusVersion implements HasConsensusVersion.
Expand Down
12 changes: 6 additions & 6 deletions x/auth/vesting/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

// RegisterInterface associates protoName with AccountI and VestingAccount
// Interfaces and creates a registry of it's concrete implementations
func RegisterInterfaces(registry registry.LegacyRegistry) {
registry.RegisterInterface(
func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
registrar.RegisterInterface(
"cosmos.vesting.v1beta1.VestingAccount",
(*exported.VestingAccount)(nil),
&ContinuousVestingAccount{},
Expand All @@ -37,7 +37,7 @@ func RegisterInterfaces(registry registry.LegacyRegistry) {
&PermanentLockedAccount{},
)

registry.RegisterImplementations(
registrar.RegisterImplementations(
(*sdk.AccountI)(nil),
&BaseVestingAccount{},
&DelayedVestingAccount{},
Expand All @@ -46,7 +46,7 @@ func RegisterInterfaces(registry registry.LegacyRegistry) {
&PermanentLockedAccount{},
)

registry.RegisterImplementations(
registrar.RegisterImplementations(
(*authtypes.GenesisAccount)(nil),
&BaseVestingAccount{},
&DelayedVestingAccount{},
Expand All @@ -55,11 +55,11 @@ func RegisterInterfaces(registry registry.LegacyRegistry) {
&PermanentLockedAccount{},
)

registry.RegisterImplementations(
registrar.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgCreateVestingAccount{},
&MsgCreatePermanentLockedAccount{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc)
}
8 changes: 4 additions & 4 deletions x/authz/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
}

// RegisterInterfaces registers the interfaces types with the interface registry
func RegisterInterfaces(registry registry.LegacyRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
registrar.RegisterImplementations((*sdk.Msg)(nil),
&MsgGrant{},
&MsgRevoke{},
&MsgExec{},
Expand All @@ -34,12 +34,12 @@ func RegisterInterfaces(registry registry.LegacyRegistry) {
// and authz depends on x/bank and x/staking in other places, these registrations are placed here
// to prevent a cyclic dependency.
// see: https://github.com/cosmos/cosmos-sdk/pull/16509
registry.RegisterInterface(
registrar.RegisterInterface(
"cosmos.authz.v1beta1.Authorization",
(*Authorization)(nil),
&GenericAuthorization{},
&bank.SendAuthorization{},
&staking.StakeAuthorization{},
)
msgservice.RegisterMsgServiceDesc(registry, MsgServiceDesc())
msgservice.RegisterMsgServiceDesc(registrar, MsgServiceDesc())
}
4 changes: 2 additions & 2 deletions x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
}

// RegisterInterfaces registers the authz module's interface types
func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
authz.RegisterInterfaces(registry)
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
authz.RegisterInterfaces(registrar)
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module.
Expand Down
4 changes: 2 additions & 2 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (AppModule) GetTxCmd() *cobra.Command {
}

// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
types.RegisterInterfaces(registry)
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
types.RegisterInterfaces(registrar)
}

// RegisterServices registers module services.
Expand Down
6 changes: 3 additions & 3 deletions x/bank/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&Params{}, "cosmos-sdk/x/bank/Params", nil)
}

func RegisterInterfaces(registry registry.LegacyRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
registrar.RegisterImplementations((*sdk.Msg)(nil),
&MsgSend{},
&MsgMultiSend{},
&MsgUpdateParams{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc)
}
4 changes: 2 additions & 2 deletions x/circuit/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwrunt
}

// RegisterInterfaces registers interfaces and implementations of the circuit module.
func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
types.RegisterInterfaces(registry)
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
types.RegisterInterfaces(registrar)
}

// RegisterServices registers module services.
Expand Down
6 changes: 3 additions & 3 deletions x/circuit/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

// RegisterInterfaces registers the interfaces types with the interface registry.
func RegisterInterfaces(registry registry.LegacyRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
registrar.RegisterImplementations((*sdk.Msg)(nil),
&MsgAuthorizeCircuitBreaker{},
&MsgResetCircuitBreaker{},
&MsgTripCircuitBreaker{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc)
}
4 changes: 2 additions & 2 deletions x/consensus/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwrunt
}

// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
types.RegisterInterfaces(registry)
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
types.RegisterInterfaces(registrar)
}

// RegisterServices registers module services.
Expand Down
6 changes: 3 additions & 3 deletions x/consensus/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

func RegisterInterfaces(registry registry.LegacyRegistry) {
registry.RegisterImplementations(
func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
registrar.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgUpdateParams{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc)
}

// RegisterLegacyAminoCodec registers the necessary x/consensus interfaces and concrete types
Expand Down
4 changes: 2 additions & 2 deletions x/counter/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) Name() string { return types.ModuleName }

// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModule) RegisterInterfaces(registry registry.LegacyRegistry) {
types.RegisterInterfaces(registry)
func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
types.RegisterInterfaces(registrar)
}
Loading
Loading