diff --git a/CHANGELOG.md b/CHANGELOG.md index 385550813bf..34a61ca83da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (core/02-client, light-clients) [\#5806](https://github.com/cosmos/ibc-go/pull/5806) Decouple light client routing from their encoding structure. * (core/04-channel) [\#5991](https://github.com/cosmos/ibc-go/pull/5991) The client CLI `QueryLatestConsensusState` has been removed. * (light-clients/06-solomachine) [\#6037](https://github.com/cosmos/ibc-go/pull/6037) Remove `Initialize` function from `ClientState` and move logic to `Initialize` function of `LightClientModule`. +* (light-clients/06-solomachine) [\#6230](https://github.com/cosmos/ibc-go/pull/6230) Remove `GetTimestampAtHeight`, `Status` and `UpdateStateOnMisbehaviour` functions from `ClientState` and move logic to functions of `LightClientModule`. * (core/02-client) [\#6084](https://github.com/cosmos/ibc-go/pull/6084) Removed `stakingKeeper` as an argument to `NewKeeper` and replaced with a `ConsensusHost` implementation. * (testing) [\#6070](https://github.com/cosmos/ibc-go/pull/6070) Remove `AssertEventsLegacy` function. * (core) [\#6138](https://github.com/cosmos/ibc-go/pull/6138) Remove `Router` reference from IBC core keeper and use instead the router on the existing `PortKeeper` reference. diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index 0012683f295..b3e03747167 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -118,7 +118,7 @@ Please check also the [Light client developer guide](../03-light-clients/01-deve ### 06-solomachine -The `Initialize` function in `ClientState` has been removed and all its logic has been moved to the implementation of the `LightClientModule` interface `Initialize` function. +The `Initialize`, `Status`, `GetTimestampAtHeight` and `UpdateStateOnMisbehaviour` functions in `ClientState` have been removed and all their logic has been moved to functions of the `LightClientModule`. ### 07-tendermint diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 2b816a9dfb7..43d30fc4577 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -32,28 +32,6 @@ func (ClientState) ClientType() string { return exported.Solomachine } -// GetTimestampAtHeight returns the timestamp in nanoseconds of the consensus state at the given height. -func (cs ClientState) GetTimestampAtHeight( - _ sdk.Context, - clientStore storetypes.KVStore, - cdc codec.BinaryCodec, - height exported.Height, -) (uint64, error) { - return cs.ConsensusState.Timestamp, nil -} - -// Status returns the status of the solo machine client. -// The client may be: -// - Active: if frozen sequence is 0 -// - Frozen: otherwise solo machine is frozen -func (cs ClientState) Status(_ sdk.Context, _ storetypes.KVStore, _ codec.BinaryCodec) exported.Status { - if cs.IsFrozen { - return exported.Frozen - } - - return exported.Active -} - // Validate performs basic validation of the client state fields. func (cs ClientState) Validate() error { if cs.Sequence == 0 { diff --git a/modules/light-clients/06-solomachine/light_client_module.go b/modules/light-clients/06-solomachine/light_client_module.go index 35682f9b911..2e8f2d9fc99 100644 --- a/modules/light-clients/06-solomachine/light_client_module.go +++ b/modules/light-clients/06-solomachine/light_client_module.go @@ -95,7 +95,9 @@ func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string return clientState.CheckForMisbehaviour(ctx, l.cdc, clientStore, clientMsg) } -// UpdateStateOnMisbehaviour obtains the client state associated with the client identifier and calls into the clientState.UpdateStateOnMisbehaviour method. +// UpdateStateOnMisbehaviour updates state upon misbehaviour, freezing the ClientState. +// This method should only be called when misbehaviour is detected as it does not perform +// any misbehaviour checks. // // CONTRACT: clientID is validated in 02-client router, thus clientID is assumed here to have the format 06-solomachine-{n}. func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { @@ -105,7 +107,8 @@ func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID s panic(errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID)) } - clientState.UpdateStateOnMisbehaviour(ctx, l.cdc, clientStore, clientMsg) + clientState.IsFrozen = true + setClientState(clientStore, l.cdc, clientState) } // UpdateState obtains the client state associated with the client identifier and calls into the clientState.UpdateState method. @@ -164,7 +167,11 @@ func (l LightClientModule) VerifyNonMembership( return clientState.VerifyNonMembership(ctx, clientStore, l.cdc, height, delayTimePeriod, delayBlockPeriod, proof, path) } -// Status obtains the client state associated with the client identifier and calls into the clientState.Status method. +// Status returns the status of the solo machine client. +// The client may be: +// - Active: if `IsFrozen` is false. +// - Frozen: if `IsFrozen` is true. +// - Unknown: if the client state associated with the provided client identifier is not found. // // CONTRACT: clientID is validated in 02-client router, thus clientID is assumed here to have the format 06-solomachine-{n}. func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { @@ -174,7 +181,11 @@ func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Sta return exported.Unknown } - return clientState.Status(ctx, clientStore, l.cdc) + if clientState.IsFrozen { + return exported.Frozen + } + + return exported.Active } // LatestHeight returns the latest height for the client state for the given client identifier. @@ -193,7 +204,7 @@ func (l LightClientModule) LatestHeight(ctx sdk.Context, clientID string) export return clienttypes.NewHeight(0, clientState.Sequence) } -// TimestampAtHeight obtains the client state associated with the client identifier and calls into the clientState.GetTimestampAtHeight method. +// TimestampAtHeight obtains the client state associated with the client identifier and returns the timestamp in nanoseconds of the consensus state at the given height. // // CONTRACT: clientID is validated in 02-client router, thus clientID is assumed here to have the format 06-solomachine-{n}. func (l LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { @@ -203,7 +214,7 @@ func (l LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, h return 0, errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - return clientState.GetTimestampAtHeight(ctx, clientStore, l.cdc, height) + return clientState.ConsensusState.Timestamp, nil } // RecoverClient asserts that the substitute client is a solo machine client. It obtains the client state associated with the diff --git a/modules/light-clients/06-solomachine/update.go b/modules/light-clients/06-solomachine/update.go index d013031ba48..359bb118be4 100644 --- a/modules/light-clients/06-solomachine/update.go +++ b/modules/light-clients/06-solomachine/update.go @@ -99,11 +99,3 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client return []exported.Height{clienttypes.NewHeight(0, cs.Sequence)} } - -// 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 storetypes.KVStore, _ exported.ClientMessage) { - cs.IsFrozen = true - - setClientState(clientStore, cdc, &cs) -}