Skip to content

Commit

Permalink
chore(api!): move additional methods to light client module (#6230)
Browse files Browse the repository at this point in the history
* move methods to light client module

* remove status function from client state

* update changelog + migration docs

* godoc: update godoc of solomachine status method

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
3 people authored May 7, 2024
1 parent d34bf44 commit 7f274d5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/05-migrations/13-v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 0 additions & 22 deletions modules/light-clients/06-solomachine/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 17 additions & 6 deletions modules/light-clients/06-solomachine/light_client_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand All @@ -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) {
Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions modules/light-clients/06-solomachine/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 7f274d5

Please sign in to comment.