From 7ed7171d8ab43a0ada2fed22d43c4bef84084313 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 31 Mar 2022 14:08:26 +0200 Subject: [PATCH] feat: adding UpdateStateOnMisbehaviour to ClientState interface (#1198) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: adding UpdateStateOnMisbehaviour to ClientState interface * Update modules/core/exported/client.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * fix: return values * chore: changelog Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- CHANGELOG.md | 2 ++ modules/core/02-client/legacy/v100/solomachine.go | 7 +++++++ modules/core/exported/client.go | 3 +++ modules/light-clients/06-solomachine/types/update.go | 7 +++---- modules/light-clients/09-localhost/types/client_state.go | 6 ++---- 5 files changed, 17 insertions(+), 8 deletions(-) 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 diff --git a/modules/core/02-client/legacy/v100/solomachine.go b/modules/core/02-client/legacy/v100/solomachine.go index 9888814dee4..24744c3fcbd 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!") +} + // VerifyClientMessage panics! func (cs *ClientState) VerifyClientMessage( _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 00ebc1e418c..8bc64f9106c 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -56,6 +56,9 @@ type ClientState interface { // Genesis function ExportMetadata(sdk.KVStore) []GenesisMetadata + // 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) + // 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 diff --git a/modules/light-clients/06-solomachine/types/update.go b/modules/light-clients/06-solomachine/types/update.go index b6dfc44eac1..9379a622897 100644 --- a/modules/light-clients/06-solomachine/types/update.go +++ b/modules/light-clients/06-solomachine/types/update.go @@ -26,7 +26,8 @@ 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, cs.ConsensusState, nil } return cs.UpdateState(ctx, cdc, clientStore, msg) @@ -135,10 +136,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 1ac05f3af64..02031551f27 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