Skip to content

Commit

Permalink
feat: adding UpdateStateOnMisbehaviour to ClientState interface (#1198)
Browse files Browse the repository at this point in the history
* feat: adding UpdateStateOnMisbehaviour to ClientState interface

* Update modules/core/exported/client.go

Co-authored-by: colin axnér <[email protected]>

* fix: return values

* chore: changelog

Co-authored-by: colin axnér <[email protected]>
  • Loading branch information
seantking and colin-axner authored Mar 31, 2022
1 parent 18f1382 commit 3c7358b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions modules/core/02-client/legacy/v100/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions modules/core/exported/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions modules/light-clients/06-solomachine/types/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
6 changes: 2 additions & 4 deletions modules/light-clients/09-localhost/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c7358b

Please sign in to comment.