From ff5cc2bb91debc154ecf1fd6023d5d1640bc01bc Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 09:31:02 +0200 Subject: [PATCH 1/6] feat: adding VerifyClientMessage to ClientState interface --- modules/core/02-client/legacy/v100/solomachine.go | 7 +++++++ modules/core/exported/client.go | 4 +++- .../07-tendermint/types/misbehaviour_handle.go | 2 +- modules/light-clients/07-tendermint/types/update.go | 4 ++-- modules/light-clients/09-localhost/types/client_state.go | 9 +++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/core/02-client/legacy/v100/solomachine.go b/modules/core/02-client/legacy/v100/solomachine.go index c9814439902..81457f8a328 100644 --- a/modules/core/02-client/legacy/v100/solomachine.go +++ b/modules/core/02-client/legacy/v100/solomachine.go @@ -88,6 +88,13 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { panic("legacy solo machine is deprecated!") } +// VerifyClientMessage returns nil +func (cs *ClientState) VerifyClientMessage( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, +) error { + return nil +} + // CheckHeaderAndUpdateState panics! func (cs *ClientState) CheckHeaderAndUpdateState( _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 39095aff28f..5abc00d7806 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -56,8 +56,10 @@ type ClientState interface { // Genesis function ExportMetadata(sdk.KVStore) []GenesisMetadata - // Update and Misbehaviour functions + // VerifyClientMessage verifies a Header or a Misbehaviour + VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg ClientMessage) error + // Update and Misbehaviour functions CheckHeaderAndUpdateState(sdk.Context, codec.BinaryCodec, sdk.KVStore, ClientMessage) (ClientState, ConsensusState, error) CheckMisbehaviourAndUpdateState(sdk.Context, codec.BinaryCodec, sdk.KVStore, ClientMessage) (ClientState, error) CheckSubstituteAndUpdateState(ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore sdk.KVStore, substituteClient ClientState) (ClientState, error) diff --git a/modules/light-clients/07-tendermint/types/misbehaviour_handle.go b/modules/light-clients/07-tendermint/types/misbehaviour_handle.go index 932829aa56b..7dce230b6f7 100644 --- a/modules/light-clients/07-tendermint/types/misbehaviour_handle.go +++ b/modules/light-clients/07-tendermint/types/misbehaviour_handle.go @@ -32,7 +32,7 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState( return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", misbehaviour, &Misbehaviour{}) } - if err := cs.VerifyClientMessage(ctx, clientStore, cdc, tmMisbehaviour); err != nil { + if err := cs.VerifyClientMessage(ctx, cdc, clientStore, tmMisbehaviour); err != nil { return nil, err } diff --git a/modules/light-clients/07-tendermint/types/update.go b/modules/light-clients/07-tendermint/types/update.go index 0862447a4b3..615ed14a381 100644 --- a/modules/light-clients/07-tendermint/types/update.go +++ b/modules/light-clients/07-tendermint/types/update.go @@ -64,7 +64,7 @@ func (cs ClientState) CheckHeaderAndUpdateState( conflictingHeader = true } - if err := cs.VerifyClientMessage(ctx, clientStore, cdc, tmHeader); err != nil { + if err := cs.VerifyClientMessage(ctx, cdc, clientStore, tmHeader); err != nil { return nil, nil, err } @@ -119,7 +119,7 @@ func checkTrustedHeader(header *Header, consState *ConsensusState) error { // VerifyClientMessage checks if the clientMessage is of type Header or Misbehaviour and verifies the message func (cs *ClientState) VerifyClientMessage( - ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, + ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage, ) error { switch msg := clientMsg.(type) { diff --git a/modules/light-clients/09-localhost/types/client_state.go b/modules/light-clients/09-localhost/types/client_state.go index 728e4ec5f12..1ac05f3af64 100644 --- a/modules/light-clients/09-localhost/types/client_state.go +++ b/modules/light-clients/09-localhost/types/client_state.go @@ -142,6 +142,15 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") } +// VerifyClientMessage +// TODO: localhost client will be removed +func (cs ClientState) VerifyClientMessage( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, + _ exported.ClientMessage, +) error { + return nil +} + // VerifyClientState verifies that the localhost client state is stored locally func (cs ClientState) VerifyClientState( store sdk.KVStore, cdc codec.BinaryCodec, From 7a2e5954da7b557c8b07f8453f6bbe9a82883c4e Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 09:49:40 +0200 Subject: [PATCH 2/6] fix: legacy --- modules/core/02-client/legacy/v100/solomachine.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/02-client/legacy/v100/solomachine.go b/modules/core/02-client/legacy/v100/solomachine.go index 81457f8a328..9381cd1ef09 100644 --- a/modules/core/02-client/legacy/v100/solomachine.go +++ b/modules/core/02-client/legacy/v100/solomachine.go @@ -88,11 +88,11 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { panic("legacy solo machine is deprecated!") } -// VerifyClientMessage returns nil +// VerifyClientMessage panics func (cs *ClientState) VerifyClientMessage( _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, ) error { - return nil + panic("legacy solo machine is deprecated!") } // CheckHeaderAndUpdateState panics! From eba6524b6cef1039756589dc145c997bc286211e Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 10:54:36 +0200 Subject: [PATCH 3/6] remove todo + fix test --- .../07-tendermint/types/misbehaviour_handle_test.go | 6 +----- modules/light-clients/07-tendermint/types/update_test.go | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/light-clients/07-tendermint/types/misbehaviour_handle_test.go b/modules/light-clients/07-tendermint/types/misbehaviour_handle_test.go index 4657bae4d34..62af23b2707 100644 --- a/modules/light-clients/07-tendermint/types/misbehaviour_handle_test.go +++ b/modules/light-clients/07-tendermint/types/misbehaviour_handle_test.go @@ -775,15 +775,11 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { clientState := path.EndpointA.GetClientState() - // TODO: remove casting when `VerifyClientMessage` is apart of ClientState interface - tmClientState, ok := clientState.(*types.ClientState) - suite.Require().True(ok) - tc.malleate() clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - err = tmClientState.VerifyClientMessage(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec(), misbehaviour) + err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, misbehaviour) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/light-clients/07-tendermint/types/update_test.go b/modules/light-clients/07-tendermint/types/update_test.go index a6ae04c0897..3bc96b0fb93 100644 --- a/modules/light-clients/07-tendermint/types/update_test.go +++ b/modules/light-clients/07-tendermint/types/update_test.go @@ -382,10 +382,7 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { tc.malleate() - tmClientState, ok := clientState.(*types.ClientState) - suite.Require().True(ok) - - err = tmClientState.VerifyClientMessage(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec(), header) + err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, header) if tc.expPass { suite.Require().NoError(err) From 830299b192a51241d73c18c67dd8d957706dee7c Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 13:36:05 +0200 Subject: [PATCH 4/6] Update modules/core/exported/client.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/core/exported/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 5abc00d7806..c55b494b3fd 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -56,7 +56,7 @@ type ClientState interface { // Genesis function ExportMetadata(sdk.KVStore) []GenesisMetadata - // VerifyClientMessage verifies a Header or a Misbehaviour + // VerifyClientMessage verifies a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update. VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg ClientMessage) error // Update and Misbehaviour functions From df322e44307ebffac262d539d883e8c4c1352438 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 13:36:11 +0200 Subject: [PATCH 5/6] Update modules/core/02-client/legacy/v100/solomachine.go Co-authored-by: Damian Nolan --- modules/core/02-client/legacy/v100/solomachine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/02-client/legacy/v100/solomachine.go b/modules/core/02-client/legacy/v100/solomachine.go index 9381cd1ef09..b0e85878234 100644 --- a/modules/core/02-client/legacy/v100/solomachine.go +++ b/modules/core/02-client/legacy/v100/solomachine.go @@ -88,7 +88,7 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { panic("legacy solo machine is deprecated!") } -// VerifyClientMessage panics +// VerifyClientMessage panics! func (cs *ClientState) VerifyClientMessage( _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, ) error { From 41cc1a6164dd1ed621b9d1ac49330c36a30e701c Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 14:26:34 +0200 Subject: [PATCH 6/6] chore: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5651a3d7ebd..9d746fb889c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * [\#1186](https://github.com/cosmos/ibc-go/pull/1186/files) Removing `GetRoot` function from ConsensusState interface in `02-client`. `GetRoot` is unused by core IBC. +* (modules/core/02-client) [\#1196](https://github.com/cosmos/ibc-go/pull/1196) Adding VerifyClientMessage to ClientState interface. ### Features