From b1dbb6847e1227f5811cff894ffa27e4d340fa1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 24 Nov 2022 13:16:17 +0100 Subject: [PATCH 1/5] feat: add AppModuleBasic for tendermint client --- docs/migrations/v6-to-v7.md | 24 ++++++++- modules/core/types/codec.go | 2 - modules/light-clients/07-tendermint/module.go | 51 ++++++++++++++++++- testing/simapp/app.go | 2 + 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index c43bddd8dcf..16066f6eed0 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -13,7 +13,29 @@ There are four sections based on the four potential user groups of this document ## Chains -- No relevant changes were made in this release. +### Light client registration + +Chains must explicitly register the types of any light client modules it wishes to integrate. + +#### Tendermint registration + +To register the tendermint client, modify the `app.go` file to include the tendermint `AppModuleBasic`: + +```diff +import ( + ... ++ ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" + ... +) +... + +ModuleBasics = module.NewBasicManager( + ... + ibc.AppModuleBasic{}, ++ ibctm.AppModuleBasic{}, + ... +) +``` ## IBC Apps diff --git a/modules/core/types/codec.go b/modules/core/types/codec.go index 4c688e6ca28..96226e396ae 100644 --- a/modules/core/types/codec.go +++ b/modules/core/types/codec.go @@ -8,7 +8,6 @@ import ( channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v6/modules/core/23-commitment/types" solomachine "github.com/cosmos/ibc-go/v6/modules/light-clients/06-solomachine" - ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ) // RegisterInterfaces registers x/ibc interfaces into protobuf Any. @@ -17,6 +16,5 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { connectiontypes.RegisterInterfaces(registry) channeltypes.RegisterInterfaces(registry) solomachine.RegisterInterfaces(registry) - ibctm.RegisterInterfaces(registry) commitmenttypes.RegisterInterfaces(registry) } diff --git a/modules/light-clients/07-tendermint/module.go b/modules/light-clients/07-tendermint/module.go index 935bf34cafd..571a3ff24a8 100644 --- a/modules/light-clients/07-tendermint/module.go +++ b/modules/light-clients/07-tendermint/module.go @@ -1,6 +1,53 @@ package tendermint -// Name returns the IBC client name -func Name() string { +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" +) + +var _ module.AppModuleBasic = AppModuleBasic{} + +// AppModuleBasic defines the basic application module used by the tendermint light client. +type AppModuleBasic struct{} + +// Name returns the tendermint module name. +func (AppModuleBasic) Name() string { return SubModuleName } + +// RegisterLegacyAminoCodec does nothing. The Tendermint client does not support amino. +func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} + +// RegisterInterfaces registers module concrete types into protobuf Any. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + RegisterInterfaces(registry) +} + +// DefaultGenesis returns nil +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return nil +} + +// ValidateGenesis return nil +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + return nil +} + +// RegisterGRPCGatewayRoutes performs a no-op. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {} + +// GetTxCmd returns nil. +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns nil. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil +} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 702531b4996..42c6422f640 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -109,6 +109,7 @@ import ( porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" + ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ibcmock "github.com/cosmos/ibc-go/v6/testing/mock" simappparams "github.com/cosmos/ibc-go/v6/testing/simapp/params" simappupgrades "github.com/cosmos/ibc-go/v6/testing/simapp/upgrades" @@ -153,6 +154,7 @@ var ( crisis.AppModuleBasic{}, slashing.AppModuleBasic{}, ibc.AppModuleBasic{}, + ibctm.AppModuleBasic{}, feegrantmodule.AppModuleBasic{}, upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, From 9b47794da1ac5f7532bde2b68071c88c70667faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 24 Nov 2022 13:24:04 +0100 Subject: [PATCH 2/5] chore: add additional information --- docs/migrations/v6-to-v7.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index 16066f6eed0..5c6de5ef341 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -37,6 +37,8 @@ ModuleBasics = module.NewBasicManager( ) ``` +It may be useful to reference the [PR](https://github.com/cosmos/ibc-go/pull/2825) which added the `AppModuleBasic` for the tendermint client. + ## IBC Apps - No relevant changes were made in this release. From 900ee3a7fb18adf872819cf08da74c8b8221db37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 24 Nov 2022 13:25:20 +0100 Subject: [PATCH 3/5] chore: add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08a7139458d..8caf3d4da90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,6 +115,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (light-clients/07-tendermint) [\#2825](https://github.com/cosmos/ibc-go/pull/2825) Add `AppModuleBasic` for the 07-tendermint client and remove tendermint type registration from core IBC. Chains must register the `AppModuleBasic` of light clients. * (core/24-host) [\#2820](https://github.com/cosmos/ibc-go/pull/2820) Add `MustParseClientStatePath` which parses the clientID from a client state key path. * (apps/27-interchain-accounts) [\#2147](https://github.com/cosmos/ibc-go/pull/2147) Adding a `SubmitTx` gRPC endpoint for the ICS27 Controller module which allows owners of interchain accounts to submit transactions. This replaces the previously existing need for authentication modules to implement this standard functionality. * (testing/simapp) [\#2190](https://github.com/cosmos/ibc-go/pull/2190) Adding the new `x/group` cosmos-sdk module to simapp. From 4ab248df489a32bda8b11d7a6f65f50ec1ea192d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:30:10 +0100 Subject: [PATCH 4/5] chore: fix indentation --- docs/migrations/v6-to-v7.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index 5c6de5ef341..0f9e3ac23ef 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -23,17 +23,17 @@ To register the tendermint client, modify the `app.go` file to include the tende ```diff import ( - ... -+ ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" - ... + ... ++ ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" + ... ) ... ModuleBasics = module.NewBasicManager( - ... - ibc.AppModuleBasic{}, -+ ibctm.AppModuleBasic{}, - ... + ... + ibc.AppModuleBasic{}, ++ ibctm.AppModuleBasic{}, + ... ) ``` From 5b86a55c3aec14bfd6600fa908c6210ac6b11f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:32:03 +0100 Subject: [PATCH 5/5] chore: improve godoc for module.go --- modules/light-clients/07-tendermint/module.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/light-clients/07-tendermint/module.go b/modules/light-clients/07-tendermint/module.go index 571a3ff24a8..653c7098a8c 100644 --- a/modules/light-clients/07-tendermint/module.go +++ b/modules/light-clients/07-tendermint/module.go @@ -14,6 +14,8 @@ import ( var _ module.AppModuleBasic = AppModuleBasic{} // AppModuleBasic defines the basic application module used by the tendermint light client. +// Only the RegisterInterfaces function needs to be implemented. All other function perform +// a no-op. type AppModuleBasic struct{} // Name returns the tendermint module name. @@ -21,20 +23,21 @@ func (AppModuleBasic) Name() string { return SubModuleName } -// RegisterLegacyAminoCodec does nothing. The Tendermint client does not support amino. +// RegisterLegacyAminoCodec performs a no-op. The Tendermint client does not support amino. func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} -// RegisterInterfaces registers module concrete types into protobuf Any. +// RegisterInterfaces registers module concrete types into protobuf Any. This allows core IBC +// to unmarshal tendermint light client types. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { RegisterInterfaces(registry) } -// DefaultGenesis returns nil +// DefaultGenesis performs a no-op. Genesis is not supported for the tendermint light client. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return nil } -// ValidateGenesis return nil +// ValidateGenesis performs a no-op. Genesis is not supported for the tendermint light cilent. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { return nil } @@ -42,12 +45,12 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod // RegisterGRPCGatewayRoutes performs a no-op. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {} -// GetTxCmd returns nil. +// GetTxCmd performs a no-op. Please see the 02-client cli commands. func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil } -// GetQueryCmd returns nil. +// GetQueryCmd performs a no-op. Please see the 02-client cli commands. func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }