From 82bf769d048dd262d4eba9b940ebc085400df676 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 10:04:05 +0200 Subject: [PATCH 1/4] feat: adding UpdateStateOnMisbehaviour to ClientState interface --- modules/core/02-client/legacy/v100/solomachine.go | 7 +++++++ modules/core/exported/client.go | 4 +++- modules/light-clients/06-solomachine/types/update.go | 6 ++---- modules/light-clients/09-localhost/types/client_state.go | 6 ++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/core/02-client/legacy/v100/solomachine.go b/modules/core/02-client/legacy/v100/solomachine.go index c9814439902..9f245672b49 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!") } +// UpdateStateOnMisbehaviour panics! +func (cs *ClientState) UpdateStateOnMisbehaviour( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, +) { + 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..7b406339b9d 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 + // UpdateStateOnMisbehaviour updates state upon misbehaviour + UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore) + // 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/06-solomachine/types/update.go b/modules/light-clients/06-solomachine/types/update.go index b6dfc44eac1..d6b17ca9853 100644 --- a/modules/light-clients/06-solomachine/types/update.go +++ b/modules/light-clients/06-solomachine/types/update.go @@ -26,7 +26,7 @@ func (cs ClientState) CheckHeaderAndUpdateState( foundMisbehaviour := cs.CheckForMisbehaviour(ctx, cdc, clientStore, msg) if foundMisbehaviour { - return cs.UpdateStateOnMisbehaviour(ctx, cdc, clientStore) + cs.UpdateStateOnMisbehaviour(ctx, cdc, clientStore) } return cs.UpdateState(ctx, cdc, clientStore, msg) @@ -135,10 +135,8 @@ func (cs ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ // UpdateStateOnMisbehaviour updates state upon misbehaviour. This method should only be called on misbehaviour // as it does not perform any misbehaviour checks. -func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore) (*ClientState, exported.ConsensusState, error) { +func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore) { cs.IsFrozen = true clientStore.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(cdc, &cs)) - - return &cs, cs.ConsensusState, nil } diff --git a/modules/light-clients/09-localhost/types/client_state.go b/modules/light-clients/09-localhost/types/client_state.go index 728e4ec5f12..4f2b83db92d 100644 --- a/modules/light-clients/09-localhost/types/client_state.go +++ b/modules/light-clients/09-localhost/types/client_state.go @@ -109,11 +109,9 @@ func (cs *ClientState) UpdateState( return cs, nil, nil } -// UpdateStateOnMisbehaviour returns an error (no misbehaviour case). +// UpdateStateOnMisbehaviour func (cs *ClientState) UpdateStateOnMisbehaviour( - _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, -) (*ClientState, error) { - return nil, sdkerrors.Wrapf(clienttypes.ErrUpdateClientFailed, "cannot update localhost client on misbehaviour") + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore) { } // CheckMisbehaviourAndUpdateState implements ClientState From e77ddcadbbfa289dfe784444bb8c383bc8409b7f Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 14:11:56 +0200 Subject: [PATCH 2/4] 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 7b406339b9d..e5d2387892c 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 - // UpdateStateOnMisbehaviour updates state upon misbehaviour + // UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore) // Update and Misbehaviour functions From d4a2e8b8a7a01d8f2c84c537e2c4a2c637b9ebcc Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 30 Mar 2022 14:15:35 +0200 Subject: [PATCH 3/4] fix: return values --- modules/light-clients/06-solomachine/types/update.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/light-clients/06-solomachine/types/update.go b/modules/light-clients/06-solomachine/types/update.go index d6b17ca9853..9379a622897 100644 --- a/modules/light-clients/06-solomachine/types/update.go +++ b/modules/light-clients/06-solomachine/types/update.go @@ -27,6 +27,7 @@ func (cs ClientState) CheckHeaderAndUpdateState( foundMisbehaviour := cs.CheckForMisbehaviour(ctx, cdc, clientStore, msg) if foundMisbehaviour { cs.UpdateStateOnMisbehaviour(ctx, cdc, clientStore) + return &cs, cs.ConsensusState, nil } return cs.UpdateState(ctx, cdc, clientStore, msg) From b36aada299e958a29ff2db226b56161724f973c2 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 31 Mar 2022 14:01:17 +0200 Subject: [PATCH 4/4] chore: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bd1a631b45..ba95828957a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,8 +45,10 @@ 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. +* (modules/core/02-client) [\#1198](https://github.com/cosmos/ibc-go/pull/1198) Adding UpdateStateOnMisbehaviour 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. + ### Features ### Bug Fixes