cosmos / ibc-rs

Rust implementation of the Inter-Blockchain Communication (IBC) protocol.
Apache License 2.0
181 stars 73 forks source link

support ICS008 wrapper type for host client and consensus state #1237

Closed rnbguy closed 2 weeks ago

rnbguy commented 1 month ago

Feature Summary

Now that ibc-go comes with wasm-08, client state of an ibc-rs chain maybe stored as wasm wrapped format in wasm-08 enabled chain.

So when MsgConnectionOpenTry or MsgConnectionOpenAck is received at ibc-rs, it should expect two cases:

  1. normal client state. e.g., the chain is using vanilla tendermint engine, so the counterparty ibc-go chain uses ibc-go implementation of ics07.
  2. wasm wrapped client state. e.g., the chain is using a custom consensus, so the counterparty ibc-go chain uses wasm client via wasm-08

Proposal

We need to introduce an enum:

pub enum HostClientState<T> {
    Native {
        state: T,
    },
    Wasm {
        state: T,
        checksum: Vec<u8>,
        latest_height: Height,
    },
}

Then, use HosClientState<Ctx::HostClientState> in the following places:

https://github.com/cosmos/ibc-rs/blob/2378cd4ba45094b8ed856ff7dba5f1d0882f59ae/ibc-core/ics03-connection/src/handler/conn_open_ack.rs#L52

https://github.com/cosmos/ibc-rs/blob/2378cd4ba45094b8ed856ff7dba5f1d0882f59ae/ibc-core/ics03-connection/src/handler/conn_open_try.rs#L42

rnbguy commented 1 month ago

Maybe we can add another generic associated type to ValidationContext:

https://github.com/cosmos/ibc-rs/blob/2378cd4ba45094b8ed856ff7dba5f1d0882f59ae/ibc-core/ics24-host/src/context.rs#L28-L31

    type HostClientStateAtCounterparty<V>: Into<V> + TryFrom<Any> where V: TryFrom<Any>;

And, later, we use it as::

Ctx::HostClientStateAtCounterparty<Ctx::HostClientState>::try_from(
    msg.client_state_of_a_on_b.clone()
  )
  .map_err(Into::into)?
  .into(); 

This way, we allow the crate users to build their own custom host client wrapper.

rnbguy commented 3 weeks ago

Looks like, the similar is required for host consensus state. In the following, we need to wrap the consensus state in wasm consensus state and then check for proofs.

https://github.com/cosmos/ibc-rs/blob/2378cd4ba45094b8ed856ff7dba5f1d0882f59ae/ibc-core/ics03-connection/src/handler/conn_open_ack.rs#L119-L120

https://github.com/cosmos/ibc-rs/blob/2378cd4ba45094b8ed856ff7dba5f1d0882f59ae/ibc-core/ics03-connection/src/handler/conn_open_try.rs#L115-L116