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

Adding docs for client state interface #2886

Merged
66 changes: 65 additions & 1 deletion docs/ibc/light-clients/client-state.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
<!--
order: 2
-->
-->

# Implementing the `ClientState` interface

Learn how to implement the [`Client State`](https://github.com/cosmos/ibc-go/blob/v6.0.0-rc1/modules/core/exported/client.go#L40) interface.
Copy link
Member

Choose a reason for hiding this comment

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

I know we usually want to link to a specific tag but linking to v6 seems weird to me because its the old interface. I guess we can update all links when there is a v7 tag available.

Suggested change
Learn how to implement the [`Client State`](https://github.com/cosmos/ibc-go/blob/v6.0.0-rc1/modules/core/exported/client.go#L40) interface.
Learn how to implement the [`ClientState`](https://github.com/cosmos/ibc-go/blob/v6.0.0-rc1/modules/core/exported/client.go#L40) interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think we can update this in the next release.


## `ClientType` method

`ClientType` should return a unique string identifier of the light client. This will be used when generating a client identifier.
The format is created as follows: `ClientTypes-{N}` where `{N}` is the unique global nonce associated with a specific client.
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

## `GetLatestHeight` method

`GetLatestHeight` should return the latest block height that the client state represents. .
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

## `Validate` method

`Validate` should validate every client state field and should return an error if any value is invalid. The light client
implementor is in charge of determining which checks are required. See the [tendermint light client implementation](https://github.com/cosmos/ibc-go/blob/v6.0.0-rc1/modules/light-clients/07-tendermint/types/client_state.go#L101)
as a reference.

## `Status` method

`Status` must return the status of the client. Only `Active` clients are allowed to process packets. All
possible Status types can be found [here](https://github.com/cosmos/ibc-go/blob/v6.0.0-rc1/modules/core/exported/client.go#L26-L36).

## `ZeroCustomFields` method

`ZeroCustomFields` should return a copy of the light client with all client customizable fields with their zero value. It should not mutate the fields of the light client.
This method is used when [scheduling upgrades](https://github.com/cosmos/ibc-go/blob/v6.0.0-rc1/modules/core/02-client/keeper/proposal.go#L89). Upgrades are used to upgrade chain specific fields such as chainID and the unbonding period.
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
For more information about client upgrades see [the developer guide](../upgrades/developer-guide.md).

## `GetTimestampAtHeight` method

`GetTimestampAtHeight` must return the timestamp for the consensus state associated with the provided height.
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
This value is used to facilitate timeouts by checking that a timeout on a packet has passed or not.
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

## `Initialize` method

Clients must validate the initial consensus state, and may store any client-specific metadata necessary
for correct light client operations in the `Initialize` function.
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

`Initialize` gets called when a [client is created](https://github.com/cosmos/ibc-go/blob/main/modules/core/02-client/keeper/client.go#L32).

## `VerifyMembership` method

`VerifyMembership` must verify the existence of a value at a given CommitmentPath at the specified height. For more information about membership proofs
see [the proof docs](./proofs.md).

## `VerifyNonMembership` method

`VerifyNonMembership` must verify the absence of a value at a given CommitmentPath at a specified height. For more information about non membership proofs
see [the proof docs](./proofs.md).

## `VerifyClientMessage` method

VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update.
It must handle each type of ClientMessage appropriately. Calls to CheckForMisbehaviour, UpdateState, and UpdateStateOnMisbehaviour
will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned
if the ClientMessage fails to verify.

## `CheckForMisbehaviour` method

Checks for evidence of a misbehaviour in Header or Misbehaviour type. It assumes the ClientMessage
has already been verified.