From 5d588b122b765ef222c9c876f1c01c9a21c0d724 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 09:48:14 +0200 Subject: [PATCH 1/4] feat: adding CheckForMisbehaviour to ClientState interface --- modules/core/02-client/legacy/v100/solomachine.go | 5 +++++ modules/core/exported/client.go | 4 +++- modules/light-clients/09-localhost/types/client_state.go | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/core/02-client/legacy/v100/solomachine.go b/modules/core/02-client/legacy/v100/solomachine.go index c9814439902..aac9250d3f5 100644 --- a/modules/core/02-client/legacy/v100/solomachine.go +++ b/modules/core/02-client/legacy/v100/solomachine.go @@ -88,6 +88,11 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { panic("legacy solo machine is deprecated!") } +// CheckForMisbehaviour detects duplicate height misbehaviour and BFT time violation misbehaviour +func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, msg exported.ClientMessage) bool { + panic("legacy solo machine is deprecated!") +} + // 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..5e32ecb3817 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -53,11 +53,13 @@ type ClientState interface { // Clients must return their status. Only Active clients are allowed to process packets. Status(ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec) Status + // Checks for evidence of a misbehaviour in Header or Misbehaviour type + CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, msg ClientMessage) bool + // Genesis function ExportMetadata(sdk.KVStore) []GenesisMetadata // 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/09-localhost/types/client_state.go b/modules/light-clients/09-localhost/types/client_state.go index 728e4ec5f12..addc9a40629 100644 --- a/modules/light-clients/09-localhost/types/client_state.go +++ b/modules/light-clients/09-localhost/types/client_state.go @@ -94,8 +94,8 @@ func (cs *ClientState) VerifyHeader( // CheckForMisbehaviour returns false. func (cs *ClientState) CheckForMisbehaviour( _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, -) (bool, error) { - return false, nil +) bool { + return false } // UpdateState updates the localhost client. It only needs access to the context From 1b21dcf44b9168cce7ee485ea9b8ba024318759f Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 09:51:13 +0200 Subject: [PATCH 2/4] fix: comment --- 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 aac9250d3f5..9a443ca7861 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!") } -// CheckForMisbehaviour detects duplicate height misbehaviour and BFT time violation misbehaviour +// CheckForMisbehaviour panics! func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, msg exported.ClientMessage) bool { panic("legacy solo machine is deprecated!") } From a5f3d9d6c2ec1e34fb5af2138b5afbe5d03067d2 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 31 Mar 2022 14:04:09 +0200 Subject: [PATCH 3/4] nit: fix todo --- modules/light-clients/07-tendermint/types/update_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/light-clients/07-tendermint/types/update_test.go b/modules/light-clients/07-tendermint/types/update_test.go index a6ae04c0897..08cdc7cc623 100644 --- a/modules/light-clients/07-tendermint/types/update_test.go +++ b/modules/light-clients/07-tendermint/types/update_test.go @@ -740,14 +740,9 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { tc.malleate() clientState := path.EndpointA.GetClientState() - - // TODO: remove casting when 'UpdateState' is an interface function. - tmClientState, ok := clientState.(*types.ClientState) - suite.Require().True(ok) - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - foundMisbehaviour := tmClientState.CheckForMisbehaviour( + foundMisbehaviour := clientState.CheckForMisbehaviour( suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, // pass in clientID prefixed clientStore From a1166d105479ef2a2dc115a355b41cf0117e2ba5 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 31 Mar 2022 14:07:35 +0200 Subject: [PATCH 4/4] chore: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bd1a631b45..a85ddb0ec4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#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. * (modules/core/02-client) [\#1170](https://github.com/cosmos/ibc-go/pull/1170) Updating `ClientUpdateProposal` to set client state in lightclient implementations `CheckSubstituteAndUpdateState` methods. +* (modules/core/02-client) [\#1197](https://github.com/cosmos/ibc-go/pull/1197) Adding `CheckForMisbehaviour` to `ClientState` interface. ### Features