diff --git a/cairo-contracts/packages/clients/src/cometbft/client_state.cairo b/cairo-contracts/packages/clients/src/cometbft/client_state.cairo index ad7f32df..297381b5 100644 --- a/cairo-contracts/packages/clients/src/cometbft/client_state.cairo +++ b/cairo-contracts/packages/clients/src/cometbft/client_state.cairo @@ -2,12 +2,13 @@ use core::num::traits::Zero; use starknet_ibc_clients::cometbft::CometErrors; use starknet_ibc_core::client::{Height, HeightPartialOrd, Status, StatusTrait}; -#[derive(Clone, Debug, Drop, Hash, PartialEq, Serde, starknet::Store)] +#[derive(Clone, Debug, Drop, PartialEq, Serde, starknet::Store)] pub struct CometClientState { pub latest_height: Height, pub trusting_period: u64, pub unbonding_period: u64, pub status: Status, + pub chain_id: ByteArray, } #[generate_trait] diff --git a/cairo-contracts/packages/testkit/src/configs/cometbft.cairo b/cairo-contracts/packages/testkit/src/configs/cometbft.cairo index dcad5358..fdaa44e7 100644 --- a/cairo-contracts/packages/testkit/src/configs/cometbft.cairo +++ b/cairo-contracts/packages/testkit/src/configs/cometbft.cairo @@ -36,6 +36,7 @@ pub impl CometClientConfigImpl of CometClientConfigTrait { trusting_period: *self.trusting_period, unbonding_period: *self.unbonding_period, status: Status::Active, + chain_id: "dummy_chain", }; Serde::serialize(@client_state, ref serialized_client_state); diff --git a/light-client/Cargo.lock b/light-client/Cargo.lock index a07cb52c..557bc95f 100644 --- a/light-client/Cargo.lock +++ b/light-client/Cargo.lock @@ -1041,7 +1041,7 @@ checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "hermes-cosmos-encoding-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#c00f2440ac5e600eca68fc10cef1d45f9a378ed8" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-encoding-components", @@ -1055,7 +1055,7 @@ dependencies = [ [[package]] name = "hermes-encoding-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#c00f2440ac5e600eca68fc10cef1d45f9a378ed8" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", ] @@ -1063,7 +1063,7 @@ dependencies = [ [[package]] name = "hermes-protobuf-encoding-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#c00f2440ac5e600eca68fc10cef1d45f9a378ed8" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-encoding-components", diff --git a/light-client/ibc-client-starknet-types/src/client_state.rs b/light-client/ibc-client-starknet-types/src/client_state.rs index a5789fe3..1502c0f5 100644 --- a/light-client/ibc-client-starknet-types/src/client_state.rs +++ b/light-client/ibc-client-starknet-types/src/client_state.rs @@ -1,5 +1,6 @@ use cgp::prelude::*; use ibc_core::client::types::Height; +use ibc_core::host::types::identifiers::ChainId; pub const STARKNET_CLIENT_STATE_TYPE_URL: &str = "/StarknetClientState"; @@ -7,4 +8,5 @@ pub const STARKNET_CLIENT_STATE_TYPE_URL: &str = "/StarknetClientState"; #[derive(Clone, Debug, PartialEq, derive_more::From, HasField)] pub struct StarknetClientState { pub latest_height: Height, + pub chain_id: ChainId, } diff --git a/light-client/ibc-client-starknet-types/src/encoding/impls/client_state.rs b/light-client/ibc-client-starknet-types/src/encoding/impls/client_state.rs index 9318cdbe..7cf26632 100644 --- a/light-client/ibc-client-starknet-types/src/encoding/impls/client_state.rs +++ b/light-client/ibc-client-starknet-types/src/encoding/impls/client_state.rs @@ -1,5 +1,6 @@ use cgp::core::component::UseContext; use cgp::prelude::*; +use hermes_cosmos_encoding_components::impls::chain_id::EncodeChainIdField; use hermes_encoding_components::impls::encode_mut::combine::CombineEncoders; use hermes_encoding_components::impls::encode_mut::field::EncodeField; use hermes_encoding_components::impls::encode_mut::from::DecodeFrom; @@ -8,6 +9,7 @@ use hermes_protobuf_encoding_components::components::{MutDecoderComponent, MutEn use hermes_protobuf_encoding_components::impls::encode_mut::proto_field::decode_required::DecodeRequiredProtoField; use hermes_protobuf_encoding_components::impls::encode_mut::proto_field::encode::EncodeLengthDelimitedProtoField; use ibc_core::client::types::Height; +use ibc_core::host::types::identifiers::ChainId; use crate::StarknetClientState; @@ -21,22 +23,30 @@ delegate_components! { symbol!("latest_height"), EncodeLengthDelimitedProtoField<1, UseContext>, >, + EncodeField< + symbol!("chain_id"), + EncodeChainIdField<2>, + >, ]>, MutDecoderComponent: DecodeFrom< Self, CombineEncoders, + EncodeChainIdField<2>, ]> >, } } impl Transformer for EncodeStarknetClientState { - type From = Product![Height]; + type From = Product![Height, ChainId]; type To = StarknetClientState; - fn transform(product![latest_height]: Self::From) -> Self::To { - StarknetClientState { latest_height } + fn transform(product![latest_height, chain_id]: Self::From) -> Self::To { + StarknetClientState { + latest_height, + chain_id, + } } } diff --git a/light-client/ibc-client-starknet/src/client_state/execution.rs b/light-client/ibc-client-starknet/src/client_state/execution.rs index 54b328c9..03d71872 100644 --- a/light-client/ibc-client-starknet/src/client_state/execution.rs +++ b/light-client/ibc-client-starknet/src/client_state/execution.rs @@ -61,6 +61,7 @@ where let new_client_state = ClientStateType { latest_height: header.height, + chain_id: self.0.chain_id.clone(), } .into(); diff --git a/light-client/ibc-client-starknet/src/encoding/context.rs b/light-client/ibc-client-starknet/src/encoding/context.rs index 3a0fffa1..0684e53b 100644 --- a/light-client/ibc-client-starknet/src/encoding/context.rs +++ b/light-client/ibc-client-starknet/src/encoding/context.rs @@ -21,7 +21,7 @@ use ibc_client_starknet_types::{StarknetClientState, StarknetConsensusState}; use ibc_core::client::types::error::ClientError; use ibc_core::client::types::Height; use ibc_core::commitment_types::commitment::CommitmentRoot; -use ibc_core::host::types::error::DecodingError; +use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::primitives::{Timestamp, TimestampError}; use prost::DecodeError; @@ -175,6 +175,16 @@ impl ErrorRaiser } } +impl ErrorRaiser + for StarknetLightClientEncodingContextComponents +{ + fn raise_error(e: IdentifierError) -> ClientError { + ClientError::ClientSpecific { + description: format!("{e:?}"), + } + } +} + pub trait CanUseStarknetLightClientEncoding: Async + CanEncodeAndDecode diff --git a/nix/ibc-starknet-cw.nix b/nix/ibc-starknet-cw.nix index b08f1cc3..84dcc29c 100644 --- a/nix/ibc-starknet-cw.nix +++ b/nix/ibc-starknet-cw.nix @@ -10,7 +10,7 @@ let cargoLock = { lockFile = ./../light-client/Cargo.lock; outputHashes = { - "hermes-cosmos-encoding-components-0.1.0" = "sha256-OrNFK6UQjQ7cpj8HqPipG2YcqCV4/KjiV5oRLnoUUyY="; + "hermes-cosmos-encoding-components-0.1.0" = "sha256-Lkk0bxna5bhXuOifLgMqNHaJO65bFg7oMoLBTIOVhYE="; }; }; diff --git a/relayer/Cargo.lock b/relayer/Cargo.lock index 91a85cdb..6b2c3a48 100644 --- a/relayer/Cargo.lock +++ b/relayer/Cargo.lock @@ -1781,7 +1781,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermes-any-counterparty" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-cosmos-chain-components", @@ -1798,7 +1798,7 @@ dependencies = [ [[package]] name = "hermes-async-runtime-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "async-trait", "cgp", @@ -1821,7 +1821,7 @@ dependencies = [ [[package]] name = "hermes-chain-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-chain-type-components", @@ -1832,7 +1832,7 @@ dependencies = [ [[package]] name = "hermes-chain-type-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", ] @@ -1840,7 +1840,7 @@ dependencies = [ [[package]] name = "hermes-cli-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "clap", @@ -1858,7 +1858,7 @@ dependencies = [ [[package]] name = "hermes-comet-light-client-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-chain-type-components", @@ -1867,7 +1867,7 @@ dependencies = [ [[package]] name = "hermes-comet-light-client-context" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "eyre", @@ -1883,7 +1883,7 @@ dependencies = [ [[package]] name = "hermes-cosmos-chain-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "bech32 0.9.1", "bitcoin", @@ -1936,7 +1936,7 @@ dependencies = [ [[package]] name = "hermes-cosmos-encoding-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-encoding-components", @@ -1950,7 +1950,7 @@ dependencies = [ [[package]] name = "hermes-cosmos-integration-tests" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "eyre", @@ -1983,7 +1983,7 @@ dependencies = [ [[package]] name = "hermes-cosmos-relayer" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "dirs-next", @@ -2032,7 +2032,7 @@ dependencies = [ [[package]] name = "hermes-cosmos-test-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hdpath", @@ -2059,7 +2059,7 @@ dependencies = [ [[package]] name = "hermes-cosmos-wasm-relayer" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "eyre", @@ -2108,7 +2108,7 @@ dependencies = [ [[package]] name = "hermes-encoding-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", ] @@ -2116,7 +2116,7 @@ dependencies = [ [[package]] name = "hermes-error" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "eyre", @@ -2126,7 +2126,7 @@ dependencies = [ [[package]] name = "hermes-ibc-test-suite" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-logging-components", @@ -2137,7 +2137,7 @@ dependencies = [ [[package]] name = "hermes-logger" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-logging-components", @@ -2149,7 +2149,7 @@ dependencies = [ [[package]] name = "hermes-logging-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", ] @@ -2157,7 +2157,7 @@ dependencies = [ [[package]] name = "hermes-protobuf-encoding-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-encoding-components", @@ -2168,7 +2168,7 @@ dependencies = [ [[package]] name = "hermes-relayer-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-chain-components", @@ -2181,7 +2181,7 @@ dependencies = [ [[package]] name = "hermes-relayer-components-extra" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-chain-type-components", @@ -2193,7 +2193,7 @@ dependencies = [ [[package]] name = "hermes-runtime" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-async-runtime-components", @@ -2205,7 +2205,7 @@ dependencies = [ [[package]] name = "hermes-runtime-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", ] @@ -2388,7 +2388,7 @@ dependencies = [ [[package]] name = "hermes-test-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-chain-type-components", @@ -2400,7 +2400,7 @@ dependencies = [ [[package]] name = "hermes-tokio-runtime-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "futures", @@ -2414,7 +2414,7 @@ dependencies = [ [[package]] name = "hermes-tracing-logging-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-logging-components", @@ -2426,7 +2426,7 @@ dependencies = [ [[package]] name = "hermes-wasm-client-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-cosmos-chain-components", @@ -2445,7 +2445,7 @@ dependencies = [ [[package]] name = "hermes-wasm-encoding-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-cosmos-encoding-components", @@ -2459,7 +2459,7 @@ dependencies = [ [[package]] name = "hermes-wasm-test-components" version = "0.1.0" -source = "git+https://github.com/informalsystems/hermes-sdk.git#3e0c657816fc0a185c1726979cfaccd8c83e08d6" +source = "git+https://github.com/informalsystems/hermes-sdk.git#9dd5e3539cf60d645f13a9787b7c40d5b943fecc" dependencies = [ "cgp", "hermes-chain-type-components", diff --git a/relayer/crates/starknet-chain-components/src/components/encoding/cairo.rs b/relayer/crates/starknet-chain-components/src/components/encoding/cairo.rs index 8f30538d..0574f17d 100644 --- a/relayer/crates/starknet-chain-components/src/components/encoding/cairo.rs +++ b/relayer/crates/starknet-chain-components/src/components/encoding/cairo.rs @@ -10,7 +10,8 @@ use hermes_cairo_encoding_components::impls::encode_mut::vec::EncodeList; use hermes_cairo_encoding_components::strategy::ViaCairo; pub use hermes_encoding_components::traits::decode_mut::MutDecoderComponent; pub use hermes_encoding_components::traits::encode_mut::MutEncoderComponent; -use starknet::core::types::{Felt, U256}; +use ibc::core::host::types::identifiers::ChainId; +use starknet::core::types::U256; use crate::types::channel_id::{ ChannelCounterparty, ChannelEnd, ChannelId, ChannelState, EncodeChannelCounterparty, @@ -22,7 +23,7 @@ use crate::types::connection_id::{ EncodeConnectionCounterparty, EncodeConnectionEnd, EncodeConnectionId, EncodeConnectionState, }; use crate::types::cosmos::client_state::{ - ClientStatus, CometClientState, EncodeClientStatus, EncodeCometClientState, + ClientStatus, CometClientState, EncodeChainId, EncodeClientStatus, EncodeCometClientState, }; use crate::types::cosmos::consensus_state::{CometConsensusState, EncodeCometConsensusState}; use crate::types::cosmos::height::{EncodeHeight, Height}; @@ -124,6 +125,7 @@ delegate_components! { (ViaCairo, CometClientState): EncodeCometClientState, (ViaCairo, CometConsensusState): EncodeCometConsensusState, (ViaCairo, ClientId): EncodeClientId, + (ViaCairo, ChainId): EncodeChainId, (ViaCairo, ConnectionId): EncodeConnectionId, (ViaCairo, ConnectionCounterparty): EncodeConnectionCounterparty, (ViaCairo, ConnectionState): EncodeConnectionState, diff --git a/relayer/crates/starknet-chain-components/src/impls/messages/create_client.rs b/relayer/crates/starknet-chain-components/src/impls/messages/create_client.rs index a3ab8214..69d38ed9 100644 --- a/relayer/crates/starknet-chain-components/src/impls/messages/create_client.rs +++ b/relayer/crates/starknet-chain-components/src/impls/messages/create_client.rs @@ -64,6 +64,7 @@ where trusting_period: payload.client_state.trusting_period.as_secs(), unbonding_period: payload.client_state.unbonding_period.as_secs(), status: ClientStatus::Active, + chain_id: payload.client_state.chain_id, }; let consensus_state = CometConsensusState { diff --git a/relayer/crates/starknet-chain-components/src/impls/payload_builders/create_client.rs b/relayer/crates/starknet-chain-components/src/impls/payload_builders/create_client.rs index fdd78457..e440835a 100644 --- a/relayer/crates/starknet-chain-components/src/impls/payload_builders/create_client.rs +++ b/relayer/crates/starknet-chain-components/src/impls/payload_builders/create_client.rs @@ -1,4 +1,5 @@ use cgp::prelude::CanRaiseError; +use hermes_chain_components::traits::types::chain_id::HasChainId; use hermes_relayer_components::chain::traits::payload_builders::create_client::CreateClientPayloadBuilder; use hermes_relayer_components::chain::traits::queries::chain_status::CanQueryChainStatus; use hermes_relayer_components::chain::traits::types::create_client::{ @@ -6,6 +7,7 @@ use hermes_relayer_components::chain::traits::types::create_client::{ }; use ibc::core::client::types::error::ClientError; use ibc::core::client::types::Height; +use ibc::core::host::types::identifiers::ChainId; use ibc::primitives::Timestamp; use crate::types::client_state::{StarknetClientState, WasmStarknetClientState}; @@ -25,6 +27,7 @@ where CreateClientPayloadOptions = StarknetCreateClientPayloadOptions, > + HasCreateClientPayloadType + CanQueryChainStatus + + HasChainId + CanRaiseError, { async fn build_create_client_payload( @@ -39,6 +42,7 @@ where wasm_code_hash: create_client_options.wasm_code_hash.into(), client_state: StarknetClientState { latest_height: Height::new(0, 1).map_err(Chain::raise_error)?, + chain_id: chain.chain_id().clone(), }, }; diff --git a/relayer/crates/starknet-chain-components/src/impls/types/chain_id.rs b/relayer/crates/starknet-chain-components/src/impls/types/chain_id.rs index f4aad76e..8b2d890c 100644 --- a/relayer/crates/starknet-chain-components/src/impls/types/chain_id.rs +++ b/relayer/crates/starknet-chain-components/src/impls/types/chain_id.rs @@ -1,9 +1,9 @@ use cgp::core::Async; use hermes_relayer_components::chain::traits::types::chain_id::ProvideChainIdType; -use starknet::core::types::Felt; +use ibc::core::host::types::identifiers::ChainId; pub struct ProvideFeltChainId; impl ProvideChainIdType for ProvideFeltChainId { - type ChainId = Felt; + type ChainId = ChainId; } diff --git a/relayer/crates/starknet-chain-components/src/impls/types/client.rs b/relayer/crates/starknet-chain-components/src/impls/types/client.rs index d685abf9..385db5d0 100644 --- a/relayer/crates/starknet-chain-components/src/impls/types/client.rs +++ b/relayer/crates/starknet-chain-components/src/impls/types/client.rs @@ -7,7 +7,7 @@ use hermes_relayer_components::chain::traits::types::client_state::{ }; use hermes_relayer_components::chain::traits::types::consensus_state::ProvideConsensusStateType; use hermes_relayer_components::chain::traits::types::height::HasHeightType; -use starknet::core::types::Felt; +use ibc::core::host::types::identifiers::ChainId; use crate::types::client_state::WasmStarknetClientState; use crate::types::consensus_state::WasmStarknetConsensusState; @@ -31,7 +31,7 @@ impl ClientStateFieldsGetter where Chain: HasHeightType + HasClientStateType - + HasChainIdType, + + HasChainIdType, { fn client_state_latest_height(client_state: &WasmStarknetClientState) -> u64 { client_state.client_state.latest_height.revision_height() @@ -45,8 +45,7 @@ where false } - fn client_state_chain_id(_client_state: &WasmStarknetClientState) -> Chain::ChainId { - // FIXME: Return actual Starknet chain ID - Felt::ZERO + fn client_state_chain_id(client_state: &WasmStarknetClientState) -> Chain::ChainId { + client_state.client_state.chain_id.clone() } } diff --git a/relayer/crates/starknet-chain-components/src/types/cosmos/client_state.rs b/relayer/crates/starknet-chain-components/src/types/cosmos/client_state.rs index 004bd352..97e15133 100644 --- a/relayer/crates/starknet-chain-components/src/types/cosmos/client_state.rs +++ b/relayer/crates/starknet-chain-components/src/types/cosmos/client_state.rs @@ -13,6 +13,8 @@ use hermes_cosmos_chain_components::components::client::ClientStateTypeComponent use hermes_encoding_components::impls::encode_mut::combine::CombineEncoders; use hermes_encoding_components::impls::encode_mut::field::EncodeField; use hermes_encoding_components::impls::encode_mut::from::DecodeFrom; +use hermes_encoding_components::traits::decode_mut::{CanDecodeMut, MutDecoder}; +use hermes_encoding_components::traits::encode_mut::{CanEncodeMut, MutEncoder}; use hermes_encoding_components::traits::transform::{Transformer, TransformerRef}; use hermes_wasm_encoding_components::components::{MutDecoderComponent, MutEncoderComponent}; use ibc::clients::tendermint::types::{ @@ -31,6 +33,7 @@ pub struct CometClientState { pub trusting_period: u64, pub unbonding_period: u64, pub status: ClientStatus, + pub chain_id: ChainId, } #[derive(Debug)] @@ -75,9 +78,8 @@ where false // todo } - fn client_state_chain_id(_client_state: &CometClientState) -> ChainId { - // FIXME: Store Cosmos chain ID in CometClientState and return it here - ChainId::new("cosmos").unwrap() + fn client_state_chain_id(client_state: &CometClientState) -> ChainId { + client_state.chain_id.clone() } } @@ -89,6 +91,7 @@ delegate_components! { EncodeField, EncodeField, EncodeField, + EncodeField, ], >, MutDecoderComponent: DecodeFrom, @@ -96,17 +99,24 @@ delegate_components! { } impl Transformer for EncodeCometClientState { - type From = Product![Height, u64, u64, ClientStatus]; + type From = Product![Height, u64, u64, ClientStatus, ChainId]; type To = CometClientState; fn transform( - product![latest_height, trusting_period, unbonding_period, status]: Self::From, + product![ + latest_height, + trusting_period, + unbonding_period, + status, + chain_id + ]: Self::From, ) -> CometClientState { CometClientState { latest_height, trusting_period, unbonding_period, status, + chain_id, } } } @@ -149,10 +159,8 @@ impl Transformer for EncodeClientStatus { impl From for Any { fn from(client_state: CometClientState) -> Self { - let chain_revision_number = client_state.latest_height.revision_number; - IbcCometClientState::new( - ChainId::new(&format!("cosmos-{}", chain_revision_number)).expect("no error"), + client_state.chain_id, TrustThreshold::ONE_THIRD, Duration::from_secs(client_state.trusting_period), Duration::from_secs(client_state.unbonding_period), @@ -173,3 +181,33 @@ impl From for Any { .into() } } + +pub struct EncodeChainId; + +impl MutEncoder for EncodeChainId +where + Encoding: CanEncodeMut, +{ + fn encode_mut( + encoding: &Encoding, + chain_id: &ChainId, + buffer: &mut Encoding::EncodeBuffer, + ) -> Result<(), Encoding::Error> { + let chain_id_str = chain_id.as_str().to_string(); + encoding.encode_mut(&chain_id_str, buffer)?; + Ok(()) + } +} + +impl MutDecoder for EncodeChainId +where + Encoding: CanDecodeMut + CanRaiseError<&'static str>, +{ + fn decode_mut<'a>( + encoding: &Encoding, + buffer: &mut Encoding::DecodeBuffer<'a>, + ) -> Result { + let chain_id_str = encoding.decode_mut(buffer)?; + ChainId::new(&chain_id_str).map_err(|_| Encoding::raise_error("invalid chain id")) + } +} diff --git a/relayer/crates/starknet-chain-context/src/contexts/chain.rs b/relayer/crates/starknet-chain-context/src/contexts/chain.rs index 31213d86..10d987d3 100644 --- a/relayer/crates/starknet-chain-context/src/contexts/chain.rs +++ b/relayer/crates/starknet-chain-context/src/contexts/chain.rs @@ -6,6 +6,7 @@ use cgp::core::field::impls::use_field::WithField; use cgp::core::types::impls::WithType; use cgp::prelude::*; use hermes_cairo_encoding_components::types::as_felt::AsFelt; +use hermes_chain_type_components::traits::fields::chain_id::HasChainId; use hermes_chain_type_components::traits::types::commitment_proof::HasCommitmentProofType; use hermes_chain_type_components::traits::types::height::HasHeightType; use hermes_chain_type_components::traits::types::message_response::HasMessageResponseType; @@ -154,7 +155,7 @@ use hermes_test_components::chain::traits::types::address::HasAddressType; use hermes_test_components::chain::traits::types::memo::HasMemoType; use hermes_test_components::chain::traits::types::wallet::WalletTypeComponent; use ibc::core::channel::types::packet::Packet; -use ibc::core::host::types::identifiers::{PortId as IbcPortId, Sequence}; +use ibc::core::host::types::identifiers::{ChainId, PortId as IbcPortId, Sequence}; use starknet::accounts::SingleOwnerAccount; use starknet::core::types::Felt; use starknet::providers::jsonrpc::HttpTransport; @@ -168,7 +169,7 @@ use crate::impls::error::HandleStarknetChainError; #[derive(HasField, Clone)] pub struct StarknetChain { pub runtime: HermesRuntime, - pub chain_id: Felt, + pub chain_id: ChainId, pub rpc_client: Arc>, pub account: SingleOwnerAccount>, LocalWallet>, pub ibc_client_contract_address: Option, @@ -249,7 +250,7 @@ impl JsonRpcClientGetter for StarknetChainContextComponents { } impl ChainIdGetter for StarknetChainContextComponents { - fn chain_id(chain: &StarknetChain) -> &Felt { + fn chain_id(chain: &StarknetChain) -> &ChainId { &chain.chain_id } } @@ -264,6 +265,7 @@ pub trait CanUseStarknetChain: + HasDefaultEncoding + HasCommitmentProofType + HasAddressType
+ + HasChainId + HasSelectorType + HasBlobType> + HasCommitmentPrefixType> @@ -375,6 +377,7 @@ pub trait CanUseCosmosChainWithStarknet: HasClientStateType + HasUpdateClientPayloadType + HasInitConnectionOptionsType + + HasChainId + HasCounterpartyMessageHeight + HasClientStateFields + CanQueryClientState diff --git a/relayer/crates/starknet-chain-context/src/contexts/encoding/protobuf.rs b/relayer/crates/starknet-chain-context/src/contexts/encoding/protobuf.rs index 913ad4c8..8cea847c 100644 --- a/relayer/crates/starknet-chain-context/src/contexts/encoding/protobuf.rs +++ b/relayer/crates/starknet-chain-context/src/contexts/encoding/protobuf.rs @@ -3,6 +3,7 @@ use cgp::core::error::{ErrorRaiserComponent, ErrorTypeComponent}; use cgp::prelude::*; use hermes_encoding_components::traits::convert::CanConvertBothWays; use hermes_encoding_components::traits::encode_and_decode::CanEncodeAndDecode; +use hermes_encoding_components::traits::encode_and_decode_mut::CanEncodeAndDecodeMut; use hermes_error::impls::ProvideHermesError; use hermes_protobuf_encoding_components::types::any::Any; use hermes_protobuf_encoding_components::types::strategy::{ViaAny, ViaProtobuf}; @@ -16,6 +17,8 @@ use hermes_starknet_chain_components::types::consensus_state::{ use hermes_wasm_encoding_components::types::client_state::WasmClientState; use hermes_wasm_encoding_components::types::consensus_state::WasmConsensusState; use ibc::clients::wasm_types::client_message::ClientMessage; +use ibc::core::commitment_types::commitment::CommitmentRoot; +use ibc::primitives::Timestamp; use ibc_client_starknet_types::header::StarknetHeader; use crate::impls::error::HandleStarknetChainError; @@ -58,6 +61,8 @@ pub trait CanUseStarknetProtobufEncoding: + CanConvertBothWays + CanConvertBothWays + CanConvertBothWays + + CanEncodeAndDecodeMut + + CanEncodeAndDecodeMut { } diff --git a/relayer/crates/starknet-chain-context/src/impls/error.rs b/relayer/crates/starknet-chain-context/src/impls/error.rs index a897e1b0..ad75e522 100644 --- a/relayer/crates/starknet-chain-context/src/impls/error.rs +++ b/relayer/crates/starknet-chain-context/src/impls/error.rs @@ -39,6 +39,7 @@ use hermes_starknet_chain_components::impls::queries::contract_address::Contract use hermes_starknet_chain_components::impls::send_message::UnexpectedTransactionTraceType; use hermes_starknet_chain_components::types::event::UnknownEvent; use ibc::core::client::types::error::ClientError; +use ibc::core::host::types::error::IdentifierError; use ibc::primitives::TimestampError; use prost::{DecodeError, EncodeError}; use starknet::accounts::{single_owner, AccountError}; @@ -70,6 +71,7 @@ delegate_components! { DecodeError, ClientError, TimestampError, + IdentifierError, ComputeClassHashError, StarknetSierraCompilationError, ]: ReportError, diff --git a/relayer/crates/starknet-cli/src/contexts/app.rs b/relayer/crates/starknet-cli/src/contexts/app.rs index 1a7a8906..807d9975 100644 --- a/relayer/crates/starknet-cli/src/contexts/app.rs +++ b/relayer/crates/starknet-cli/src/contexts/app.rs @@ -64,7 +64,7 @@ use hermes_starknet_integration_tests::contexts::chain_driver::StarknetChainDriv use hermes_starknet_relayer::contexts::builder::StarknetBuilder; use hermes_test_components::chain_driver::traits::config::ConfigUpdater; use ibc::core::client::types::Height; -use ibc::core::host::types::identifiers::ClientId as CosmosClientId; +use ibc::core::host::types::identifiers::{ChainId, ClientId as CosmosClientId}; use starknet::core::types::Felt; use toml::to_string_pretty; @@ -137,22 +137,22 @@ delegate_components! { delegate_components! { StarknetParserComponents { - (QueryClientStateArgs, symbol!("chain_id")): ParseFromString, + (QueryClientStateArgs, symbol!("chain_id")): ParseFromString, (QueryClientStateArgs, symbol!("client_id")): ParseFromString, (QueryClientStateArgs, symbol!("height")): ParseFromOptionalString, - (QueryConsensusStateArgs, symbol!("chain_id")): ParseFromString, + (QueryConsensusStateArgs, symbol!("chain_id")): ParseFromString, (QueryConsensusStateArgs, symbol!("client_id")): ParseFromString, (QueryConsensusStateArgs, symbol!("query_height")): ParseFromOptionalString, (QueryConsensusStateArgs, symbol!("consensus_height")): ParseFromOptionalString, - (QueryChainStatusArgs, symbol!("chain_id")): ParseFromString, + (QueryChainStatusArgs, symbol!("chain_id")): ParseFromString, - (QueryBalanceArgs, symbol!("chain_id")): ParseFromString, + (QueryBalanceArgs, symbol!("chain_id")): ParseFromString, (QueryBalanceArgs, symbol!("address")): ParseFromString, (QueryBalanceArgs, symbol!("denom")): ParseFromString, - (UpdateClientArgs, symbol!("host_chain_id")): ParseFromString, + (UpdateClientArgs, symbol!("host_chain_id")): ParseFromString, (UpdateClientArgs, symbol!("client_id")): ParseFromString, (UpdateClientArgs, symbol!("counterparty_client_id")): ParseFromString, (UpdateClientArgs, symbol!("target_height")): ParseFromOptionalString, diff --git a/relayer/crates/starknet-integration-tests/src/contexts/bootstrap.rs b/relayer/crates/starknet-integration-tests/src/contexts/bootstrap.rs index da6566e1..010252e1 100644 --- a/relayer/crates/starknet-integration-tests/src/contexts/bootstrap.rs +++ b/relayer/crates/starknet-integration-tests/src/contexts/bootstrap.rs @@ -138,7 +138,7 @@ impl ChainDriverBuilder for StarknetBootstrapComponents { let chain = StarknetChain { runtime: runtime.clone(), - chain_id, + chain_id: chain_id.to_string().parse()?, rpc_client, account, ibc_client_contract_address: None, diff --git a/relayer/crates/starknet-relayer/src/build/components/relay/build.rs b/relayer/crates/starknet-relayer/src/build/components/relay/build.rs index 5d49d497..2e02cc33 100644 --- a/relayer/crates/starknet-relayer/src/build/components/relay/build.rs +++ b/relayer/crates/starknet-relayer/src/build/components/relay/build.rs @@ -5,7 +5,6 @@ use hermes_relayer_components::build::traits::builders::relay_builder::RelayBuil use hermes_relayer_components::multi::types::index::Index; use hermes_starknet_chain_components::types::client_id::ClientId as StarknetClientId; use ibc::core::host::types::identifiers::{ChainId, ClientId as CosmosClientId}; -use starknet::core::types::Felt; use crate::contexts::builder::{StarknetBuildComponents, StarknetBuilder}; use crate::contexts::starknet_to_cosmos_relay::StarknetToCosmosRelay; @@ -14,7 +13,7 @@ impl RelayBuilder, Index<1>> for StarknetBuildComponen async fn build_relay( build: &StarknetBuilder, _index: PhantomData<(Index<0>, Index<1>)>, - _src_chain_id: &Felt, + _src_chain_id: &ChainId, dst_chain_id: &ChainId, src_client_id: &StarknetClientId, dst_client_id: &CosmosClientId, diff --git a/relayer/crates/starknet-relayer/src/contexts/builder.rs b/relayer/crates/starknet-relayer/src/contexts/builder.rs index 20f889a8..b5fe66dc 100644 --- a/relayer/crates/starknet-relayer/src/contexts/builder.rs +++ b/relayer/crates/starknet-relayer/src/contexts/builder.rs @@ -26,7 +26,6 @@ use hermes_starknet_chain_context::contexts::chain::StarknetChain; use hermes_starknet_chain_context::impls::error::HandleStarknetChainError; use ibc::core::host::types::identifiers::{ChainId, ClientId as CosmosClientId}; use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount}; -use starknet::core::types::Felt; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider}; use starknet::signers::{LocalWallet, SigningKey}; @@ -89,7 +88,7 @@ impl ChainBuilder> for StarknetBuildComponents { async fn build_chain( build: &StarknetBuilder, _index: PhantomData>, - _chain_id: &Felt, + _chain_id: &ChainId, ) -> Result { build.build_chain().await } @@ -143,7 +142,7 @@ impl StarknetBuilder { let context = StarknetChain { runtime: self.runtime.clone(), - chain_id, + chain_id: chain_id.to_string().parse()?, rpc_client, account, ibc_client_contract_address: None,