-
Notifications
You must be signed in to change notification settings - Fork 586
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
feat: adding 09-localhost loopback client module #3229
Merged
Merged
Changes from 51 commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
b996c6c
add EnableLocalhost to 03-connection
damiannolan b080ff9
adding godoc and temp comment
damiannolan ccfb9fb
dumping 09-localhost client state boilerplate
damiannolan 3416304
adding codec and app module basic
damiannolan 6b85352
rearrange code in client_state.go
damiannolan 8f13c75
adding conditional checks for localhost client
damiannolan a679368
adding localhost connection id const
damiannolan f5d0abd
updating client state for localhost
damiannolan 2dee015
adding abci call to update localhost client state
damiannolan 6c33d2e
add basic update method, update godocs
damiannolan da61d3a
Merge branch 'main' into 09-localhost
damiannolan 42cb750
Add sentinel localhost connection end to genesis state (#3040)
chatton bf26904
adding getClientStateAndKVStore to 03-connection verify.go to retriev…
damiannolan d1b0825
chore: adding 09-localhost to client InitGenesis (#3092)
damiannolan 72fcd65
adding initial localhost client testing (#3085)
damiannolan 3715153
Remove ProofHeight and Proof Validation in msg.ValidateBasic (#3061)
charleenfei badc331
updating errors returns in 09-localhost (#3105)
damiannolan 0e72157
remove chain id from localhost client (#3103)
damiannolan fdd332e
Merge branch 'main' into 09-localhost
damiannolan 40ca344
return error in 09-localhost VerifyClientMessage (#3115)
damiannolan c7d798b
disallow localhost client creation in 02-client (#3114)
damiannolan 9681f65
Merge branch 'main' into 09-localhost
damiannolan 4557d2d
Merge branch 'main' into 09-localhost
damiannolan 8e11eb1
Merge branch 'main' into 09-localhost
damiannolan 63111de
adding e2e tests for 09-localhost (#3119)
damiannolan 2edfbd2
e2e localhost test create new channel for existing ica account (#3146)
damiannolan d4e24d1
revert: unnecessary code change for localhost (#3170)
colin-axner 7568559
revert: unnecessary changes in connection handshake for localhost (#3…
colin-axner fe24586
adding localhost client ID checks to init and try validate basic (#3169)
damiannolan 69e1a51
Bumping localhost light client proto to v2 (#3168)
chatton 9352d83
fix typo
crodriguezvega 49f7065
Merge branch 'main' into 09-localhost
damiannolan c68f48b
Merge branch 'main' into 09-localhost
damiannolan 34a99fe
adding e2e upgrade test for v7.1 localhost (#3164)
damiannolan d7d43b3
localhost godocs and nits (#3199)
damiannolan 5d9639e
use sentinel proofs for localhost channels (#3195)
damiannolan 3bd6eab
chore: update AllowedClients godoc (#3200)
colin-axner 9fb39d3
chore: use single attribute for connection id in channel events (#3203)
colin-axner 5a955e0
fix: make proto-all (#3211)
colin-axner da5061f
chore: move localhost client and connection IDs to the exported packa…
colin-axner 610d812
chore: rename function (#3202)
colin-axner e50870d
update localhost upgrade handler to explicitly set allowed clients pa…
damiannolan b6cd296
correcting error - use client type, not client id in upgrade handler
damiannolan 53eea55
moving set connection to create localhost sentinel connection (#3209)
damiannolan c6beda3
Allow disabling of client type via allowed_clients param (#3196)
chatton dc9a7a7
Sync localhost branch with main (#3215)
chatton 5a9e184
removing unnecessary defensive checks in 07-tendermint (#3218)
damiannolan 868d0e4
register localhost types in ibc core, remove AppModuleBasic (#3220)
damiannolan 7303ce3
adding site docs for 09-localhost client (#3147)
damiannolan b1c4f4d
sync localhost with main to prep feat branch for PR (#3228)
damiannolan 46e1a42
Merge branch 'main' into 09-localhost
damiannolan 0ec6aad
chore: client state key nit (#3226)
crodriguezvega 5145187
indentation
crodriguezvega 9a41fe1
indentation
crodriguezvega 1e131c7
add 09-locahost to default list
5c0fc8b
update events.md
4bad6d2
Merge branch 'main' into 09-localhost
chatton 78cdc69
adding migration doc for v7.1 localhost client (#3210)
damiannolan 38f7d99
ran go mod tidy
chatton 12bd5b8
changed tendermint to cometbft
chatton b67680f
chore: add in-code comment
colin-axner 3290689
Merge branch 'main' into 09-localhost
colin-axner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- | ||
order: 3 | ||
--> | ||
|
||
# `ClientState` | ||
|
||
The 09-localhost `ClientState` maintains a single field used to track the latest sequence of the state machine i.e. the height of the blockchain. | ||
|
||
```go | ||
type ClientState struct { | ||
// the latest height of the blockchain | ||
LatestHeight clienttypes.Height | ||
} | ||
``` | ||
|
||
The 09-localhost `ClientState` is instantiated in the `InitGenesis` handler of the 02-client submodule in core IBC. | ||
It calls `CreateLocalhostClient`, declaring a new `ClientState` and initializing it with its own client prefixed store. | ||
|
||
```go | ||
func (k Keeper) CreateLocalhostClient(ctx sdk.Context) error { | ||
var clientState localhost.ClientState | ||
return clientState.Initialize(ctx, k.cdc, k.ClientStore(ctx, exported.LocalhostClientID), nil) | ||
} | ||
``` | ||
|
||
It is possible to disable the localhost client by removing the `09-localhost` entry from the `allowed_clients` list through governance. | ||
|
||
## Client updates | ||
|
||
The latest height is updated periodically through the ABCI [`BeginBlock`](https://docs.cosmos.network/v0.47/building-modules/beginblock-endblock) interface of the 02-client submodule in core IBC. | ||
|
||
[See `BeginBlocker` in abci.go.](https://github.com/cosmos/ibc-go/blob/09-localhost/modules/core/02-client/abci.go#L12) | ||
|
||
```go | ||
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { | ||
// ... | ||
|
||
if clientState, found := k.GetClientState(ctx, exported.Localhost); found { | ||
if k.GetClientStatus(ctx, clientState, exported.Localhost) == exported.Active { | ||
k.UpdateLocalhostClient(ctx, clientState) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The above calls into the the 09-localhost `UpdateState` method of the `ClientState` . | ||
It retrieves the current block height from the application context and sets the `LatestHeight` of the 09-localhost client. | ||
|
||
```go | ||
func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { | ||
height := clienttypes.GetSelfHeight(ctx) | ||
cs.LatestHeight = height | ||
|
||
clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, &cs)) | ||
|
||
return []exported.Height{height} | ||
} | ||
``` | ||
|
||
Note that the 09-localhost `ClientState` is not updated through the 02-client interface leveraged by conventional IBC light clients. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- | ||
order: 4 | ||
--> | ||
|
||
# Localhost connections | ||
|
||
The 09-localhost light client module integrates with core IBC through a single sentinel localhost connection. | ||
The sentinel `ConnectionEnd` is stored by default in the core IBC store. | ||
|
||
This enables channel handshakes to be initiated out of the box by supplying the localhost connection identifier (`connection-localhost`) in the `connectionHops` parameter of `MsgChannelOpenInit`. | ||
|
||
The `ConnectionEnd` is created and set in store via the `InitGenesis` handler of the 03-connection submodule in core IBC. | ||
The `ConnectionEnd` and its `Counterparty` both reference the `09-localhost` client identifier, and share the localhost connection identifier `connection-localhost`. | ||
|
||
```go | ||
// CreateSentinelLocalhostConnection creates and sets the sentinel localhost connection end in the IBC store. | ||
func (k Keeper) CreateSentinelLocalhostConnection(ctx sdk.Context) { | ||
counterparty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) | ||
connectionEnd := types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.ExportedVersionsToProto(types.GetCompatibleVersions()), 0) | ||
|
||
k.SetConnection(ctx, exported.LocalhostConnectionID, connectionEnd) | ||
} | ||
``` | ||
|
||
Note that connection handshakes are disallowed when using the `09-localhost` client type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- | ||
order: 2 | ||
--> | ||
|
||
# Integration | ||
|
||
The 09-localhost light client module registers codec types within the core IBC module. This differs from other light client module implementations which are expected to register codec types using the `AppModuleBasic` interface. | ||
|
||
The localhost client is added to the 02-client submodule param [`allowed_clients`](https://github.com/cosmos/ibc-go/blob/v7.0.0-rc0/proto/ibc/core/client/v1/client.proto#L102) by default in ibc-go. | ||
|
||
```go | ||
var ( | ||
// DefaultAllowedClients are the default clients for the AllowedClients parameter. | ||
DefaultAllowedClients = []string{exported.Solomachine, exported.Tendermint, exported.Localhost} | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- | ||
order: 1 | ||
--> | ||
|
||
# `09-localhost` | ||
|
||
## Overview | ||
|
||
Learn about the 09-localhost light client module. {synopsis} | ||
|
||
The 09-localhost light client module implements a localhost loopback client with the ability to send and receive IBC packets to and from the same state machine. | ||
|
||
### Context | ||
|
||
In a multichain environment, application developers will be used to developing cross-chain applications through IBC. From their point of view, whether or not they are interacting with multiple modules on the same chain or on different chains should not matter. The localhost client module enables a unified interface to interact with different applications on a single chain, using the familiar IBC application layer semantics. | ||
|
||
### Implementation | ||
|
||
There exists a [single sentinel `ClientState`](./client-state.md) instance with the client identifier `09-localhost`. | ||
|
||
To supplement this, a [sentinel `ConnectionEnd` is stored in core IBC](./connection.md) state with the connection identifier `connection-localhost`. This enables IBC applications to create channels directly on top of the sentinel connection which leverage the 09-localhost loopback functionality. | ||
|
||
[State verification](./state-verification.md) for channel state in handshakes or processing packets is reduced in complexity, the `09-localhost` client can simply compare bytes stored under the standardized key paths. | ||
|
||
### Localhost vs *regular* client | ||
|
||
The localhost client aims to provide a unified approach to interacting with applications on a single chain, as the IBC application layer provides for cross-chain interactions. To achieve this unified interface though, there are a number of differences under the hood compared to a 'regular' IBC client (excluding `06-solomachine` and `09-localhost` itself). | ||
|
||
The table below lists some important differences: | ||
|
||
| | Regular client | Localhost | | ||
| -------------------------------------------- | --------------------------------------------------------------------------- | --------- | | ||
| Number of clients | Many instances of a client *type* corresponding to different counterparties | A single sentinel client with the client identifier `09-localhost`| | ||
| Client creation | Relayer (permissionless) | `ClientState` is instantiated in the `InitGenesis` handler of the 02-client submodule in core IBC | | ||
| Client updates | Relayer submits headers using `MsgUpdateClient` | Latest height is updated periodically through the ABCI [`BeginBlock`](https://docs.cosmos.network/v0.47/building-modules/beginblock-endblock) interface of the 02-client submodule in core IBC | | ||
| Number of connections | Many connections, 1 (or more) per client | A single sentinel connection with the connection identifier `connection-localhost` | | ||
| Connection creation | Connection handshake, provided underlying client | Sentinel `ConnectionEnd` is created and set in store in the `InitGenesis` handler of the 03-connection submodule in core IBC | | ||
| Counterparty | Underlying client, representing another chain | Client with identifier `09-localhost` in same chain | | ||
| `VerifyMembership` and `VerifyNonMembership` | Performs proof verification using consensus state roots | Performs state verification using key-value lookups in the core IBC store | | ||
| Integration | Expected to register codec types using the `AppModuleBasic` interface | Registers codec types within the core IBC module | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
order: 5 | ||
--> | ||
|
||
# State verification | ||
|
||
The localhost client handles state verification through the `ClientState` interface methods `VerifyMembership` and `VerifyNonMembership` by performing read-only operations directly on the core IBC store. | ||
|
||
When verifying channel state in handshakes or processing packets the `09-localhost` client can simply compare bytes stored under the standardized key paths defined by [ICS-24](https://github.com/cosmos/ibc/tree/main/spec/core/ics-024-host-requirements). | ||
|
||
For existence proofs via `VerifyMembership` the 09-localhost client will retrieve the value stored under the provided key path and compare it against the value provided by the caller. In contrast, non-existence proofs via `VerifyNonMembership` assert the absence of a value at the provided key path. | ||
|
||
Relayers are expected to provide a sentinel proof when sending IBC messages. Submission of nil or empty proofs is disallowed in core IBC messaging. | ||
The 09-localhost light client module defines a `SentinelProof` as a single byte. Localhost client state verification will fail if the sentintel proof value is not provided. | ||
|
||
```go | ||
var SentinelProof = []byte{0x01} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Troubleshooting | ||
|
||
### Unauthorized client states | ||
|
||
If it is being reported that a client state is unauthorized, this is due to the client type not being present | ||
in the [`AllowedClients`](https://github.com/cosmos/ibc-go/blob/v6.0.0/modules/core/02-client/types/client.pb.go#L345) array. | ||
|
||
Unless the client type is present in this array, all usage of clients of this type will be prevented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Migrating from v7 to v7.1 | ||
|
||
This guide provides instructions for migrating to a new version of ibc-go. | ||
|
||
There are four sections based on the four potential user groups of this document: | ||
|
||
- [Chains](#chains) | ||
- [IBC Apps](#ibc-apps) | ||
- [Relayers](#relayers) | ||
- [IBC Light Clients](#ibc-light-clients) | ||
|
||
**Note:** ibc-go supports golang semantic versioning and therefore all imports must be updated on major version releases. | ||
|
||
## Chains | ||
|
||
- No relevant changes were made in this release. | ||
|
||
## IBC Apps | ||
|
||
- No relevant changes were made in this release. | ||
|
||
## Relayers | ||
|
||
The event attribute `packet_connection` (`connectiontypes.AttributeKeyConnection`) has been deprecated. | ||
Please use the `connection_id` attribute (`connectiontypes.AttributeKeyConnectionID`) which is emitted by all channel events. | ||
Only send packet, receive packet, write acknowledgement, and acknowledge packet events used `packet_connection` previously. | ||
|
||
## IBC Light Clients | ||
|
||
- No relevant changes were made in this release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ const ( | |
Rly = "rly" | ||
Hermes = "hermes" | ||
|
||
cosmosRelayerRepository = "ghcr.io/cosmos/relayer" | ||
cosmosRelayerUser = "100:1000" // docker run -it --rm --entrypoint echo ghcr.io/cosmos/relayer "$(id -u):$(id -g)" | ||
cosmosRelayerRepository = "damiannolan/rly" //"ghcr.io/cosmos/relayer" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
cosmosRelayerUser = "100:1000" // docker run -it --rm --entrypoint echo ghcr.io/cosmos/relayer "$(id -u):$(id -g)" | ||
) | ||
|
||
// Config holds configuration values for the relayer used in the tests. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3261