From 53ec78105470e0f15556cf0549edc514c5e41690 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 16:17:38 +0100 Subject: [PATCH 01/13] new ibc v2 paths --- ibc-eureka-core/ics24-host/types/src/path.rs | 402 +++++++++++++++++++ 1 file changed, 402 insertions(+) diff --git a/ibc-eureka-core/ics24-host/types/src/path.rs b/ibc-eureka-core/ics24-host/types/src/path.rs index 750fb3bf6..5e5a15c23 100644 --- a/ibc-eureka-core/ics24-host/types/src/path.rs +++ b/ibc-eureka-core/ics24-host/types/src/path.rs @@ -15,6 +15,12 @@ pub const NEXT_CLIENT_SEQUENCE: &str = "nextClientSequence"; pub const NEXT_CONNECTION_SEQUENCE: &str = "nextConnectionSequence"; pub const NEXT_CHANNEL_SEQUENCE: &str = "nextChannelSequence"; +pub const EUREKA: &str = "eureka"; +pub const SOURCE_CLIENT_ON_TARGET: &str = "sourceClientOnTarget"; +pub const SOURCE_PREFIX: &str = "sourcePrefix"; +pub const TARGET_CLIENT_ON_SOURCE: &str = "targetClientOnSource"; +pub const TARGET_PREFIX: &str = "targetPrefix"; + pub const CLIENT_PREFIX: &str = "clients"; pub const CLIENT_STATE: &str = "clientState"; pub const CONSENSUS_STATE_PREFIX: &str = "consensusStates"; @@ -98,6 +104,12 @@ pub enum Path { Commitment(CommitmentPath), Ack(AckPath), Receipt(ReceiptPath), + SeqSendV2(SeqSendPathV2), + SeqRecvV2(SeqRecvPathV2), + SeqAckV2(SeqAckPathV2), + CommitmentV2(CommitmentPathV2), + AckV2(AckPathV2), + ReceiptV2(ReceiptPathV2), UpgradeClientState(UpgradeClientStatePath), UpgradeConsensusState(UpgradeConsensusStatePath), } @@ -488,6 +500,46 @@ impl SeqSendPath { } } +#[cfg_attr( + feature = "parity-scale-codec", + derive( + parity_scale_codec::Encode, + parity_scale_codec::Decode, + scale_info::TypeInfo + ) +)] +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] +#[display( + fmt = "{EUREKA}/{NEXT_SEQ_SEND_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}" +)] +pub struct SeqSendPathV2 { + pub source_client_on_target: ClientId, + pub source_prefix: String, + pub target_client_on_source: ClientId, + pub target_prefix: String, +} + +impl SeqSendPathV2 { + pub fn new( + source_client_on_target: ClientId, + source_prefix: String, + target_client_on_source: ClientId, + target_prefix: String, + ) -> Self { + Self { + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + } + } +} + #[cfg_attr( feature = "parity-scale-codec", derive( @@ -511,6 +563,46 @@ impl SeqRecvPath { } } +#[cfg_attr( + feature = "parity-scale-codec", + derive( + parity_scale_codec::Encode, + parity_scale_codec::Decode, + scale_info::TypeInfo + ) +)] +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] +#[display( + fmt = "{EUREKA}/{NEXT_SEQ_RECV_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}" +)] +pub struct SeqRecvPathV2 { + pub source_client_on_target: ClientId, + pub source_prefix: String, + pub target_client_on_source: ClientId, + pub target_prefix: String, +} + +impl SeqRecvPathV2 { + pub fn new( + source_client_on_target: ClientId, + source_prefix: String, + target_client_on_source: ClientId, + target_prefix: String, + ) -> Self { + Self { + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + } + } +} + #[cfg_attr( feature = "parity-scale-codec", derive( @@ -534,6 +626,46 @@ impl SeqAckPath { } } +#[cfg_attr( + feature = "parity-scale-codec", + derive( + parity_scale_codec::Encode, + parity_scale_codec::Decode, + scale_info::TypeInfo + ) +)] +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] +#[display( + fmt = "{EUREKA}/{NEXT_SEQ_ACK_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}" +)] +pub struct SeqAckPathV2 { + pub source_client_on_target: ClientId, + pub source_prefix: String, + pub target_client_on_source: ClientId, + pub target_prefix: String, +} + +impl SeqAckPathV2 { + pub fn new( + source_client_on_target: ClientId, + source_prefix: String, + target_client_on_source: ClientId, + target_prefix: String, + ) -> Self { + Self { + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + } + } +} + #[cfg_attr( feature = "parity-scale-codec", derive( @@ -573,6 +705,55 @@ impl CommitmentPath { } } +#[cfg_attr( + feature = "parity-scale-codec", + derive( + parity_scale_codec::Encode, + parity_scale_codec::Decode, + scale_info::TypeInfo + ) +)] +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] +#[display( + fmt = "{EUREKA}/{PACKET_COMMITMENT_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}/{SEQUENCE_PREFIX}/{sequence}" +)] +pub struct CommitmentPathV2 { + pub source_client_on_target: ClientId, + pub source_prefix: String, + pub target_client_on_source: ClientId, + pub target_prefix: String, + pub sequence: Sequence, +} + +impl CommitmentPathV2 { + pub fn new( + source_client_on_target: ClientId, + source_prefix: String, + target_client_on_source: ClientId, + target_prefix: String, + sequence: Sequence, + ) -> Self { + Self { + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + sequence, + } + } + + /// Returns the commitment store prefix under which all the packet + /// commitments are stored: "commitments" + pub fn prefix() -> String { + format!("{EUREKA}/{PACKET_COMMITMENT_PREFIX}") + } +} + #[cfg_attr( feature = "parity-scale-codec", derive( @@ -612,6 +793,55 @@ impl AckPath { } } +#[cfg_attr( + feature = "parity-scale-codec", + derive( + parity_scale_codec::Encode, + parity_scale_codec::Decode, + scale_info::TypeInfo + ) +)] +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] +#[display( + fmt = "{EUREKA}/{PACKET_ACK_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}/{SEQUENCE_PREFIX}/{sequence}" +)] +pub struct AckPathV2 { + pub source_client_on_target: ClientId, + pub source_prefix: String, + pub target_client_on_source: ClientId, + pub target_prefix: String, + pub sequence: Sequence, +} + +impl AckPathV2 { + pub fn new( + source_client_on_target: ClientId, + source_prefix: String, + target_client_on_source: ClientId, + target_prefix: String, + sequence: Sequence, + ) -> Self { + Self { + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + sequence, + } + } + + /// Returns the ack store prefix under which all the packet acks are stored: + /// "acks" + pub fn prefix() -> String { + format!("{EUREKA}/{PACKET_ACK_PREFIX}") + } +} + #[cfg_attr( feature = "parity-scale-codec", derive( @@ -651,6 +881,55 @@ impl ReceiptPath { } } +#[cfg_attr( + feature = "parity-scale-codec", + derive( + parity_scale_codec::Encode, + parity_scale_codec::Decode, + scale_info::TypeInfo + ) +)] +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] +#[display( + fmt = "{EUREKA}/{PACKET_RECEIPT_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}/{SEQUENCE_PREFIX}/{sequence}" +)] +pub struct ReceiptPathV2 { + pub source_client_on_target: ClientId, + pub source_prefix: String, + pub target_client_on_source: ClientId, + pub target_prefix: String, + pub sequence: Sequence, +} + +impl ReceiptPathV2 { + pub fn new( + source_client_on_target: ClientId, + source_prefix: String, + target_client_on_source: ClientId, + target_prefix: String, + sequence: Sequence, + ) -> Self { + Self { + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + sequence, + } + } + + /// Returns the receipt store prefix under which all the packet receipts are + /// stored: "receipts" + pub fn prefix() -> String { + format!("{EUREKA}/{PACKET_RECEIPT_PREFIX}") + } +} + #[cfg_attr( feature = "parity-scale-codec", derive( @@ -768,6 +1047,8 @@ impl FromStr for Path { .or_else(|| parse_commitments(&components)) .or_else(|| parse_acks(&components)) .or_else(|| parse_receipts(&components)) + .or_else(|| parse_commit_ack_receipt_seqs_v2(&components)) + .or_else(|| parse_commit_ack_receipt_v2(&components)) .or_else(|| parse_upgrade_client_state(&components)) .or_else(|| parse_upgrade_consensus_state(&components)) .ok_or(PathError::ParseFailure { @@ -1075,6 +1356,127 @@ fn parse_receipts(components: &[&str]) -> Option { ) } +fn parse_commit_ack_receipt_seqs_v2(components: &[&str]) -> Option { + if components.len() != 10 { + return None; + } + + if !(components[0] == EUREKA + && components[2] == SOURCE_CLIENT_ON_TARGET + && components[4] == SOURCE_PREFIX + && components[6] == TARGET_CLIENT_ON_SOURCE + && components[8] == TARGET_PREFIX) + { + return None; + } + + if !(components[1] == NEXT_SEQ_SEND_PREFIX + || components[1] == NEXT_SEQ_RECV_PREFIX + || components[1] == NEXT_SEQ_ACK_PREFIX) + { + return None; + } + + let source_client_on_target = ClientId::from_str(components[3]).ok()?; + let source_prefix = components[5].into(); + let target_client_on_source = ClientId::from_str(components[7]).ok()?; + let target_prefix = components[9].into(); + + match components[1] { + NEXT_SEQ_SEND_PREFIX => Some( + SeqSendPathV2::new( + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + ) + .into(), + ), + NEXT_SEQ_RECV_PREFIX => Some( + SeqRecvPathV2::new( + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + ) + .into(), + ), + NEXT_SEQ_ACK_PREFIX => Some( + SeqAckPathV2::new( + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + ) + .into(), + ), + _ => None, + } +} + +fn parse_commit_ack_receipt_v2(components: &[&str]) -> Option { + if components.len() != 12 { + return None; + } + + if !(components[0] == EUREKA + && components[2] == SOURCE_CLIENT_ON_TARGET + && components[4] == SOURCE_PREFIX + && components[6] == TARGET_CLIENT_ON_SOURCE + && components[8] == TARGET_PREFIX + && components[10] == SEQUENCE_PREFIX) + { + return None; + } + + if !(components[1] == PACKET_COMMITMENT_PREFIX + || components[1] == PACKET_ACK_PREFIX + || components[1] == PACKET_RECEIPT_PREFIX) + { + return None; + } + + let source_client_on_target = ClientId::from_str(components[3]).ok()?; + let source_prefix = components[5].into(); + let target_client_on_source = ClientId::from_str(components[7]).ok()?; + let target_prefix = components[9].into(); + let sequence = Sequence::from_str(components[11]).ok()?; + + match components[1] { + PACKET_COMMITMENT_PREFIX => Some( + CommitmentPathV2::new( + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + sequence, + ) + .into(), + ), + PACKET_ACK_PREFIX => Some( + AckPathV2::new( + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + sequence, + ) + .into(), + ), + PACKET_RECEIPT_PREFIX => Some( + ReceiptPathV2::new( + source_client_on_target, + source_prefix, + target_client_on_source, + target_prefix, + sequence, + ) + .into(), + ), + _ => None, + } +} + fn parse_upgrade_client_state(components: &[&str]) -> Option { if components.len() != 3 { return None; From b0ba71744df992c9474d144798458797b480bc01 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 16:49:49 +0100 Subject: [PATCH 02/13] use reference in arguments --- ibc-eureka-core/ics24-host/types/src/path.rs | 146 +++++++++---------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/ibc-eureka-core/ics24-host/types/src/path.rs b/ibc-eureka-core/ics24-host/types/src/path.rs index 5e5a15c23..497aedcfe 100644 --- a/ibc-eureka-core/ics24-host/types/src/path.rs +++ b/ibc-eureka-core/ics24-host/types/src/path.rs @@ -526,16 +526,16 @@ pub struct SeqSendPathV2 { impl SeqSendPathV2 { pub fn new( - source_client_on_target: ClientId, - source_prefix: String, - target_client_on_source: ClientId, - target_prefix: String, + source_client_on_target: &ClientId, + source_prefix: &str, + target_client_on_source: &ClientId, + target_prefix: &str, ) -> Self { Self { - source_client_on_target, - source_prefix, - target_client_on_source, - target_prefix, + source_client_on_target: source_client_on_target.clone(), + source_prefix: source_prefix.to_string(), + target_client_on_source: target_client_on_source.clone(), + target_prefix: target_prefix.to_string(), } } } @@ -589,16 +589,16 @@ pub struct SeqRecvPathV2 { impl SeqRecvPathV2 { pub fn new( - source_client_on_target: ClientId, - source_prefix: String, - target_client_on_source: ClientId, - target_prefix: String, + source_client_on_target: &ClientId, + source_prefix: &str, + target_client_on_source: &ClientId, + target_prefix: &str, ) -> Self { Self { - source_client_on_target, - source_prefix, - target_client_on_source, - target_prefix, + source_client_on_target: source_client_on_target.clone(), + source_prefix: source_prefix.to_string(), + target_client_on_source: target_client_on_source.clone(), + target_prefix: target_prefix.to_string(), } } } @@ -652,16 +652,16 @@ pub struct SeqAckPathV2 { impl SeqAckPathV2 { pub fn new( - source_client_on_target: ClientId, - source_prefix: String, - target_client_on_source: ClientId, - target_prefix: String, + source_client_on_target: &ClientId, + source_prefix: &str, + target_client_on_source: &ClientId, + target_prefix: &str, ) -> Self { Self { - source_client_on_target, - source_prefix, - target_client_on_source, - target_prefix, + source_client_on_target: source_client_on_target.clone(), + source_prefix: source_prefix.to_string(), + target_client_on_source: target_client_on_source.clone(), + target_prefix: target_prefix.to_string(), } } } @@ -732,18 +732,18 @@ pub struct CommitmentPathV2 { impl CommitmentPathV2 { pub fn new( - source_client_on_target: ClientId, - source_prefix: String, - target_client_on_source: ClientId, - target_prefix: String, - sequence: Sequence, + source_client_on_target: &ClientId, + source_prefix: &str, + target_client_on_source: &ClientId, + target_prefix: &str, + sequence: &Sequence, ) -> Self { Self { - source_client_on_target, - source_prefix, - target_client_on_source, - target_prefix, - sequence, + source_client_on_target: source_client_on_target.clone(), + source_prefix: source_prefix.to_string(), + target_client_on_source: target_client_on_source.clone(), + target_prefix: target_prefix.to_string(), + sequence: *sequence, } } @@ -820,18 +820,18 @@ pub struct AckPathV2 { impl AckPathV2 { pub fn new( - source_client_on_target: ClientId, - source_prefix: String, - target_client_on_source: ClientId, - target_prefix: String, - sequence: Sequence, + source_client_on_target: &ClientId, + source_prefix: &str, + target_client_on_source: &ClientId, + target_prefix: &str, + sequence: &Sequence, ) -> Self { Self { - source_client_on_target, - source_prefix, - target_client_on_source, - target_prefix, - sequence, + source_client_on_target: source_client_on_target.clone(), + source_prefix: source_prefix.to_string(), + target_client_on_source: target_client_on_source.clone(), + target_prefix: target_prefix.to_string(), + sequence: *sequence, } } @@ -908,18 +908,18 @@ pub struct ReceiptPathV2 { impl ReceiptPathV2 { pub fn new( - source_client_on_target: ClientId, - source_prefix: String, - target_client_on_source: ClientId, - target_prefix: String, - sequence: Sequence, + source_client_on_target: &ClientId, + source_prefix: &str, + target_client_on_source: &ClientId, + target_prefix: &str, + sequence: &Sequence, ) -> Self { Self { - source_client_on_target, - source_prefix, - target_client_on_source, - target_prefix, - sequence, + source_client_on_target: source_client_on_target.clone(), + source_prefix: source_prefix.to_string(), + target_client_on_source: target_client_on_source.clone(), + target_prefix: target_prefix.to_string(), + sequence: *sequence, } } @@ -1378,34 +1378,34 @@ fn parse_commit_ack_receipt_seqs_v2(components: &[&str]) -> Option { } let source_client_on_target = ClientId::from_str(components[3]).ok()?; - let source_prefix = components[5].into(); + let source_prefix = components[5]; let target_client_on_source = ClientId::from_str(components[7]).ok()?; - let target_prefix = components[9].into(); + let target_prefix = components[9]; match components[1] { NEXT_SEQ_SEND_PREFIX => Some( SeqSendPathV2::new( - source_client_on_target, + &source_client_on_target, source_prefix, - target_client_on_source, + &target_client_on_source, target_prefix, ) .into(), ), NEXT_SEQ_RECV_PREFIX => Some( SeqRecvPathV2::new( - source_client_on_target, + &source_client_on_target, source_prefix, - target_client_on_source, + &target_client_on_source, target_prefix, ) .into(), ), NEXT_SEQ_ACK_PREFIX => Some( SeqAckPathV2::new( - source_client_on_target, + &source_client_on_target, source_prefix, - target_client_on_source, + &target_client_on_source, target_prefix, ) .into(), @@ -1437,39 +1437,39 @@ fn parse_commit_ack_receipt_v2(components: &[&str]) -> Option { } let source_client_on_target = ClientId::from_str(components[3]).ok()?; - let source_prefix = components[5].into(); + let source_prefix = components[5]; let target_client_on_source = ClientId::from_str(components[7]).ok()?; - let target_prefix = components[9].into(); + let target_prefix = components[9]; let sequence = Sequence::from_str(components[11]).ok()?; match components[1] { PACKET_COMMITMENT_PREFIX => Some( CommitmentPathV2::new( - source_client_on_target, + &source_client_on_target, source_prefix, - target_client_on_source, + &target_client_on_source, target_prefix, - sequence, + &sequence, ) .into(), ), PACKET_ACK_PREFIX => Some( AckPathV2::new( - source_client_on_target, + &source_client_on_target, source_prefix, - target_client_on_source, + &target_client_on_source, target_prefix, - sequence, + &sequence, ) .into(), ), PACKET_RECEIPT_PREFIX => Some( ReceiptPathV2::new( - source_client_on_target, + &source_client_on_target, source_prefix, - target_client_on_source, + &target_client_on_source, target_prefix, - sequence, + &sequence, ) .into(), ), From edcbb07dc469807ad337b99bd82184e96783a2d0 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 16:50:02 +0100 Subject: [PATCH 03/13] use v2 paths by default --- ibc-eureka-core/ics24-host/src/context.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibc-eureka-core/ics24-host/src/context.rs b/ibc-eureka-core/ics24-host/src/context.rs index 8638a5ec9..c9051eedb 100644 --- a/ibc-eureka-core/ics24-host/src/context.rs +++ b/ibc-eureka-core/ics24-host/src/context.rs @@ -9,7 +9,8 @@ use ibc_eureka_core_handler_types::events::IbcEvent; use ibc_eureka_core_host_types::error::HostError; use ibc_eureka_core_host_types::identifiers::Sequence; use ibc_eureka_core_host_types::path::{ - AckPath, CommitmentPath, ReceiptPath, SeqAckPath, SeqRecvPath, SeqSendPath, + AckPathV2 as AckPath, CommitmentPathV2 as CommitmentPath, ReceiptPathV2 as ReceiptPath, + SeqAckPathV2 as SeqAckPath, SeqRecvPathV2 as SeqRecvPath, SeqSendPathV2 as SeqSendPath, }; use ibc_primitives::prelude::*; use ibc_primitives::{Signer, Timestamp}; From 61ee18ae558d8c4d9e2d052a4841693574e212c8 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 16:50:40 +0100 Subject: [PATCH 04/13] use new v2 paths for commit ack receipt --- ibc-eureka-core/ics04-channel/src/context.rs | 4 +- .../src/handler/acknowledgement.rs | 63 +++++++++++++------ .../ics04-channel/src/handler/recv_packet.rs | 59 +++++++++++++---- .../ics04-channel/src/handler/send_packet.rs | 34 ++++++++-- .../ics04-channel/src/handler/timeout.rs | 40 ++++++++---- 5 files changed, 150 insertions(+), 50 deletions(-) diff --git a/ibc-eureka-core/ics04-channel/src/context.rs b/ibc-eureka-core/ics04-channel/src/context.rs index 87b0ab296..91c9f012f 100644 --- a/ibc-eureka-core/ics04-channel/src/context.rs +++ b/ibc-eureka-core/ics04-channel/src/context.rs @@ -5,7 +5,9 @@ use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::IbcEvent; use ibc_eureka_core_host::types::error::HostError; use ibc_eureka_core_host::types::identifiers::Sequence; -use ibc_eureka_core_host::types::path::{CommitmentPath, SeqSendPath}; +use ibc_eureka_core_host::types::path::{ + CommitmentPathV2 as CommitmentPath, SeqSendPathV2 as SeqSendPath, +}; use ibc_eureka_core_host::{ExecutionContext, ValidationContext}; use ibc_primitives::prelude::*; diff --git a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs index 1c0f32e5d..8a7ca75cd 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs @@ -6,7 +6,9 @@ use ibc_eureka_core_channel_types::events::AcknowledgePacket; use ibc_eureka_core_channel_types::msgs::MsgAcknowledgement; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; -use ibc_eureka_core_host::types::path::{AckPath, ClientConsensusStatePath, CommitmentPath, Path}; +use ibc_eureka_core_host::types::path::{ + AckPathV2 as AckPath, ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, +}; use ibc_eureka_core_host::{ExecutionContext, ValidationContext}; use ibc_eureka_core_router::module::Module; use ibc_primitives::prelude::*; @@ -35,8 +37,10 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (_, port_id_on_a) = &payload.header.source_port; - let channel_id_on_a = &packet.header.target_client_on_source; + let (source_prefix, _source_port) = &payload.header.source_port; + let channel_target_client_on_source = &packet.header.target_client_on_source; + let (target_prefix, _target_port) = &payload.header.target_port; + let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; // In all cases, this event is emitted @@ -44,7 +48,13 @@ where ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?; ctx_a.emit_ibc_event(event)?; - let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a); + let commitment_path_on_a = CommitmentPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); // check if we're in the NO-OP case if ctx_a.get_packet_commitment(&commitment_path_on_a).is_err() { @@ -92,14 +102,20 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (prefix_on_a, port_id_on_a) = &payload.header.source_port; - let channel_id_on_a = &packet.header.target_client_on_source; - let (_, port_id_on_b) = &payload.header.target_port; - let channel_id_on_b = &packet.header.source_client_on_target; + let (source_prefix, _source_port) = &payload.header.source_port; + let channel_target_client_on_source = &packet.header.target_client_on_source; + let (target_prefix, _target_port) = &payload.header.target_port; + let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; - let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a); + let commitment_path_on_a = CommitmentPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); // Verify packet commitment let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else { @@ -126,34 +142,43 @@ where // Verify proofs { // TODO(rano): avoid a vs b confusion - let client_id_on_a = channel_id_on_b.as_ref(); + let id_target_client_on_source = channel_target_client_on_source.as_ref(); let client_val_ctx_a = ctx_a.get_client_validation_context(); - let client_state_of_b_on_a = client_val_ctx_a.client_state(client_id_on_a)?; + let target_client_on_source = client_val_ctx_a.client_state(id_target_client_on_source)?; - client_state_of_b_on_a - .status(ctx_a.get_client_validation_context(), client_id_on_a)? + target_client_on_source + .status( + ctx_a.get_client_validation_context(), + id_target_client_on_source, + )? .verify_is_active()?; - client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; + target_client_on_source.validate_proof_height(msg.proof_height_on_b)?; let client_cons_state_path_on_a = ClientConsensusStatePath::new( - client_id_on_a.clone(), + id_target_client_on_source.clone(), msg.proof_height_on_b.revision_number(), msg.proof_height_on_b.revision_height(), ); let consensus_state_of_b_on_a = client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?; let ack_commitment = compute_ack_commitment(&msg.acknowledgement); - let ack_path_on_b = AckPath::new(port_id_on_b, channel_id_on_b, *seq_on_a); + let ack_path_on_b = AckPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); // Verify the proof for the packet against the chain store. - client_state_of_b_on_a.verify_membership( - prefix_on_a, + target_client_on_source.verify_membership( + target_prefix, &msg.proof_acked_on_b, consensus_state_of_b_on_a.root(), - Path::Ack(ack_path_on_b), + Path::AckV2(ack_path_on_b), ack_commitment.into_vec(), )?; } diff --git a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs index ea76af1e3..3537f4e65 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs @@ -7,7 +7,8 @@ use ibc_eureka_core_channel_types::msgs::MsgRecvPacket; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_eureka_core_host::types::path::{ - AckPath, ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath, SeqRecvPath, + AckPathV2 as AckPath, ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, + ReceiptPathV2 as ReceiptPath, SeqRecvPathV2 as SeqRecvPath, }; use ibc_eureka_core_host::{ExecutionContext, ValidationContext}; use ibc_eureka_core_router::module::Module; @@ -35,16 +36,23 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (_, target_port) = &payload.header.target_port; + let (source_prefix, _source_port) = &payload.header.source_port; let channel_source_client_on_target = &packet.header.source_client_on_target; + let (target_prefix, _target_port) = &payload.header.target_port; + let channel_target_client_on_source = &packet.header.target_client_on_source; let seq_on_a = &packet.header.seq_on_a; // Check if another relayer already relayed the packet. // We don't want to fail the transaction in this case. { let packet_already_received = { - let receipt_path_on_b = - ReceiptPath::new(target_port, channel_source_client_on_target, *seq_on_a); + let receipt_path_on_b = ReceiptPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); ctx_b.get_packet_receipt(&receipt_path_on_b)?.is_ok() }; @@ -59,11 +67,22 @@ where { // `recvPacket` core handler state changes { - let seq_recv_path_on_b = SeqRecvPath::new(target_port, channel_source_client_on_target); + let seq_recv_path_on_b = SeqRecvPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + ); let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?; ctx_b.store_next_sequence_recv(&seq_recv_path_on_b, next_seq_recv.increment())?; } - let ack_path_on_b = AckPath::new(target_port, channel_source_client_on_target, *seq_on_a); + let ack_path_on_b = AckPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); // `writeAcknowledgement` handler state changes ctx_b.store_packet_acknowledgement( &ack_path_on_b, @@ -105,8 +124,9 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (prefix_source, source_port) = &payload.header.source_port; + let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; + let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; @@ -157,15 +177,20 @@ where &packet.header.timeout_height_on_b, &packet.header.timeout_timestamp_on_b, ); - let commitment_path_on_a = - CommitmentPath::new(source_port, channel_target_client_on_source, *seq_on_a); + let commitment_path_on_a = CommitmentPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); // Verify the proof for the packet against the chain store. source_client_on_target.verify_membership( - prefix_source, + source_prefix, &msg.proof_commitment_on_a, consensus_state_of_a_on_b.root(), - Path::Commitment(commitment_path_on_a), + Path::CommitmentV2(commitment_path_on_a), expected_commitment_on_a.into_vec(), )?; } @@ -191,11 +216,19 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (_, target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; + let (target_prefix, _target_port) = &payload.header.target_port; + let channel_target_client_on_source = &packet.header.target_client_on_source; + let (source_prefix, _source_port) = &payload.header.source_port; let seq_on_a = &packet.header.seq_on_a; - let ack_path_on_b = AckPath::new(target_port, channel_source_client_on_target, *seq_on_a); + let ack_path_on_b = AckPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); if ctx_b.get_packet_acknowledgement(&ack_path_on_b).is_ok() { return Err(ChannelError::DuplicateAcknowledgment(*seq_on_a)); } diff --git a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs index 6e9747ebe..1ac3ded5f 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -4,7 +4,9 @@ use ibc_eureka_core_channel_types::events::SendPacket; use ibc_eureka_core_channel_types::packet::Packet; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; -use ibc_eureka_core_host::types::path::{ClientConsensusStatePath, CommitmentPath, SeqSendPath}; +use ibc_eureka_core_host::types::path::{ + ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, SeqSendPathV2 as SeqSendPath, +}; use ibc_primitives::prelude::*; use crate::context::{SendPacketExecutionContext, SendPacketValidationContext}; @@ -32,8 +34,10 @@ pub fn send_packet_validate( let payload = &packet.payloads[0]; - let (_, source_port) = &payload.header.source_port; + let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; + let (target_prefix, _target_port) = &payload.header.target_port; + let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let id_target_client_on_source = channel_target_client_on_source.as_ref(); @@ -75,7 +79,12 @@ pub fn send_packet_validate( } // TODO(rano): include full channel identifier in the path - let seq_send_path_on_a = SeqSendPath::new(source_port, channel_target_client_on_source); + let seq_send_path_on_a = SeqSendPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + ); let next_seq_send_on_a = ctx_a.get_next_sequence_send(&seq_send_path_on_a)?; if seq_on_a != &next_seq_send_on_a { @@ -97,20 +106,33 @@ pub fn send_packet_execute( ) -> Result<(), ChannelError> { let payload = &packet.payloads[0]; - let (_, source_port) = &payload.header.source_port; + let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; + let (target_prefix, _target_port) = &payload.header.target_port; + let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; { - let seq_send_path_on_a = SeqSendPath::new(source_port, channel_target_client_on_source); + let seq_send_path_on_a = SeqSendPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + ); let next_seq_send_on_a = ctx_a.get_next_sequence_send(&seq_send_path_on_a)?; ctx_a.store_next_sequence_send(&seq_send_path_on_a, next_seq_send_on_a.increment())?; } ctx_a.store_packet_commitment( - &CommitmentPath::new(source_port, channel_target_client_on_source, *seq_on_a), + &CommitmentPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ), compute_packet_commitment( data, &packet.header.timeout_height_on_b, diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs index 0166dffc8..09e0f4d96 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs @@ -5,7 +5,8 @@ use ibc_eureka_core_channel_types::msgs::MsgTimeout; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_eureka_core_host::types::path::{ - ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath, + ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, + ReceiptPathV2 as ReceiptPath, }; use ibc_eureka_core_host::{ExecutionContext, ValidationContext}; use ibc_eureka_core_router::module::Module; @@ -38,8 +39,10 @@ where let payload = &packet.payloads[0]; - let (_, source_port) = &payload.header.source_port; + let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; + let (target_prefix, _target_port) = &payload.header.target_port; + let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; // In all cases, this event is emitted @@ -47,8 +50,13 @@ where ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?; ctx_a.emit_ibc_event(event)?; - let commitment_path_on_a = - CommitmentPath::new(source_port, channel_target_client_on_source, *seq_on_a); + let commitment_path_on_a = CommitmentPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); // check if we're in the NO-OP case if ctx_a.get_packet_commitment(&commitment_path_on_a).is_err() { @@ -88,16 +96,21 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (_, source_port) = &payload.header.source_port; + let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, target_port) = &payload.header.target_port; + let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; //verify packet commitment - let commitment_path_on_a = - CommitmentPath::new(source_port, channel_target_client_on_source, *seq_on_a); + let commitment_path_on_a = CommitmentPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else { // This error indicates that the timeout has already been relayed // or there is a misconfigured relayer attempting to prove a timeout @@ -154,14 +167,19 @@ where } let next_seq_recv_verification_result = { - let receipt_path_on_b = - ReceiptPath::new(target_port, channel_source_client_on_target, *seq_on_a); + let receipt_path_on_b = ReceiptPath::new( + channel_source_client_on_target.as_ref(), + &format!("{source_prefix:?}"), + channel_target_client_on_source.as_ref(), + &format!("{target_prefix:?}"), + seq_on_a, + ); target_client_on_source.verify_non_membership( target_prefix, &msg.proof_unreceived_on_b, consensus_state_of_b_on_a.root(), - Path::Receipt(receipt_path_on_b), + Path::ReceiptV2(receipt_path_on_b), ) }; From 4d3ec533fb72231d8dfab1a5e598985066f2ed7a Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 16:51:38 +0100 Subject: [PATCH 05/13] add todo comment --- ibc-eureka-core/ics04-channel/src/handler/send_packet.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs index 1ac3ded5f..64cba4240 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -81,6 +81,7 @@ pub fn send_packet_validate( // TODO(rano): include full channel identifier in the path let seq_send_path_on_a = SeqSendPath::new( channel_source_client_on_target.as_ref(), + // todo(rano): use ascii encoding of the bytes &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), &format!("{target_prefix:?}"), From 096aa08aa65d7d67dedb60b205d185ac21fb7748 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 17:33:09 +0100 Subject: [PATCH 06/13] counterparty client methods --- ibc-eureka-core/ics02-client/context/src/context.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ibc-eureka-core/ics02-client/context/src/context.rs b/ibc-eureka-core/ics02-client/context/src/context.rs index 7c219cf00..ce92c1622 100644 --- a/ibc-eureka-core/ics02-client/context/src/context.rs +++ b/ibc-eureka-core/ics02-client/context/src/context.rs @@ -1,4 +1,5 @@ use ibc_eureka_core_client_types::Height; +use ibc_eureka_core_commitment_types::commitment::CommitmentPrefix; use ibc_eureka_core_host_types::error::HostError; use ibc_eureka_core_host_types::identifiers::ClientId; use ibc_eureka_core_host_types::path::{ClientConsensusStatePath, ClientStatePath}; @@ -39,6 +40,11 @@ pub trait ClientValidationContext: Sized { client_id: &ClientId, height: &Height, ) -> Result<(Timestamp, Height), HostError>; + + fn counterparty_client( + &self, + client_id: &ClientId, + ) -> Result<(ClientId, CommitmentPrefix), HostError>; } /// Defines the methods that all client `ExecutionContext`s (precisely the @@ -98,6 +104,13 @@ pub trait ClientExecutionContext: /// /// Note that this timestamp is determined by the host. fn delete_update_meta(&mut self, client_id: ClientId, height: Height) -> Result<(), HostError>; + + fn store_counterparty_client( + &self, + client_id: &ClientId, + counterparty_client_id: &ClientId, + counterparty_prefix: &CommitmentPrefix, + ) -> Result<(), HostError>; } /// An optional trait that extends the client validation context capabilities by From aacc9b8875f546020dcb920f0ef55d949a8b2485 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 17:34:14 +0100 Subject: [PATCH 07/13] rm prefix in path --- ibc-eureka-core/ics24-host/types/src/path.rs | 133 ++++--------------- 1 file changed, 28 insertions(+), 105 deletions(-) diff --git a/ibc-eureka-core/ics24-host/types/src/path.rs b/ibc-eureka-core/ics24-host/types/src/path.rs index 497aedcfe..050cb81b8 100644 --- a/ibc-eureka-core/ics24-host/types/src/path.rs +++ b/ibc-eureka-core/ics24-host/types/src/path.rs @@ -17,9 +17,7 @@ pub const NEXT_CHANNEL_SEQUENCE: &str = "nextChannelSequence"; pub const EUREKA: &str = "eureka"; pub const SOURCE_CLIENT_ON_TARGET: &str = "sourceClientOnTarget"; -pub const SOURCE_PREFIX: &str = "sourcePrefix"; pub const TARGET_CLIENT_ON_SOURCE: &str = "targetClientOnSource"; -pub const TARGET_PREFIX: &str = "targetPrefix"; pub const CLIENT_PREFIX: &str = "clients"; pub const CLIENT_STATE: &str = "clientState"; @@ -515,27 +513,18 @@ impl SeqSendPath { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] #[display( - fmt = "{EUREKA}/{NEXT_SEQ_SEND_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}" + fmt = "{EUREKA}/{NEXT_SEQ_SEND_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}" )] pub struct SeqSendPathV2 { pub source_client_on_target: ClientId, - pub source_prefix: String, pub target_client_on_source: ClientId, - pub target_prefix: String, } impl SeqSendPathV2 { - pub fn new( - source_client_on_target: &ClientId, - source_prefix: &str, - target_client_on_source: &ClientId, - target_prefix: &str, - ) -> Self { + pub fn new(source_client_on_target: &ClientId, target_client_on_source: &ClientId) -> Self { Self { source_client_on_target: source_client_on_target.clone(), - source_prefix: source_prefix.to_string(), target_client_on_source: target_client_on_source.clone(), - target_prefix: target_prefix.to_string(), } } } @@ -578,27 +567,18 @@ impl SeqRecvPath { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] #[display( - fmt = "{EUREKA}/{NEXT_SEQ_RECV_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}" + fmt = "{EUREKA}/{NEXT_SEQ_RECV_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}" )] pub struct SeqRecvPathV2 { pub source_client_on_target: ClientId, - pub source_prefix: String, pub target_client_on_source: ClientId, - pub target_prefix: String, } impl SeqRecvPathV2 { - pub fn new( - source_client_on_target: &ClientId, - source_prefix: &str, - target_client_on_source: &ClientId, - target_prefix: &str, - ) -> Self { + pub fn new(source_client_on_target: &ClientId, target_client_on_source: &ClientId) -> Self { Self { source_client_on_target: source_client_on_target.clone(), - source_prefix: source_prefix.to_string(), target_client_on_source: target_client_on_source.clone(), - target_prefix: target_prefix.to_string(), } } } @@ -641,27 +621,18 @@ impl SeqAckPath { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] #[display( - fmt = "{EUREKA}/{NEXT_SEQ_ACK_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}" + fmt = "{EUREKA}/{NEXT_SEQ_ACK_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}" )] pub struct SeqAckPathV2 { pub source_client_on_target: ClientId, - pub source_prefix: String, pub target_client_on_source: ClientId, - pub target_prefix: String, } impl SeqAckPathV2 { - pub fn new( - source_client_on_target: &ClientId, - source_prefix: &str, - target_client_on_source: &ClientId, - target_prefix: &str, - ) -> Self { + pub fn new(source_client_on_target: &ClientId, target_client_on_source: &ClientId) -> Self { Self { source_client_on_target: source_client_on_target.clone(), - source_prefix: source_prefix.to_string(), target_client_on_source: target_client_on_source.clone(), - target_prefix: target_prefix.to_string(), } } } @@ -720,29 +691,25 @@ impl CommitmentPath { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] #[display( - fmt = "{EUREKA}/{PACKET_COMMITMENT_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}/{SEQUENCE_PREFIX}/{sequence}" + fmt = "{EUREKA}/{PACKET_COMMITMENT_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{SEQUENCE_PREFIX}/{sequence}" )] pub struct CommitmentPathV2 { pub source_client_on_target: ClientId, - pub source_prefix: String, + pub target_client_on_source: ClientId, - pub target_prefix: String, + pub sequence: Sequence, } impl CommitmentPathV2 { pub fn new( source_client_on_target: &ClientId, - source_prefix: &str, target_client_on_source: &ClientId, - target_prefix: &str, sequence: &Sequence, ) -> Self { Self { source_client_on_target: source_client_on_target.clone(), - source_prefix: source_prefix.to_string(), target_client_on_source: target_client_on_source.clone(), - target_prefix: target_prefix.to_string(), sequence: *sequence, } } @@ -808,29 +775,23 @@ impl AckPath { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] #[display( - fmt = "{EUREKA}/{PACKET_ACK_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}/{SEQUENCE_PREFIX}/{sequence}" + fmt = "{EUREKA}/{PACKET_ACK_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{SEQUENCE_PREFIX}/{sequence}" )] pub struct AckPathV2 { pub source_client_on_target: ClientId, - pub source_prefix: String, pub target_client_on_source: ClientId, - pub target_prefix: String, pub sequence: Sequence, } impl AckPathV2 { pub fn new( source_client_on_target: &ClientId, - source_prefix: &str, target_client_on_source: &ClientId, - target_prefix: &str, sequence: &Sequence, ) -> Self { Self { source_client_on_target: source_client_on_target.clone(), - source_prefix: source_prefix.to_string(), target_client_on_source: target_client_on_source.clone(), - target_prefix: target_prefix.to_string(), sequence: *sequence, } } @@ -896,29 +857,23 @@ impl ReceiptPath { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display)] #[display( - fmt = "{EUREKA}/{PACKET_RECEIPT_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{SOURCE_PREFIX}/{source_prefix}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{TARGET_PREFIX}/{target_prefix}/{SEQUENCE_PREFIX}/{sequence}" + fmt = "{EUREKA}/{PACKET_RECEIPT_PREFIX}/{SOURCE_CLIENT_ON_TARGET}/{source_client_on_target}/{TARGET_CLIENT_ON_SOURCE}/{target_client_on_source}/{SEQUENCE_PREFIX}/{sequence}" )] pub struct ReceiptPathV2 { pub source_client_on_target: ClientId, - pub source_prefix: String, pub target_client_on_source: ClientId, - pub target_prefix: String, pub sequence: Sequence, } impl ReceiptPathV2 { pub fn new( source_client_on_target: &ClientId, - source_prefix: &str, target_client_on_source: &ClientId, - target_prefix: &str, sequence: &Sequence, ) -> Self { Self { source_client_on_target: source_client_on_target.clone(), - source_prefix: source_prefix.to_string(), target_client_on_source: target_client_on_source.clone(), - target_prefix: target_prefix.to_string(), sequence: *sequence, } } @@ -1357,15 +1312,13 @@ fn parse_receipts(components: &[&str]) -> Option { } fn parse_commit_ack_receipt_seqs_v2(components: &[&str]) -> Option { - if components.len() != 10 { + if components.len() != 6 { return None; } if !(components[0] == EUREKA && components[2] == SOURCE_CLIENT_ON_TARGET - && components[4] == SOURCE_PREFIX - && components[6] == TARGET_CLIENT_ON_SOURCE - && components[8] == TARGET_PREFIX) + && components[4] == TARGET_CLIENT_ON_SOURCE) { return None; } @@ -1378,53 +1331,31 @@ fn parse_commit_ack_receipt_seqs_v2(components: &[&str]) -> Option { } let source_client_on_target = ClientId::from_str(components[3]).ok()?; - let source_prefix = components[5]; - let target_client_on_source = ClientId::from_str(components[7]).ok()?; - let target_prefix = components[9]; + let target_client_on_source = ClientId::from_str(components[5]).ok()?; match components[1] { - NEXT_SEQ_SEND_PREFIX => Some( - SeqSendPathV2::new( - &source_client_on_target, - source_prefix, - &target_client_on_source, - target_prefix, - ) - .into(), - ), - NEXT_SEQ_RECV_PREFIX => Some( - SeqRecvPathV2::new( - &source_client_on_target, - source_prefix, - &target_client_on_source, - target_prefix, - ) - .into(), - ), - NEXT_SEQ_ACK_PREFIX => Some( - SeqAckPathV2::new( - &source_client_on_target, - source_prefix, - &target_client_on_source, - target_prefix, - ) - .into(), - ), + NEXT_SEQ_SEND_PREFIX => { + Some(SeqSendPathV2::new(&source_client_on_target, &target_client_on_source).into()) + } + NEXT_SEQ_RECV_PREFIX => { + Some(SeqRecvPathV2::new(&source_client_on_target, &target_client_on_source).into()) + } + NEXT_SEQ_ACK_PREFIX => { + Some(SeqAckPathV2::new(&source_client_on_target, &target_client_on_source).into()) + } _ => None, } } fn parse_commit_ack_receipt_v2(components: &[&str]) -> Option { - if components.len() != 12 { + if components.len() != 8 { return None; } if !(components[0] == EUREKA && components[2] == SOURCE_CLIENT_ON_TARGET - && components[4] == SOURCE_PREFIX - && components[6] == TARGET_CLIENT_ON_SOURCE - && components[8] == TARGET_PREFIX - && components[10] == SEQUENCE_PREFIX) + && components[4] == TARGET_CLIENT_ON_SOURCE + && components[6] == SEQUENCE_PREFIX) { return None; } @@ -1437,18 +1368,14 @@ fn parse_commit_ack_receipt_v2(components: &[&str]) -> Option { } let source_client_on_target = ClientId::from_str(components[3]).ok()?; - let source_prefix = components[5]; - let target_client_on_source = ClientId::from_str(components[7]).ok()?; - let target_prefix = components[9]; - let sequence = Sequence::from_str(components[11]).ok()?; + let target_client_on_source = ClientId::from_str(components[5]).ok()?; + let sequence = Sequence::from_str(components[7]).ok()?; match components[1] { PACKET_COMMITMENT_PREFIX => Some( CommitmentPathV2::new( &source_client_on_target, - source_prefix, &target_client_on_source, - target_prefix, &sequence, ) .into(), @@ -1456,9 +1383,7 @@ fn parse_commit_ack_receipt_v2(components: &[&str]) -> Option { PACKET_ACK_PREFIX => Some( AckPathV2::new( &source_client_on_target, - source_prefix, &target_client_on_source, - target_prefix, &sequence, ) .into(), @@ -1466,9 +1391,7 @@ fn parse_commit_ack_receipt_v2(components: &[&str]) -> Option { PACKET_RECEIPT_PREFIX => Some( ReceiptPathV2::new( &source_client_on_target, - source_prefix, &target_client_on_source, - target_prefix, &sequence, ) .into(), From 7031b8c40a16c4b0e91c050bd28e08462230eda5 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 17:36:55 +0100 Subject: [PATCH 08/13] rm prefix from Packet struct --- .../ics04-channel/types/src/events/mod.rs | 20 +++++++++---------- .../ics04-channel/types/src/msgs/mod.rs | 6 +++--- .../ics04-channel/types/src/packet.rs | 15 +++++++------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ibc-eureka-core/ics04-channel/types/src/events/mod.rs b/ibc-eureka-core/ics04-channel/types/src/events/mod.rs index f8ccd293a..457adf6f9 100644 --- a/ibc-eureka-core/ics04-channel/types/src/events/mod.rs +++ b/ibc-eureka-core/ics04-channel/types/src/events/mod.rs @@ -554,9 +554,9 @@ impl SendPacket { timeout_height_attr_on_b: packet.header.timeout_height_on_b.into(), timeout_timestamp_attr_on_b: packet.header.timeout_timestamp_on_b.into(), seq_attr_on_a: packet.header.seq_on_a.into(), - port_id_attr_on_a: payload.header.source_port.1.into(), + port_id_attr_on_a: payload.header.source_port.into(), chan_id_attr_on_a: packet.header.target_client_on_source.into(), - port_id_attr_on_b: payload.header.target_port.1.into(), + port_id_attr_on_b: payload.header.target_port.into(), chan_id_attr_on_b: packet.header.source_client_on_target.into(), } } @@ -652,9 +652,9 @@ impl ReceivePacket { timeout_height_attr_on_b: packet.header.timeout_height_on_b.into(), timeout_timestamp_attr_on_b: packet.header.timeout_timestamp_on_b.into(), seq_attr_on_a: packet.header.seq_on_a.into(), - port_id_attr_on_a: payload.header.source_port.1.into(), + port_id_attr_on_a: payload.header.source_port.into(), chan_id_attr_on_a: packet.header.target_client_on_source.into(), - port_id_attr_on_b: payload.header.target_port.1.into(), + port_id_attr_on_b: payload.header.target_port.into(), chan_id_attr_on_b: packet.header.source_client_on_target.into(), } } @@ -751,9 +751,9 @@ impl WriteAcknowledgement { timeout_height_attr_on_b: packet.header.timeout_height_on_b.into(), timeout_timestamp_attr_on_b: packet.header.timeout_timestamp_on_b.into(), seq_attr_on_a: packet.header.seq_on_a.into(), - port_id_attr_on_a: payload.header.source_port.1.into(), + port_id_attr_on_a: payload.header.source_port.into(), chan_id_attr_on_a: packet.header.target_client_on_source.into(), - port_id_attr_on_b: payload.header.target_port.1.into(), + port_id_attr_on_b: payload.header.target_port.into(), chan_id_attr_on_b: packet.header.source_client_on_target.into(), acknowledgement: acknowledgement.into(), } @@ -853,9 +853,9 @@ impl AcknowledgePacket { timeout_height_attr_on_b: packet.header.timeout_height_on_b.into(), timeout_timestamp_attr_on_b: packet.header.timeout_timestamp_on_b.into(), seq_on_a: packet.header.seq_on_a.into(), - port_id_attr_on_a: payload.header.source_port.1.into(), + port_id_attr_on_a: payload.header.source_port.into(), chan_id_attr_on_a: packet.header.target_client_on_source.into(), - port_id_attr_on_b: payload.header.target_port.1.into(), + port_id_attr_on_b: payload.header.target_port.into(), chan_id_attr_on_b: packet.header.source_client_on_target.into(), } } @@ -943,9 +943,9 @@ impl TimeoutPacket { timeout_height_attr_on_b: packet.header.timeout_height_on_b.into(), timeout_timestamp_attr_on_b: packet.header.timeout_timestamp_on_b.into(), seq_attr_on_a: packet.header.seq_on_a.into(), - port_id_attr_on_a: payload.header.source_port.1.into(), + port_id_attr_on_a: payload.header.source_port.into(), chan_id_attr_on_a: packet.header.target_client_on_source.into(), - port_id_attr_on_b: payload.header.target_port.1.into(), + port_id_attr_on_b: payload.header.target_port.into(), chan_id_attr_on_b: packet.header.source_client_on_target.into(), } } diff --git a/ibc-eureka-core/ics04-channel/types/src/msgs/mod.rs b/ibc-eureka-core/ics04-channel/types/src/msgs/mod.rs index 69981fb5d..158bcc33f 100644 --- a/ibc-eureka-core/ics04-channel/types/src/msgs/mod.rs +++ b/ibc-eureka-core/ics04-channel/types/src/msgs/mod.rs @@ -30,8 +30,8 @@ pub enum PacketMsg { pub fn packet_msg_to_port_id(msg: &PacketMsg) -> &PortId { match msg { - PacketMsg::Recv(msg) => &msg.packet.payloads[0].header.target_port.1, - PacketMsg::Ack(msg) => &msg.packet.payloads[0].header.source_port.1, - PacketMsg::Timeout(msg) => &msg.packet.payloads[0].header.source_port.1, + PacketMsg::Recv(msg) => &msg.packet.payloads[0].header.target_port, + PacketMsg::Ack(msg) => &msg.packet.payloads[0].header.source_port, + PacketMsg::Timeout(msg) => &msg.packet.payloads[0].header.source_port, } } diff --git a/ibc-eureka-core/ics04-channel/types/src/packet.rs b/ibc-eureka-core/ics04-channel/types/src/packet.rs index bec1b78cc..d83d03296 100644 --- a/ibc-eureka-core/ics04-channel/types/src/packet.rs +++ b/ibc-eureka-core/ics04-channel/types/src/packet.rs @@ -1,6 +1,5 @@ //! Defines the packet type use ibc_eureka_core_client_types::Height; -use ibc_eureka_core_commitment_types::commitment::CommitmentPrefix; use ibc_eureka_core_host_types::error::DecodingError; use ibc_eureka_core_host_types::identifiers::{ChannelId, PortId, Sequence}; use ibc_primitives::prelude::*; @@ -105,8 +104,8 @@ pub struct PacketHeader { #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct PayloadHeader { - pub source_port: (CommitmentPrefix, PortId), - pub target_port: (CommitmentPrefix, PortId), + pub source_port: PortId, + pub target_port: PortId, } #[cfg_attr( @@ -196,7 +195,7 @@ impl core::fmt::Display for Packet { write!( f, "src_port:{}, dst_port:{}", - payload.header.source_port.1, payload.header.target_port.1 + payload.header.source_port, payload.header.target_port )?; } Ok(()) @@ -247,8 +246,8 @@ impl TryFrom for Packet { // TODO(rano): support multi payload; currently only one payload is supported payloads: vec![Payload { header: PayloadHeader { - source_port: (CommitmentPrefix::empty(), raw_pkt.source_port.parse()?), - target_port: (CommitmentPrefix::empty(), raw_pkt.destination_port.parse()?), + source_port: raw_pkt.source_port.parse()?, + target_port: raw_pkt.destination_port.parse()?, }, data: raw_pkt.data, }], @@ -265,8 +264,8 @@ impl From for RawPacket { timeout_height: packet.header.timeout_height_on_b.into(), timeout_timestamp: packet.header.timeout_timestamp_on_b.nanoseconds(), // TODO(rano): support multi payload; currently only one payload is supported - source_port: packet.payloads[0].header.source_port.1.to_string(), - destination_port: packet.payloads[0].header.target_port.1.to_string(), + source_port: packet.payloads[0].header.source_port.to_string(), + destination_port: packet.payloads[0].header.target_port.to_string(), data: packet.payloads[0].data.clone(), } } From 8ec343e136804ab558bde6dc569fe1cba39cf7e8 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 17:37:11 +0100 Subject: [PATCH 09/13] add counterparty mismatch error --- ibc-eureka-core/ics04-channel/types/src/error.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ibc-eureka-core/ics04-channel/types/src/error.rs b/ibc-eureka-core/ics04-channel/types/src/error.rs index bcaad7b9a..8d2529744 100644 --- a/ibc-eureka-core/ics04-channel/types/src/error.rs +++ b/ibc-eureka-core/ics04-channel/types/src/error.rs @@ -4,7 +4,7 @@ use displaydoc::Display; use ibc_eureka_core_client_types::error::ClientError; use ibc_eureka_core_client_types::Height; use ibc_eureka_core_host_types::error::{DecodingError, HostError, IdentifierError}; -use ibc_eureka_core_host_types::identifiers::Sequence; +use ibc_eureka_core_host_types::identifiers::{ClientId, Sequence}; use ibc_primitives::prelude::*; use ibc_primitives::{Timestamp, TimestampError}; @@ -50,6 +50,11 @@ pub enum ChannelError { MissingCounterparty, /// missing timeout MissingTimeout, + /// mismatched counterparty: expected `{expected}`, actual `{actual}` + MismatchCounterparty { + expected: ClientId, + actual: ClientId, + }, /// mismatched packet sequence: expected `{expected}`, actual `{actual}` MismatchedPacketSequence { expected: Sequence, From d8c4acd0c6e09ed0d85b1085325f0f4e30da5a6d Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 17:38:48 +0100 Subject: [PATCH 10/13] refactor after prefix rm --- .../src/handler/acknowledgement.rs | 13 +----------- .../ics04-channel/src/handler/recv_packet.rs | 20 +------------------ .../ics04-channel/src/handler/send_packet.rs | 12 ----------- .../ics04-channel/src/handler/timeout.rs | 14 +------------ 4 files changed, 3 insertions(+), 56 deletions(-) diff --git a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs index 8a7ca75cd..7134492e4 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs @@ -35,11 +35,8 @@ where ExecCtx: ExecutionContext, { let packet = &msg.packet; - let payload = &packet.payloads[0]; - let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; @@ -50,9 +47,7 @@ where let commitment_path_on_a = CommitmentPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); @@ -102,18 +97,14 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; let commitment_path_on_a = CommitmentPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); @@ -167,15 +158,13 @@ where let ack_commitment = compute_ack_commitment(&msg.acknowledgement); let ack_path_on_b = AckPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); // Verify the proof for the packet against the chain store. target_client_on_source.verify_membership( - target_prefix, + &target_prefix, &msg.proof_acked_on_b, consensus_state_of_b_on_a.root(), Path::AckV2(ack_path_on_b), diff --git a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs index 3537f4e65..525924523 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs @@ -34,11 +34,8 @@ where ExecCtx: ExecutionContext, { let packet = &msg.packet; - let payload = &packet.payloads[0]; - let (source_prefix, _source_port) = &payload.header.source_port; let channel_source_client_on_target = &packet.header.source_client_on_target; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_target_client_on_source = &packet.header.target_client_on_source; let seq_on_a = &packet.header.seq_on_a; @@ -48,9 +45,7 @@ where let packet_already_received = { let receipt_path_on_b = ReceiptPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); ctx_b.get_packet_receipt(&receipt_path_on_b)?.is_ok() @@ -69,18 +64,14 @@ where { let seq_recv_path_on_b = SeqRecvPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), ); let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?; ctx_b.store_next_sequence_recv(&seq_recv_path_on_b, next_seq_recv.increment())?; } let ack_path_on_b = AckPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); // `writeAcknowledgement` handler state changes @@ -124,9 +115,7 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; @@ -179,15 +168,13 @@ where ); let commitment_path_on_a = CommitmentPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); // Verify the proof for the packet against the chain store. source_client_on_target.verify_membership( - source_prefix, + &source_prefix, &msg.proof_commitment_on_a, consensus_state_of_a_on_b.root(), Path::CommitmentV2(commitment_path_on_a), @@ -214,19 +201,14 @@ where Ctx: ValidationContext, { let packet = &msg.packet; - let payload = &packet.payloads[0]; let channel_source_client_on_target = &packet.header.source_client_on_target; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (source_prefix, _source_port) = &payload.header.source_port; let seq_on_a = &packet.header.seq_on_a; let ack_path_on_b = AckPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); if ctx_b.get_packet_acknowledgement(&ack_path_on_b).is_ok() { diff --git a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs index 64cba4240..e9e793195 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -32,11 +32,7 @@ pub fn send_packet_validate( return Err(ChannelError::MissingTimeout); } - let payload = &packet.payloads[0]; - - let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; @@ -82,9 +78,7 @@ pub fn send_packet_validate( let seq_send_path_on_a = SeqSendPath::new( channel_source_client_on_target.as_ref(), // todo(rano): use ascii encoding of the bytes - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), ); let next_seq_send_on_a = ctx_a.get_next_sequence_send(&seq_send_path_on_a)?; @@ -107,9 +101,7 @@ pub fn send_packet_execute( ) -> Result<(), ChannelError> { let payload = &packet.payloads[0]; - let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; @@ -117,9 +109,7 @@ pub fn send_packet_execute( { let seq_send_path_on_a = SeqSendPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), ); let next_seq_send_on_a = ctx_a.get_next_sequence_send(&seq_send_path_on_a)?; @@ -129,9 +119,7 @@ pub fn send_packet_execute( ctx_a.store_packet_commitment( &CommitmentPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ), compute_packet_commitment( diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs index 09e0f4d96..ca415ce70 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs @@ -37,11 +37,7 @@ where { let (packet, signer) = (msg.packet, msg.signer); - let payload = &packet.payloads[0]; - - let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; @@ -52,9 +48,7 @@ where let commitment_path_on_a = CommitmentPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); @@ -96,9 +90,7 @@ where let packet = &msg.packet; let payload = &packet.payloads[0]; - let (source_prefix, _source_port) = &payload.header.source_port; let channel_target_client_on_source = &packet.header.target_client_on_source; - let (target_prefix, _target_port) = &payload.header.target_port; let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; let data = &payload.data; @@ -106,9 +98,7 @@ where //verify packet commitment let commitment_path_on_a = CommitmentPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else { @@ -169,14 +159,12 @@ where let next_seq_recv_verification_result = { let receipt_path_on_b = ReceiptPath::new( channel_source_client_on_target.as_ref(), - &format!("{source_prefix:?}"), channel_target_client_on_source.as_ref(), - &format!("{target_prefix:?}"), seq_on_a, ); target_client_on_source.verify_non_membership( - target_prefix, + &target_prefix, &msg.proof_unreceived_on_b, consensus_state_of_b_on_a.root(), Path::ReceiptV2(receipt_path_on_b), From 6bbe2955543f720b889c9eef0379ce886d669828 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 17:39:43 +0100 Subject: [PATCH 11/13] check clientid and use prefix of counterparty --- .../ics04-channel/src/handler/acknowledgement.rs | 12 ++++++++++++ .../ics04-channel/src/handler/recv_packet.rs | 14 ++++++++++++++ .../ics04-channel/src/handler/send_packet.rs | 14 +++++++++++++- .../ics04-channel/src/handler/timeout.rs | 14 ++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs index 7134492e4..998629fc8 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs @@ -6,6 +6,7 @@ use ibc_eureka_core_channel_types::events::AcknowledgePacket; use ibc_eureka_core_channel_types::msgs::MsgAcknowledgement; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ AckPathV2 as AckPath, ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, }; @@ -134,9 +135,20 @@ where { // TODO(rano): avoid a vs b confusion let id_target_client_on_source = channel_target_client_on_source.as_ref(); + let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); let client_val_ctx_a = ctx_a.get_client_validation_context(); + let (stored_id_source_client_on_target, target_prefix) = + client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + + if &stored_id_source_client_on_target != id_source_client_on_target { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_source_client_on_target.clone(), + actual: id_source_client_on_target.clone(), + }); + } + let target_client_on_source = client_val_ctx_a.client_state(id_target_client_on_source)?; target_client_on_source diff --git a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs index 525924523..9774f8750 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs @@ -6,6 +6,7 @@ use ibc_eureka_core_channel_types::events::{ReceivePacket, WriteAcknowledgement} use ibc_eureka_core_channel_types::msgs::MsgRecvPacket; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ AckPathV2 as AckPath, ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, ReceiptPathV2 as ReceiptPath, SeqRecvPathV2 as SeqRecvPath, @@ -140,7 +141,20 @@ where // Verify proofs { let id_source_client_on_target = channel_source_client_on_target.as_ref(); + let id_target_client_on_source: &ClientId = channel_target_client_on_source.as_ref(); + let client_val_ctx_b = ctx_b.get_client_validation_context(); + + let (stored_id_target_client_on_source, source_prefix) = + client_val_ctx_b.counterparty_client(id_source_client_on_target)?; + + if &stored_id_target_client_on_source != id_target_client_on_source { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_target_client_on_source.clone(), + actual: id_target_client_on_source.clone(), + }); + } + let source_client_on_target = client_val_ctx_b.client_state(id_source_client_on_target)?; source_client_on_target diff --git a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs index e9e793195..463699357 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -4,6 +4,7 @@ use ibc_eureka_core_channel_types::events::SendPacket; use ibc_eureka_core_channel_types::packet::Packet; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, SeqSendPathV2 as SeqSendPath, }; @@ -36,9 +37,20 @@ pub fn send_packet_validate( let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; + let client_val_ctx_a = ctx_a.get_client_validation_context(); + let id_target_client_on_source = channel_target_client_on_source.as_ref(); + let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); - let client_val_ctx_a = ctx_a.get_client_validation_context(); + let (stored_id_source_client_on_target, _) = + client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + + if &stored_id_source_client_on_target != id_source_client_on_target { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_source_client_on_target.clone(), + actual: id_source_client_on_target.clone(), + }); + } let target_client_on_source = client_val_ctx_a.client_state(id_target_client_on_source)?; diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs index ca415ce70..fa474f85b 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs @@ -4,6 +4,7 @@ use ibc_eureka_core_channel_types::events::TimeoutPacket; use ibc_eureka_core_channel_types::msgs::MsgTimeout; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, ReceiptPathV2 as ReceiptPath, @@ -125,7 +126,20 @@ where // Verify proofs { let id_target_client_on_source = channel_target_client_on_source.as_ref(); + let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); + let client_val_ctx_a = ctx_a.get_client_validation_context(); + + let (stored_id_source_client_on_target, target_prefix) = + client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + + if &stored_id_source_client_on_target != id_source_client_on_target { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_source_client_on_target.clone(), + actual: id_source_client_on_target.clone(), + }); + } + let target_client_on_source = client_val_ctx_a.client_state(id_target_client_on_source)?; target_client_on_source From b9bfec16268fb17ef0bc42289a4b060eeeb6bd0a Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 17:44:23 +0100 Subject: [PATCH 12/13] rename counterparty methods --- ibc-eureka-core/ics02-client/context/src/context.rs | 9 +++++++-- .../ics04-channel/src/handler/acknowledgement.rs | 2 +- ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs | 2 +- ibc-eureka-core/ics04-channel/src/handler/send_packet.rs | 2 +- ibc-eureka-core/ics04-channel/src/handler/timeout.rs | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ibc-eureka-core/ics02-client/context/src/context.rs b/ibc-eureka-core/ics02-client/context/src/context.rs index ce92c1622..25c3b8e57 100644 --- a/ibc-eureka-core/ics02-client/context/src/context.rs +++ b/ibc-eureka-core/ics02-client/context/src/context.rs @@ -41,7 +41,8 @@ pub trait ClientValidationContext: Sized { height: &Height, ) -> Result<(Timestamp, Height), HostError>; - fn counterparty_client( + /// Returns the client identifier and the commitment prefix of the counterparty client. + fn counterparty_meta( &self, client_id: &ClientId, ) -> Result<(ClientId, CommitmentPrefix), HostError>; @@ -105,12 +106,16 @@ pub trait ClientExecutionContext: /// Note that this timestamp is determined by the host. fn delete_update_meta(&mut self, client_id: ClientId, height: Height) -> Result<(), HostError>; - fn store_counterparty_client( + /// Store the client identifier and the commitment prefix of the counterparty client. + fn store_counterparty_meta( &self, client_id: &ClientId, counterparty_client_id: &ClientId, counterparty_prefix: &CommitmentPrefix, ) -> Result<(), HostError>; + + /// Delete the client identifier and the commitment prefix of the counterparty client. + fn delete_counterparty_meta(&self, client_id: &ClientId) -> Result<(), HostError>; } /// An optional trait that extends the client validation context capabilities by diff --git a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs index 998629fc8..17b863d27 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs @@ -140,7 +140,7 @@ where let client_val_ctx_a = ctx_a.get_client_validation_context(); let (stored_id_source_client_on_target, target_prefix) = - client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + client_val_ctx_a.counterparty_meta(id_target_client_on_source)?; if &stored_id_source_client_on_target != id_source_client_on_target { return Err(ChannelError::MismatchCounterparty { diff --git a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs index 9774f8750..4d4701f25 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs @@ -146,7 +146,7 @@ where let client_val_ctx_b = ctx_b.get_client_validation_context(); let (stored_id_target_client_on_source, source_prefix) = - client_val_ctx_b.counterparty_client(id_source_client_on_target)?; + client_val_ctx_b.counterparty_meta(id_source_client_on_target)?; if &stored_id_target_client_on_source != id_target_client_on_source { return Err(ChannelError::MismatchCounterparty { diff --git a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs index 463699357..e8196aa5a 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -43,7 +43,7 @@ pub fn send_packet_validate( let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); let (stored_id_source_client_on_target, _) = - client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + client_val_ctx_a.counterparty_meta(id_target_client_on_source)?; if &stored_id_source_client_on_target != id_source_client_on_target { return Err(ChannelError::MismatchCounterparty { diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs index fa474f85b..d96feaa82 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs @@ -131,7 +131,7 @@ where let client_val_ctx_a = ctx_a.get_client_validation_context(); let (stored_id_source_client_on_target, target_prefix) = - client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + client_val_ctx_a.counterparty_meta(id_target_client_on_source)?; if &stored_id_source_client_on_target != id_source_client_on_target { return Err(ChannelError::MismatchCounterparty { From c6d916b398eb1c7714454049a9f9677c6ae5c560 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 28 Oct 2024 21:27:17 +0100 Subject: [PATCH 13/13] provide counterparty msg --- .../ics02-client/context/src/context.rs | 2 +- .../ics02-client/src/handler/mod.rs | 1 + .../src/handler/provide_counterparty.rs | 57 +++++++++++++++++++ .../ics02-client/types/src/msgs/mod.rs | 3 + .../types/src/msgs/provide_counterparty.rs | 38 +++++++++++++ .../src/handler/acknowledgement.rs | 5 +- .../ics04-channel/src/handler/recv_packet.rs | 5 +- .../ics04-channel/src/handler/send_packet.rs | 5 +- .../ics04-channel/src/handler/timeout.rs | 5 +- .../ics25-handler/src/entrypoint.rs | 6 +- 10 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs create mode 100644 ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs diff --git a/ibc-eureka-core/ics02-client/context/src/context.rs b/ibc-eureka-core/ics02-client/context/src/context.rs index 25c3b8e57..dc134e1fd 100644 --- a/ibc-eureka-core/ics02-client/context/src/context.rs +++ b/ibc-eureka-core/ics02-client/context/src/context.rs @@ -45,7 +45,7 @@ pub trait ClientValidationContext: Sized { fn counterparty_meta( &self, client_id: &ClientId, - ) -> Result<(ClientId, CommitmentPrefix), HostError>; + ) -> Result, HostError>; } /// Defines the methods that all client `ExecutionContext`s (precisely the diff --git a/ibc-eureka-core/ics02-client/src/handler/mod.rs b/ibc-eureka-core/ics02-client/src/handler/mod.rs index 791b5ce39..cd5a9e65c 100644 --- a/ibc-eureka-core/ics02-client/src/handler/mod.rs +++ b/ibc-eureka-core/ics02-client/src/handler/mod.rs @@ -1,6 +1,7 @@ //! This module implements the processing logic for ICS2 (client abstractions and functions) msgs. pub mod create_client; +pub mod provide_counterparty; pub mod recover_client; pub mod update_client; pub mod upgrade_client; diff --git a/ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs b/ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs new file mode 100644 index 000000000..b4154f3c6 --- /dev/null +++ b/ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs @@ -0,0 +1,57 @@ +//! Protocol logic specific to processing ICS2 messages of type `MsgProvideCouterparty`. + +use ibc_eureka_core_client_context::prelude::*; +use ibc_eureka_core_client_types::error::ClientError; +use ibc_eureka_core_client_types::msgs::MsgProvideCouterparty; +use ibc_eureka_core_host::{ExecutionContext, ValidationContext}; +use ibc_primitives::prelude::*; + +pub fn validate(ctx: &Ctx, msg: MsgProvideCouterparty) -> Result<(), ClientError> +where + Ctx: ValidationContext, +{ + let MsgProvideCouterparty { + client_id, signer, .. + } = &msg; + + ctx.validate_message_signer(signer)?; + + let client_val_ctx = ctx.get_client_validation_context(); + + // Read client state from the host chain store. The client should already exist. + let client_state = client_val_ctx.client_state(client_id)?; + + client_state + .status(client_val_ctx, client_id)? + .verify_is_active()?; + + if client_val_ctx.counterparty_meta(client_id)?.is_some() { + return Err(ClientError::ClientSpecific { + description: "counterparty is already provided".into(), + }); + } + + Ok(()) +} + +pub fn execute(ctx: &mut Ctx, msg: MsgProvideCouterparty) -> Result<(), ClientError> +where + Ctx: ExecutionContext, +{ + let MsgProvideCouterparty { + client_id, + counterparty_client_id, + counterparty_commitment_prefix, + .. + } = &msg; + + let client_exec_ctx = ctx.get_client_execution_context(); + + client_exec_ctx.store_counterparty_meta( + client_id, + counterparty_client_id, + counterparty_commitment_prefix, + )?; + + Ok(()) +} diff --git a/ibc-eureka-core/ics02-client/types/src/msgs/mod.rs b/ibc-eureka-core/ics02-client/types/src/msgs/mod.rs index 7c02331c3..0ba422b1c 100644 --- a/ibc-eureka-core/ics02-client/types/src/msgs/mod.rs +++ b/ibc-eureka-core/ics02-client/types/src/msgs/mod.rs @@ -9,12 +9,14 @@ use ibc_proto::google::protobuf::Any; mod create_client; mod misbehaviour; +mod provide_counterparty; mod recover_client; mod update_client; mod upgrade_client; pub use create_client::*; pub use misbehaviour::*; +pub use provide_counterparty::*; pub use recover_client::*; pub use update_client::*; pub use upgrade_client::*; @@ -33,6 +35,7 @@ pub enum ClientMsg { Misbehaviour(MsgSubmitMisbehaviour), UpgradeClient(MsgUpgradeClient), RecoverClient(MsgRecoverClient), + ProvideCounterparty(MsgProvideCouterparty), } pub enum MsgUpdateOrMisbehaviour { diff --git a/ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs b/ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs new file mode 100644 index 000000000..8c3d97fe5 --- /dev/null +++ b/ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs @@ -0,0 +1,38 @@ +//! Definition of domain type message `MsgProvideCouterparty`. + +use ibc_eureka_core_commitment_types::commitment::CommitmentPrefix; +use ibc_eureka_core_host_types::identifiers::ClientId; +use ibc_primitives::prelude::*; +use ibc_primitives::Signer; + +pub const _PROVIDE_COUNTERPARTY_TYPE_URL: &str = "/ibc.core.client.v1.MsgProvideCouterparty"; + +/// A type of message that links an on-chain (IBC) client to its counterparty. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct MsgProvideCouterparty { + pub client_id: ClientId, + pub counterparty_client_id: ClientId, + pub counterparty_commitment_prefix: CommitmentPrefix, + pub signer: Signer, +} + +impl MsgProvideCouterparty { + pub fn new( + client_id: ClientId, + counterparty_client_id: ClientId, + counterparty_commitment_prefix: CommitmentPrefix, + signer: Signer, + ) -> Self { + MsgProvideCouterparty { + client_id, + counterparty_client_id, + counterparty_commitment_prefix, + signer, + } + } +} diff --git a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs index 17b863d27..6c2f1a5ec 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs @@ -139,8 +139,9 @@ where let client_val_ctx_a = ctx_a.get_client_validation_context(); - let (stored_id_source_client_on_target, target_prefix) = - client_val_ctx_a.counterparty_meta(id_target_client_on_source)?; + let (stored_id_source_client_on_target, target_prefix) = client_val_ctx_a + .counterparty_meta(id_target_client_on_source)? + .ok_or(ChannelError::MissingCounterparty)?; if &stored_id_source_client_on_target != id_source_client_on_target { return Err(ChannelError::MismatchCounterparty { diff --git a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs index 4d4701f25..1a3eca9ad 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs @@ -145,8 +145,9 @@ where let client_val_ctx_b = ctx_b.get_client_validation_context(); - let (stored_id_target_client_on_source, source_prefix) = - client_val_ctx_b.counterparty_meta(id_source_client_on_target)?; + let (stored_id_target_client_on_source, source_prefix) = client_val_ctx_b + .counterparty_meta(id_source_client_on_target)? + .ok_or(ChannelError::MissingCounterparty)?; if &stored_id_target_client_on_source != id_target_client_on_source { return Err(ChannelError::MismatchCounterparty { diff --git a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs index e8196aa5a..b1a15110d 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -42,8 +42,9 @@ pub fn send_packet_validate( let id_target_client_on_source = channel_target_client_on_source.as_ref(); let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); - let (stored_id_source_client_on_target, _) = - client_val_ctx_a.counterparty_meta(id_target_client_on_source)?; + let (stored_id_source_client_on_target, _) = client_val_ctx_a + .counterparty_meta(id_target_client_on_source)? + .ok_or(ChannelError::MissingCounterparty)?; if &stored_id_source_client_on_target != id_source_client_on_target { return Err(ChannelError::MismatchCounterparty { diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs index d96feaa82..24ac17f31 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs @@ -130,8 +130,9 @@ where let client_val_ctx_a = ctx_a.get_client_validation_context(); - let (stored_id_source_client_on_target, target_prefix) = - client_val_ctx_a.counterparty_meta(id_target_client_on_source)?; + let (stored_id_source_client_on_target, target_prefix) = client_val_ctx_a + .counterparty_meta(id_target_client_on_source)? + .ok_or(ChannelError::MissingCounterparty)?; if &stored_id_source_client_on_target != id_source_client_on_target { return Err(ChannelError::MismatchCounterparty { diff --git a/ibc-eureka-core/ics25-handler/src/entrypoint.rs b/ibc-eureka-core/ics25-handler/src/entrypoint.rs index 69010d5d6..6044cab33 100644 --- a/ibc-eureka-core/ics25-handler/src/entrypoint.rs +++ b/ibc-eureka-core/ics25-handler/src/entrypoint.rs @@ -4,7 +4,9 @@ use ibc_eureka_core_channel::handler::{ }; use ibc_eureka_core_channel::types::msgs::{packet_msg_to_port_id, PacketMsg}; use ibc_eureka_core_client::context::{ClientExecutionContext, ClientValidationContext}; -use ibc_eureka_core_client::handler::{create_client, update_client, upgrade_client}; +use ibc_eureka_core_client::handler::{ + create_client, provide_counterparty, update_client, upgrade_client, +}; use ibc_eureka_core_client::types::error::ClientError; use ibc_eureka_core_client::types::msgs::{ClientMsg, MsgUpdateOrMisbehaviour}; use ibc_eureka_core_handler_types::error::HandlerError; @@ -60,6 +62,7 @@ where // Recover client messages are not dispatched by ibc-rs as they can only be // authorized via a passing governance proposal } + ClientMsg::ProvideCounterparty(msg) => provide_counterparty::validate(ctx, msg)?, }, MsgEnvelope::Packet(msg) => { let port_id = packet_msg_to_port_id(&msg); @@ -105,6 +108,7 @@ where // Recover client messages are not dispatched by ibc-rs as they can only be // authorized via a passing governance proposal } + ClientMsg::ProvideCounterparty(msg) => provide_counterparty::execute(ctx, msg)?, }, MsgEnvelope::Packet(msg) => { let port_id = packet_msg_to_port_id(&msg);