Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api!): move additional methods to light client module #6230

Merged
merged 7 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
Copy link
Contributor

@coderabbitai coderabbitai bot May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the URL is properly formatted as a Markdown link.

- * (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`.
+ * (light-clients/06-solomachine) [[\#6230](https://github.com/cosmos/ibc-go/pull/6230)](https://github.com/cosmos/ibc-go/pull/6230) Remove `GetTimestampAtHeight`, `Status` and `UpdateStateOnMisbehaviour` functions from `ClientState` and move logic to functions of `LightClientModule`.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* (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`.
* (light-clients/06-solomachine) [[#6230](https://github.com/cosmos/ibc-go/pull/6230)](https://github.com/cosmos/ibc-go/pull/6230) Remove `GetTimestampAtHeight`, `Status` and `UpdateStateOnMisbehaviour` functions from `ClientState` and move logic to functions of `LightClientModule`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of the changelogs follow the existing format

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damiannolan, thank you for your input. We'll keep the changelog format consistent with the existing entries as per your guidance. If there's anything else you need, feel free to let me know!

* (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)
}
Loading