From 6300ad32aed6c37a58a229b6ffe5dce140f13dc2 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Mon, 4 Jul 2022 15:49:20 +0200 Subject: [PATCH] Change `ChannelId` representation to `String` (#2361) ICS 024 does not restrict channel IDs to the "channel-{N}" format. Change the internal representation of ChannelId to String, and modify the API accordingly to the similar ID types. --- * Change ChannelId representation to String ICS 024 does not restrict channel IDs to the "channel-{N}" format. * More clone calls for ChannelId, clippy fixes * fmt fix * Changelog entry for #2361 * ChannelId formatting fixes - Create valid IDs with ChannelId::new (could be under valid length). - Format as the inner string with Display. - Derive Debug, no need for a manual definition, which printed it wrong. * Relax the channel identifier valid length Contrary to what is still documented in ICS 024, the minimum length accepted by ibc-go is 8 characters: https://github.com/cosmos/ibc-go/blob/e04964912c266bab923253c48d72cc8ec8b38f5e/modules/core/24-host/validate.go#L76-L81 * Add unit tests for validate_channel_identifier * Tweak test data for excessively long channel IDs The length limit is now 64 characters in accordance with ICS 024 and ibc-go, but longer than previous code admitted. * Improve changelog entries for #2361 - File under the modules component. - Add an entry to bug-fixes mentioning the corrected enforcement of the length limit on channel IDs. * Fix outdated comment * Clarify comment Co-authored-by: Romain Ruetschi --- .../ibc/2361-string-channel-id.md | 2 + .../ibc/2361-channel-id-max-len-64.md | 3 + relayer-cli/src/commands/clear.rs | 2 +- relayer-cli/src/commands/query/channel.rs | 2 +- .../src/commands/query/channel_client.rs | 2 +- .../src/commands/query/channel_ends.rs | 21 +++--- relayer-cli/src/commands/query/packet/ack.rs | 2 +- .../src/commands/query/packet/commitment.rs | 2 +- relayer-cli/src/commands/tx/channel.rs | 20 +++--- relayer-cli/src/commands/tx/packet.rs | 4 +- relayer-cli/src/commands/tx/transfer.rs | 4 +- relayer/src/chain/counterparty.rs | 24 +++---- relayer/src/chain/endpoint.rs | 4 +- relayer/src/chain/handle/base.rs | 4 +- relayer/src/chain/handle/cache.rs | 2 +- relayer/src/channel.rs | 66 +++++++++---------- relayer/src/link.rs | 33 ++++++---- relayer/src/link/packet_events.rs | 8 +-- relayer/src/link/relay_path.rs | 28 ++++---- relayer/src/object.rs | 10 +-- relayer/src/path.rs | 6 +- relayer/src/supervisor/client_state_filter.rs | 6 +- relayer/src/supervisor/scan.rs | 16 +++-- relayer/src/supervisor/spawn.rs | 4 +- relayer/src/transfer.rs | 2 +- relayer/src/worker.rs | 2 +- tools/integration-test/src/mbt/utils.rs | 8 +-- .../src/tests/execute_schedule.rs | 2 +- .../src/tests/manual/simulation.rs | 2 +- .../src/tests/query_packet.rs | 2 +- .../src/bootstrap/binary/channel.rs | 10 +-- tools/test-framework/src/relayer/channel.rs | 11 ++-- tools/test-framework/src/relayer/transfer.rs | 2 +- 33 files changed, 170 insertions(+), 146 deletions(-) create mode 100644 .changelog/unreleased/breaking-changes/ibc/2361-string-channel-id.md create mode 100644 .changelog/unreleased/bug-fixes/ibc/2361-channel-id-max-len-64.md diff --git a/.changelog/unreleased/breaking-changes/ibc/2361-string-channel-id.md b/.changelog/unreleased/breaking-changes/ibc/2361-string-channel-id.md new file mode 100644 index 0000000000..87ad2965e3 --- /dev/null +++ b/.changelog/unreleased/breaking-changes/ibc/2361-string-channel-id.md @@ -0,0 +1,2 @@ +- Change `ChannelId` representation to a string, allowing all IDs valid per ICS 024 + ([#2330](https://github.com/informalsystems/ibc-rs/issues/2330)). diff --git a/.changelog/unreleased/bug-fixes/ibc/2361-channel-id-max-len-64.md b/.changelog/unreleased/bug-fixes/ibc/2361-channel-id-max-len-64.md new file mode 100644 index 0000000000..119c2b1b08 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/ibc/2361-channel-id-max-len-64.md @@ -0,0 +1,3 @@ +- Permit channel identifiers with length up to 64 characters, + as per the ICS 024 specification. + ([#2330](https://github.com/informalsystems/ibc-rs/issues/2330)). diff --git a/relayer-cli/src/commands/clear.rs b/relayer-cli/src/commands/clear.rs index 7f91636253..9a14ab60bc 100644 --- a/relayer-cli/src/commands/clear.rs +++ b/relayer-cli/src/commands/clear.rs @@ -110,7 +110,7 @@ impl Runnable for ClearPacketsCmd { // Construct links in both directions. let opts = LinkParameters { src_port_id: self.port_id.clone(), - src_channel_id: self.channel_id, + src_channel_id: self.channel_id.clone(), }; let fwd_link = match Link::new_from_opts(chains.src.clone(), chains.dst, opts, false) { Ok(link) => link, diff --git a/relayer-cli/src/commands/query/channel.rs b/relayer-cli/src/commands/query/channel.rs index fae9ac33c3..9e64865a34 100644 --- a/relayer-cli/src/commands/query/channel.rs +++ b/relayer-cli/src/commands/query/channel.rs @@ -58,7 +58,7 @@ impl Runnable for QueryChannelEndCmd { let res = chain.query_channel( QueryChannelRequest { port_id: self.port_id.clone(), - channel_id: self.channel_id, + channel_id: self.channel_id.clone(), height: self.height.map_or(QueryHeight::Latest, |revision_height| { QueryHeight::Specific( ibc::Height::new(chain.id().version(), revision_height) diff --git a/relayer-cli/src/commands/query/channel_client.rs b/relayer-cli/src/commands/query/channel_client.rs index 02212a35e3..7af4adf19b 100644 --- a/relayer-cli/src/commands/query/channel_client.rs +++ b/relayer-cli/src/commands/query/channel_client.rs @@ -51,7 +51,7 @@ impl Runnable for QueryChannelClientCmd { match chain.query_channel_client_state(QueryChannelClientStateRequest { port_id: self.port_id.clone(), - channel_id: self.channel_id, + channel_id: self.channel_id.clone(), }) { Ok(cs) => Output::success(cs).exit(), Err(e) => Output::error(format!("{}", e)).exit(), diff --git a/relayer-cli/src/commands/query/channel_ends.rs b/relayer-cli/src/commands/query/channel_ends.rs index 34403d9623..97c9e44781 100644 --- a/relayer-cli/src/commands/query/channel_ends.rs +++ b/relayer-cli/src/commands/query/channel_ends.rs @@ -88,12 +88,15 @@ fn do_run(cmd: &QueryChannelEndsCmd) -> Result<(), Box>::new((*config).clone()); - let chain = registry.get_or_spawn(&chain_id)?; + let chain = registry.get_or_spawn(chain_id)?; let chain_height = match cmd.height { Some(height) => { @@ -105,7 +108,7 @@ fn do_run(cmd: &QueryChannelEndsCmd) -> Result<(), Box(cmd: &QueryChannelEndsCmd) -> Result<(), Box(cmd: &QueryChannelEndsCmd) -> Result<(), Box link, @@ -114,7 +114,7 @@ impl Runnable for TxRawPacketAckCmd { let opts = LinkParameters { src_port_id: self.src_port_id.clone(), - src_channel_id: self.src_channel_id, + src_channel_id: self.src_channel_id.clone(), }; let link = match Link::new_from_opts(chains.src, chains.dst, opts, false) { Ok(link) => link, diff --git a/relayer-cli/src/commands/tx/transfer.rs b/relayer-cli/src/commands/tx/transfer.rs index 387774c7f6..c43a105adb 100644 --- a/relayer-cli/src/commands/tx/transfer.rs +++ b/relayer-cli/src/commands/tx/transfer.rs @@ -144,7 +144,7 @@ impl TxIcs20MsgTransferCmd { let opts = TransferOptions { packet_src_port_id: self.src_port_id.clone(), - packet_src_channel_id: self.src_channel_id, + packet_src_channel_id: self.src_channel_id.clone(), amount: self.amount, denom, receiver: self.receiver.clone(), @@ -180,7 +180,7 @@ impl Runnable for TxIcs20MsgTransferCmd { .query_channel( QueryChannelRequest { port_id: opts.packet_src_port_id.clone(), - channel_id: opts.packet_src_channel_id, + channel_id: opts.packet_src_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, diff --git a/relayer/src/chain/counterparty.rs b/relayer/src/chain/counterparty.rs index 7a0892c4cf..9ef37c9c6a 100644 --- a/relayer/src/chain/counterparty.rs +++ b/relayer/src/chain/counterparty.rs @@ -161,7 +161,7 @@ pub fn channel_connection_client( .query_channel( QueryChannelRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -171,7 +171,7 @@ pub fn channel_connection_client( if channel_end.state_matches(&State::Uninitialized) { return Err(Error::channel_uninitialized( port_id.clone(), - *channel_id, + channel_id.clone(), chain.id(), )); } @@ -179,7 +179,7 @@ pub fn channel_connection_client( let connection_id = channel_end .connection_hops() .first() - .ok_or_else(|| Error::missing_connection_hops(*channel_id, chain.id()))?; + .ok_or_else(|| Error::missing_connection_hops(channel_id.clone(), chain.id()))?; let (connection_end, _) = chain .query_connection( @@ -194,7 +194,7 @@ pub fn channel_connection_client( if !connection_end.is_open() { return Err(Error::connection_not_open( connection_id.clone(), - *channel_id, + channel_id.clone(), chain.id(), )); } @@ -212,7 +212,7 @@ pub fn channel_connection_client( let client = IdentifiedAnyClientState::new(client_id.clone(), client_state); let connection = IdentifiedConnectionEnd::new(connection_id.clone(), connection_end); - let channel = IdentifiedChannelEnd::new(port_id.clone(), *channel_id, channel_end); + let channel = IdentifiedChannelEnd::new(port_id.clone(), channel_id.clone(), channel_end); Ok(ChannelConnectionClient::new(channel, connection, client)) } @@ -272,14 +272,14 @@ pub fn channel_on_destination( .query_channel( QueryChannelRequest { port_id: channel.channel_end.counterparty().port_id().clone(), - channel_id: *remote_channel_id, + channel_id: remote_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, ) .map(|(c, _)| IdentifiedChannelEnd { port_id: channel.channel_end.counterparty().port_id().clone(), - channel_id: *remote_channel_id, + channel_id: remote_channel_id.clone(), channel_end: c, }) .map_err(Error::relayer)?; @@ -310,7 +310,7 @@ pub fn check_channel_counterparty( .query_channel( QueryChannelRequest { port_id: target_pchan.port_id.clone(), - channel_id: target_pchan.channel_id, + channel_id: target_pchan.channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -362,7 +362,7 @@ pub fn commitments_on_chain( let (mut commit_sequences, response_height) = chain .query_packet_commitments(QueryPacketCommitmentsRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), pagination: Some(PageRequest::all()), }) .map_err(Error::relayer)?; @@ -387,7 +387,7 @@ pub fn unreceived_packets_sequences( chain .query_unreceived_packets(QueryUnreceivedPacketsRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), packet_commitment_sequences: commitments_on_counterparty, }) .map_err(Error::relayer) @@ -407,7 +407,7 @@ pub fn packet_acknowledgements( let (mut acked_sequences, response_height) = chain .query_packet_acknowledgements(QueryPacketAcknowledgementsRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), pagination: Some(PageRequest::all()), packet_commitment_sequences: commit_sequences, }) @@ -435,7 +435,7 @@ pub fn unreceived_acknowledgements_sequences( chain .query_unreceived_acknowledgements(QueryUnreceivedAcksRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), packet_ack_sequences: acks_on_counterparty, }) .map_err(Error::relayer) diff --git a/relayer/src/chain/endpoint.rs b/relayer/src/chain/endpoint.rs index bbeea6bb7b..272c8a5374 100644 --- a/relayer/src/chain/endpoint.rs +++ b/relayer/src/chain/endpoint.rs @@ -461,7 +461,7 @@ pub trait ChainEndpoint: Sized { let (_, maybe_channel_proof) = self.query_channel( QueryChannelRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), height: QueryHeight::Specific(height), }, IncludeProof::Yes, @@ -540,7 +540,7 @@ pub trait ChainEndpoint: Sized { let (_, maybe_channel_proof) = self.query_channel( QueryChannelRequest { port_id: port_id.clone(), - channel_id, + channel_id: channel_id.clone(), height: QueryHeight::Specific(height), }, IncludeProof::Yes, diff --git a/relayer/src/chain/handle/base.rs b/relayer/src/chain/handle/base.rs index 05903f2db4..ce1e998e32 100644 --- a/relayer/src/chain/handle/base.rs +++ b/relayer/src/chain/handle/base.rs @@ -371,7 +371,7 @@ impl ChainHandle for BaseChainHandle { ) -> Result { self.send(|reply_to| ChainRequest::BuildChannelProofs { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), height, reply_to, }) @@ -388,7 +388,7 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::BuildPacketProofs { packet_type, port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), sequence, height, reply_to, diff --git a/relayer/src/chain/handle/cache.rs b/relayer/src/chain/handle/cache.rs index 157e4a986a..4355b2ae5a 100644 --- a/relayer/src/chain/handle/cache.rs +++ b/relayer/src/chain/handle/cache.rs @@ -312,7 +312,7 @@ impl ChainHandle for CachingChainHandle { IncludeProof::No => { if matches!(request.height, QueryHeight::Latest) { let (result, in_cache) = self.cache.get_or_try_insert_channel_with( - &PortChannelId::new(request.channel_id, request.port_id.clone()), + &PortChannelId::new(request.channel_id.clone(), request.port_id.clone()), || { handle .query_channel(request, IncludeProof::No) diff --git a/relayer/src/channel.rs b/relayer/src/channel.rs index ced239526d..f8895e0502 100644 --- a/relayer/src/channel.rs +++ b/relayer/src/channel.rs @@ -271,7 +271,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: channel.src_port_id.clone(), - channel_id: channel.src_channel_id, + channel_id: channel.src_channel_id.clone(), height: QueryHeight::Specific(height), }, IncludeProof::No, @@ -280,7 +280,7 @@ impl Channel { let a_connection_id = a_channel.connection_hops().first().ok_or_else(|| { ChannelError::supervisor(SupervisorError::missing_connection_hops( - channel.src_channel_id, + channel.src_channel_id.clone(), chain.id(), )) })?; @@ -301,7 +301,7 @@ impl Channel { .cloned() .ok_or_else(|| { ChannelError::supervisor(SupervisorError::channel_connection_uninitialized( - channel.src_channel_id, + channel.src_channel_id.clone(), chain.id(), a_connection.counterparty().clone(), )) @@ -314,7 +314,7 @@ impl Channel { a_connection.client_id().clone(), a_connection_id.clone(), channel.src_port_id.clone(), - Some(channel.src_channel_id), + Some(channel.src_channel_id.clone()), None, ), b_side: ChannelSide::new( @@ -322,7 +322,7 @@ impl Channel { a_connection.counterparty().client_id().clone(), b_connection_id.clone(), a_channel.remote.port_id.clone(), - a_channel.remote.channel_id, + a_channel.remote.channel_id.clone(), None, ), connection_delay: a_connection.delay_period(), @@ -419,7 +419,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.a_side.port_id.clone(), - channel_id: *id, + channel_id: id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -437,7 +437,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.b_side.port_id.clone(), - channel_id: *id, + channel_id: id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -596,7 +596,7 @@ impl Channel { e })?; let channel_id = extract_channel_id(&event)?; - self.a_side.channel_id = Some(*channel_id); + self.a_side.channel_id = Some(channel_id.clone()); } // send the Try message to chain a (source) @@ -607,7 +607,7 @@ impl Channel { })?; let channel_id = extract_channel_id(&event)?; - self.a_side.channel_id = Some(*channel_id); + self.a_side.channel_id = Some(channel_id.clone()); } // send the Try message to chain b (destination) @@ -618,7 +618,7 @@ impl Channel { })?; let channel_id = extract_channel_id(&event)?; - self.b_side.channel_id = Some(*channel_id); + self.b_side.channel_id = Some(channel_id.clone()); } // send the Ack message to chain a (source) @@ -708,14 +708,14 @@ impl Channel { let channel_deps = channel_connection_client(self.src_chain(), self.src_port_id(), channel_id) - .map_err(|e| ChannelError::query_channel(*channel_id, e))?; + .map_err(|e| ChannelError::query_channel(channel_id.clone(), e))?; channel_state_on_destination( &channel_deps.channel, &channel_deps.connection, self.dst_chain(), ) - .map_err(|e| ChannelError::query_channel(*channel_id, e)) + .map_err(|e| ChannelError::query_channel(channel_id.clone(), e)) } pub fn handshake_step( @@ -905,7 +905,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, + channel_id: dst_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -918,11 +918,7 @@ impl Channel { return Err(ChannelError::missing_channel_on_destination()); } - check_destination_channel_state( - *dst_channel_id, - dst_channel, - dst_expected_channel.clone(), - )?; + check_destination_channel_state(dst_channel_id, &dst_channel, &dst_expected_channel)?; Ok(dst_expected_channel) } @@ -939,7 +935,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, + channel_id: src_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -952,7 +948,7 @@ impl Channel { self.dst_port_id().clone(), self.src_chain().id(), src_channel.counterparty().port_id().clone(), - *src_channel_id, + src_channel_id.clone(), )); } @@ -1001,9 +997,9 @@ impl Channel { .map_err(|e| ChannelError::fetch_signer(self.dst_chain().id(), e))?; let previous_channel_id = if src_channel.counterparty().channel_id.is_none() { - self.b_side.channel_id + self.b_side.channel_id.clone() } else { - src_channel.counterparty().channel_id + src_channel.counterparty().channel_id.clone() }; // Build the domain type message @@ -1069,7 +1065,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, + channel_id: src_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -1109,8 +1105,8 @@ impl Channel { // Build the domain type message let new_msg = MsgChannelOpenAck { port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, - counterparty_channel_id: *src_channel_id, + channel_id: dst_channel_id.clone(), + counterparty_channel_id: src_channel_id.clone(), counterparty_version: src_channel.version().clone(), proofs, signer, @@ -1177,7 +1173,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, + channel_id: src_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -1217,7 +1213,7 @@ impl Channel { // Build the domain type message let new_msg = MsgChannelOpenConfirm { port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, + channel_id: dst_channel_id.clone(), proofs, signer, }; @@ -1278,7 +1274,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, + channel_id: dst_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -1293,7 +1289,7 @@ impl Channel { // Build the domain type message let new_msg = MsgChannelCloseInit { port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, + channel_id: dst_channel_id.clone(), signer, }; @@ -1348,7 +1344,7 @@ impl Channel { .query_channel( QueryChannelRequest { port_id: self.src_port_id().clone(), - channel_id: *src_channel_id, + channel_id: src_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -1388,7 +1384,7 @@ impl Channel { // Build the domain type message let new_msg = MsgChannelCloseConfirm { port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, + channel_id: dst_channel_id.clone(), proofs, signer, }; @@ -1463,9 +1459,9 @@ pub enum ChannelMsgType { } fn check_destination_channel_state( - channel_id: ChannelId, - existing_channel: ChannelEnd, - expected_channel: ChannelEnd, + channel_id: &ChannelId, + existing_channel: &ChannelEnd, + expected_channel: &ChannelEnd, ) -> Result<(), ChannelError> { let good_connection_hops = existing_channel.connection_hops() == expected_channel.connection_hops(); @@ -1483,6 +1479,6 @@ fn check_destination_channel_state( if good_state && good_connection_hops && good_channel_port_ids { Ok(()) } else { - Err(ChannelError::channel_already_exist(channel_id)) + Err(ChannelError::channel_already_exist(channel_id.clone())) } } diff --git a/relayer/src/link.rs b/relayer/src/link.rs index 44bd4f7eaa..56ca8503b3 100644 --- a/relayer/src/link.rs +++ b/relayer/src/link.rs @@ -61,42 +61,50 @@ impl Link { .query_channel( QueryChannelRequest { port_id: opts.src_port_id.clone(), - channel_id: opts.src_channel_id, + channel_id: opts.src_channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, ) .map_err(|e| { - LinkError::channel_not_found(a_port_id.clone(), *a_channel_id, a_chain.id(), e) + LinkError::channel_not_found( + a_port_id.clone(), + a_channel_id.clone(), + a_chain.id(), + e, + ) })?; if !a_channel.state_matches(&ChannelState::Open) && !a_channel.state_matches(&ChannelState::Closed) { return Err(LinkError::invalid_channel_state( - *a_channel_id, + a_channel_id.clone(), a_chain.id(), )); } let b_channel_id = a_channel .counterparty() - .channel_id - .ok_or_else(|| LinkError::counterparty_channel_not_found(*a_channel_id))?; + .channel_id() + .ok_or_else(|| LinkError::counterparty_channel_not_found(a_channel_id.clone()))?; if a_channel.connection_hops().is_empty() { - return Err(LinkError::no_connection_hop(*a_channel_id, a_chain.id())); + return Err(LinkError::no_connection_hop( + a_channel_id.clone(), + a_chain.id(), + )); } // Check that the counterparty details on the destination chain matches the source chain check_channel_counterparty( b_chain.clone(), &PortChannelId { - channel_id: b_channel_id, + channel_id: b_channel_id.clone(), port_id: a_channel.counterparty().port_id.clone(), }, &PortChannelId { - channel_id: *a_channel_id, + channel_id: a_channel_id.clone(), port_id: opts.src_port_id.clone(), }, ) @@ -115,7 +123,10 @@ impl Link { .map_err(LinkError::relayer)?; if !a_connection.state_matches(&ConnectionState::Open) { - return Err(LinkError::channel_not_opened(*a_channel_id, a_chain.id())); + return Err(LinkError::channel_not_opened( + a_channel_id.clone(), + a_chain.id(), + )); } let channel = Channel { @@ -133,7 +144,7 @@ impl Link { a_connection.counterparty().client_id().clone(), a_connection.counterparty().connection_id().unwrap().clone(), a_channel.counterparty().port_id.clone(), - Some(b_channel_id), + Some(b_channel_id.clone()), None, ), connection_delay: a_connection.delay_period(), @@ -147,7 +158,7 @@ impl Link { pub fn reverse(&self, with_tx_confirmation: bool) -> Result, LinkError> { let opts = LinkParameters { src_port_id: self.a_to_b.dst_port_id().clone(), - src_channel_id: *self.a_to_b.dst_channel_id(), + src_channel_id: self.a_to_b.dst_channel_id().clone(), }; let chain_b = self.a_to_b.dst_chain().clone(); let chain_a = self.a_to_b.src_chain().clone(); diff --git a/relayer/src/link/packet_events.rs b/relayer/src/link/packet_events.rs index accce5b4d5..9b086400b0 100644 --- a/relayer/src/link/packet_events.rs +++ b/relayer/src/link/packet_events.rs @@ -68,9 +68,9 @@ pub fn query_send_packet_events( let mut query = QueryPacketEventDataRequest { event_id: WithBlockDataType::SendPacket, source_port_id: path.counterparty_port_id.clone(), - source_channel_id: path.counterparty_channel_id, + source_channel_id: path.counterparty_channel_id.clone(), destination_port_id: path.port_id.clone(), - destination_channel_id: path.channel_id, + destination_channel_id: path.channel_id.clone(), sequences, height: QueryHeight::Specific(src_query_height), }; @@ -124,9 +124,9 @@ pub fn query_write_ack_events( .query_txs(QueryTxRequest::Packet(QueryPacketEventDataRequest { event_id: WithBlockDataType::WriteAck, source_port_id: path.port_id.clone(), - source_channel_id: path.channel_id, + source_channel_id: path.channel_id.clone(), destination_port_id: path.counterparty_port_id.clone(), - destination_channel_id: path.counterparty_channel_id, + destination_channel_id: path.counterparty_channel_id.clone(), sequences, height: QueryHeight::Specific(src_query_height), })) diff --git a/relayer/src/link/relay_path.rs b/relayer/src/link/relay_path.rs index 9bce02cf54..08a5c70852 100644 --- a/relayer/src/link/relay_path.rs +++ b/relayer/src/link/relay_path.rs @@ -125,22 +125,24 @@ impl RelayPath { let src_chain_id = src_chain.id(); let dst_chain_id = dst_chain.id(); - let src_channel_id = *channel + let src_channel_id = channel .src_channel_id() - .ok_or_else(|| LinkError::missing_channel_id(src_chain.id()))?; + .ok_or_else(|| LinkError::missing_channel_id(src_chain.id()))? + .clone(); - let dst_channel_id = *channel + let dst_channel_id = channel .dst_channel_id() - .ok_or_else(|| LinkError::missing_channel_id(dst_chain.id()))?; + .ok_or_else(|| LinkError::missing_channel_id(dst_chain.id()))? + .clone(); let src_port_id = channel.src_port_id().clone(); let dst_port_id = channel.dst_port_id().clone(); let path = PathIdentifiers { port_id: dst_port_id.clone(), - channel_id: dst_channel_id, + channel_id: dst_channel_id.clone(), counterparty_port_id: src_port_id.clone(), - counterparty_channel_id: src_channel_id, + counterparty_channel_id: src_channel_id.clone(), }; Ok(Self { @@ -206,7 +208,7 @@ impl RelayPath { .query_channel( QueryChannelRequest { port_id: self.src_port_id().clone(), - channel_id: *self.src_channel_id(), + channel_id: self.src_channel_id().clone(), height: height_query, }, IncludeProof::No, @@ -220,7 +222,7 @@ impl RelayPath { .query_channel( QueryChannelRequest { port_id: self.dst_port_id().clone(), - channel_id: *self.dst_channel_id(), + channel_id: self.dst_channel_id().clone(), height: height_query, }, IncludeProof::No, @@ -339,7 +341,7 @@ impl RelayPath { // Build the domain type message let new_msg = MsgChannelCloseConfirm { port_id: self.dst_port_id().clone(), - channel_id: *self.dst_channel_id(), + channel_id: self.dst_channel_id().clone(), proofs, signer: self.dst_signer()?, }; @@ -780,7 +782,7 @@ impl RelayPath { .dst_chain() .query_unreceived_packets(QueryUnreceivedPacketsRequest { port_id: self.dst_port_id().clone(), - channel_id: *self.dst_channel_id(), + channel_id: self.dst_channel_id().clone(), packet_commitment_sequences: vec![packet.sequence], }) .map_err(LinkError::relayer)?; @@ -796,7 +798,7 @@ impl RelayPath { .query_packet_commitment( QueryPacketCommitmentRequest { port_id: self.src_port_id().clone(), - channel_id: *self.src_channel_id(), + channel_id: self.src_channel_id().clone(), sequence: packet.sequence, height: QueryHeight::Latest, }, @@ -821,7 +823,7 @@ impl RelayPath { .dst_chain() .query_unreceived_acknowledgements(QueryUnreceivedAcksRequest { port_id: self.dst_port_id().clone(), - channel_id: *self.dst_channel_id(), + channel_id: self.dst_channel_id().clone(), packet_ack_sequences: vec![packet.sequence], }) .map_err(LinkError::relayer)?; @@ -1211,7 +1213,7 @@ impl RelayPath { .query_next_sequence_receive( QueryNextSequenceReceiveRequest { port_id: self.dst_port_id().clone(), - channel_id: *dst_channel_id, + channel_id: dst_channel_id.clone(), height: QueryHeight::Specific(height), }, IncludeProof::No, diff --git a/relayer/src/object.rs b/relayer/src/object.rs index 5ab8911595..ccd976b212 100644 --- a/relayer/src/object.rs +++ b/relayer/src/object.rs @@ -394,7 +394,7 @@ impl Object { Ok(Channel { dst_chain_id, src_chain_id: src_chain.id(), - src_channel_id: *channel_id, + src_channel_id: channel_id.clone(), src_port_id: attributes.port_id().clone(), } .into()) @@ -415,7 +415,7 @@ impl Object { Ok(Packet { dst_chain_id, src_chain_id: src_chain.id(), - src_channel_id: e.packet.source_channel, + src_channel_id: e.packet.source_channel.clone(), src_port_id: e.packet.source_port.clone(), } .into()) @@ -436,7 +436,7 @@ impl Object { Ok(Packet { dst_chain_id, src_chain_id: src_chain.id(), - src_channel_id: e.packet.destination_channel, + src_channel_id: e.packet.destination_channel.clone(), src_port_id: e.packet.destination_port.clone(), } .into()) @@ -457,7 +457,7 @@ impl Object { Ok(Packet { dst_chain_id, src_chain_id: src_chain.id(), - src_channel_id: *e.src_channel_id(), + src_channel_id: e.src_channel_id().clone(), src_port_id: e.src_port_id().clone(), } .into()) @@ -474,7 +474,7 @@ impl Object { Ok(Packet { dst_chain_id, src_chain_id: src_chain.id(), - src_channel_id: *e.channel_id(), + src_channel_id: e.channel_id().clone(), src_port_id: e.port_id().clone(), } .into()) diff --git a/relayer/src/path.rs b/relayer/src/path.rs index e15d7648ab..278ff34812 100644 --- a/relayer/src/path.rs +++ b/relayer/src/path.rs @@ -19,14 +19,14 @@ impl From<&IdentifiedChannelEnd> for PathIdentifiers { fn from(ice: &IdentifiedChannelEnd) -> Self { let counterparty = ice.channel_end.counterparty(); let counterparty_channel_id = counterparty - .channel_id + .channel_id() .expect("no channel identifier in counterparty channel end"); Self { port_id: ice.port_id.clone(), - channel_id: ice.channel_id, + channel_id: ice.channel_id.clone(), counterparty_port_id: counterparty.port_id.clone(), - counterparty_channel_id, + counterparty_channel_id: counterparty_channel_id.clone(), } } } diff --git a/relayer/src/supervisor/client_state_filter.rs b/relayer/src/supervisor/client_state_filter.rs index 0e9e49de24..4fa5d6c127 100644 --- a/relayer/src/supervisor/client_state_filter.rs +++ b/relayer/src/supervisor/client_state_filter.rs @@ -306,7 +306,7 @@ impl FilterPolicy { port_id: &PortId, channel_id: &ChannelId, ) -> Result { - let identifier = CacheKey::Channel(chain_id.clone(), port_id.clone(), *channel_id); + let identifier = CacheKey::Channel(chain_id.clone(), port_id.clone(), channel_id.clone()); trace!( "[client filter] controlling permissions for {:?}", @@ -327,7 +327,7 @@ impl FilterPolicy { .query_channel( QueryChannelRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -369,7 +369,7 @@ impl FilterPolicy { conn_id, )?; - let key = CacheKey::Channel(chain_id.clone(), port_id.clone(), *channel_id); + let key = CacheKey::Channel(chain_id.clone(), port_id.clone(), channel_id.clone()); debug!( "[client filter] {:?}: relay for channel {:?}: ", diff --git a/relayer/src/supervisor/scan.rs b/relayer/src/supervisor/scan.rs index d2c44d788e..946cc989eb 100644 --- a/relayer/src/supervisor/scan.rs +++ b/relayer/src/supervisor/scan.rs @@ -353,7 +353,7 @@ impl<'a, Chain: ChainHandle> ChainScanner<'a, Chain> { connection_scan .channels - .entry(channel.channel_id) + .entry(channel.channel_id.clone()) .or_insert_with(|| ChannelScan::new(channel, counterparty_channel)); } Err(e) => error!(channel = %channel_id, "failed to scan channel, reason: {}", e), @@ -489,7 +489,7 @@ impl<'a, Chain: ChainHandle> ChainScanner<'a, Chain> { counterparty, }; - (*scan.id(), scan) + (scan.id().clone(), scan) }) .collect(); @@ -627,7 +627,7 @@ fn scan_allowed_channel( { return Err(Error::uninitialized_channel( port_id.clone(), - *channel_id, + channel_id.clone(), chain.id(), )); } @@ -716,7 +716,7 @@ fn query_channel( .query_channel( QueryChannelRequest { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -725,7 +725,7 @@ fn query_channel( Ok(IdentifiedChannelEnd::new( port_id.clone(), - *channel_id, + channel_id.clone(), channel_end, )) } @@ -740,7 +740,11 @@ fn query_connection_for_channel( .first() .cloned() .ok_or_else(|| { - Error::missing_connection_hop(channel.port_id.clone(), channel.channel_id, chain.id()) + Error::missing_connection_hop( + channel.port_id.clone(), + channel.channel_id.clone(), + chain.id(), + ) })?; query_connection(chain, &connection_id) diff --git a/relayer/src/supervisor/spawn.rs b/relayer/src/supervisor/spawn.rs index 469dac4b7b..c3e6f2ae12 100644 --- a/relayer/src/supervisor/spawn.rs +++ b/relayer/src/supervisor/spawn.rs @@ -278,7 +278,7 @@ impl<'a, Chain: ChainHandle> SpawnContext<'a, Chain> { let path_object = Object::Packet(Packet { dst_chain_id: counterparty_chain.id(), src_chain_id: chain.id(), - src_channel_id: *channel_scan.id(), + src_channel_id: channel_scan.channel.channel_id.clone(), src_port_id: channel_scan.channel.port_id.clone(), }); @@ -302,7 +302,7 @@ impl<'a, Chain: ChainHandle> SpawnContext<'a, Chain> { let channel_object = Object::Channel(Channel { dst_chain_id: counterparty_chain.id(), src_chain_id: chain.id(), - src_channel_id: *channel_scan.id(), + src_channel_id: channel_scan.channel.channel_id, src_port_id: channel_scan.channel.port_id, }); diff --git a/relayer/src/transfer.rs b/relayer/src/transfer.rs index 89c7222c73..fd2a7cb504 100644 --- a/relayer/src/transfer.rs +++ b/relayer/src/transfer.rs @@ -167,7 +167,7 @@ pub fn build_and_send_transfer_messages( chains.b, LinkParameters { src_port_id: path.src_port_id.clone(), - src_channel_id: path.src_channel_id, + src_channel_id: path.src_channel_id.clone(), }, packets_config.tx_confirmation, ); diff --git a/tools/integration-test/src/mbt/utils.rs b/tools/integration-test/src/mbt/utils.rs index 1245f3d6b2..2233946397 100644 --- a/tools/integration-test/src/mbt/utils.rs +++ b/tools/integration-test/src/mbt/utils.rs @@ -83,7 +83,7 @@ pub fn get_unreceived_packets_at_dst( let channel_id_a = channel.channel_id_a.value(); let request = QueryUnreceivedPacketsRequest { port_id: port_id_a.clone(), - channel_id: *channel_id_a, + channel_id: channel_id_a.clone(), packet_commitment_sequences: Vec::new(), }; Ok(chain.query_unreceived_packets(request)?) @@ -97,7 +97,7 @@ pub fn get_committed_packets_at_src( let channel_id_a = channel.channel_id_a.value(); let request = QueryPacketCommitmentsRequest { port_id: port_id_a.clone(), - channel_id: *channel_id_a, + channel_id: channel_id_a.clone(), pagination: None, }; let (sequences, _) = chain.query_packet_commitments(request)?; @@ -112,7 +112,7 @@ pub fn get_unacknowledged_packets_at_src let channel_id_a = channel.channel_id_a.value(); let request = QueryPacketAcknowledgementsRequest { port_id: port_id_a.clone(), - channel_id: *channel_id_a, + channel_id: channel_id_a.clone(), pagination: None, packet_commitment_sequences: Vec::new(), }; diff --git a/tools/integration-test/src/tests/execute_schedule.rs b/tools/integration-test/src/tests/execute_schedule.rs index 96f374e609..0a75ca6d26 100644 --- a/tools/integration-test/src/tests/execute_schedule.rs +++ b/tools/integration-test/src/tests/execute_schedule.rs @@ -45,7 +45,7 @@ impl BinaryChannelTest for ExecuteScheduleTest { let chain_a_link_opts = LinkParameters { src_port_id: channel.port_a.clone().into_value(), - src_channel_id: channel.channel_id_a.into_value(), + src_channel_id: channel.channel_id_a.clone().into_value(), }; let chain_a_link = Link::new_from_opts( diff --git a/tools/integration-test/src/tests/manual/simulation.rs b/tools/integration-test/src/tests/manual/simulation.rs index 6419ab37a4..df62833202 100644 --- a/tools/integration-test/src/tests/manual/simulation.rs +++ b/tools/integration-test/src/tests/manual/simulation.rs @@ -83,7 +83,7 @@ fn tx_raw_ft_transfer( ) -> Result, Error> { let transfer_options = TransferOptions { packet_src_port_id: channel.port_a.value().clone(), - packet_src_channel_id: *channel.channel_id_a.value(), + packet_src_channel_id: channel.channel_id_a.value().clone(), amount: amount.into(), denom: denom.value().to_string(), receiver: Some(recipient.value().0.clone()), diff --git a/tools/integration-test/src/tests/query_packet.rs b/tools/integration-test/src/tests/query_packet.rs index 86480cfdce..c556e65cf3 100644 --- a/tools/integration-test/src/tests/query_packet.rs +++ b/tools/integration-test/src/tests/query_packet.rs @@ -59,7 +59,7 @@ impl BinaryChannelTest for QueryPacketPendingTest { let opts = LinkParameters { src_port_id: channel.port_a.clone().into_value(), - src_channel_id: channel.channel_id_a.into_value(), + src_channel_id: channel.channel_id_a.clone().into_value(), }; let link = Link::new_from_opts( chains.handle_a().clone(), diff --git a/tools/test-framework/src/bootstrap/binary/channel.rs b/tools/test-framework/src/bootstrap/binary/channel.rs index 04a2698fd8..9cde04e708 100644 --- a/tools/test-framework/src/bootstrap/binary/channel.rs +++ b/tools/test-framework/src/bootstrap/binary/channel.rs @@ -107,15 +107,17 @@ pub fn bootstrap_channel_with_connection TaggedChannelEndExt for DualTagged { fn tagged_counterparty_channel_id(&self) -> Option> { - self.contra_map(|c| c.counterparty().channel_id).transpose() + self.contra_map(|c| c.counterparty().channel_id.clone()) + .transpose() } fn tagged_counterparty_port_id(&self) -> TaggedPortId { @@ -64,7 +65,7 @@ pub fn init_channel( let event = channel.build_chan_open_init_and_send()?; - let channel_id = *extract_channel_id(&event)?; + let channel_id = extract_channel_id(&event)?.clone(); let channel2 = Channel::restore_from_event(handle_b.clone(), handle_a.clone(), event)?; @@ -79,7 +80,7 @@ pub fn query_channel_end( let (channel_end, _) = handle.query_channel( QueryChannelRequest { port_id: port_id.into_value().clone(), - channel_id: *channel_id.into_value(), + channel_id: channel_id.into_value().clone(), height: QueryHeight::Latest, }, IncludeProof::No, @@ -96,14 +97,14 @@ pub fn query_identified_channel_end( let (channel_end, _) = handle.query_channel( QueryChannelRequest { port_id: port_id.into_value().clone(), - channel_id: *channel_id.into_value(), + channel_id: channel_id.into_value().clone(), height: QueryHeight::Latest, }, IncludeProof::No, )?; Ok(DualTagged::new(IdentifiedChannelEnd::new( port_id.into_value().clone(), - *channel_id.into_value(), + channel_id.into_value().clone(), channel_end, ))) } diff --git a/tools/test-framework/src/relayer/transfer.rs b/tools/test-framework/src/relayer/transfer.rs index 5ab1bd0573..3a9f2c0bca 100644 --- a/tools/test-framework/src/relayer/transfer.rs +++ b/tools/test-framework/src/relayer/transfer.rs @@ -48,7 +48,7 @@ pub fn build_transfer_message( Ok(raw_build_transfer_message( (*port_id.value()).clone(), - **channel_id.value(), + (*channel_id.value()).clone(), amount.into(), denom.to_string(), sender,