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/modules/src/applications/transfer/context.rs b/modules/src/applications/transfer/context.rs index 89ca094396..53f36337ef 100644 --- a/modules/src/applications/transfer/context.rs +++ b/modules/src/applications/transfer/context.rs @@ -35,7 +35,7 @@ pub trait Ics20Reader: ChannelReader { fn get_channel_escrow_address( &self, port_id: &PortId, - channel_id: ChannelId, + channel_id: &ChannelId, ) -> Result<::AccountId, Ics20Error> { let hash = cosmos_adr028_escrow_address(port_id, channel_id); String::from_utf8(hex::encode_upper(hash)) @@ -60,7 +60,7 @@ pub trait Ics20Reader: ChannelReader { } // https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md -fn cosmos_adr028_escrow_address(port_id: &PortId, channel_id: ChannelId) -> Vec { +fn cosmos_adr028_escrow_address(port_id: &PortId, channel_id: &ChannelId) -> Vec { let contents = format!("{}/{}", port_id, channel_id); let mut hasher = Sha256::new(); @@ -112,13 +112,9 @@ fn validate_transfer_channel_params( ctx: &mut impl Ics20Context, order: Order, port_id: &PortId, - channel_id: &ChannelId, + _channel_id: &ChannelId, version: &Version, ) -> Result<(), Ics20Error> { - if channel_id.sequence() > (u32::MAX as u64) { - return Err(Ics20Error::chan_seq_exceeds_limit(channel_id.sequence())); - } - if order != Order::Unordered { return Err(Ics20Error::channel_not_unordered(order)); } @@ -321,7 +317,7 @@ pub(crate) mod test { let port_id = port_id.parse().unwrap(); let channel_id = channel_id.parse().unwrap(); let gen_address = { - let addr = cosmos_adr028_escrow_address(&port_id, channel_id); + let addr = cosmos_adr028_escrow_address(&port_id, &channel_id); bech32::encode("cosmos", addr) }; assert_eq!(gen_address, address.to_owned()) diff --git a/modules/src/applications/transfer/error.rs b/modules/src/applications/transfer/error.rs index d509a9a69b..e5d0e794b9 100644 --- a/modules/src/applications/transfer/error.rs +++ b/modules/src/applications/transfer/error.rs @@ -88,10 +88,6 @@ define_error! { [ TraceError ] | _ | { "invalid hex string" }, - ChanSeqExceedsLimit - { sequence: u64 } - | e | { format_args!("channel sequence ({0}) exceeds limit of {1}", e.sequence, u32::MAX) }, - ChannelNotUnordered { order: Order } | e | { format_args!("expected '{0}' channel, got '{1}'", Order::Unordered, e.order) }, diff --git a/modules/src/applications/transfer/relay.rs b/modules/src/applications/transfer/relay.rs index 63fb15103b..f5e0e166ce 100644 --- a/modules/src/applications/transfer/relay.rs +++ b/modules/src/applications/transfer/relay.rs @@ -24,12 +24,12 @@ fn refund_packet_token( if is_sender_chain_source( packet.source_port.clone(), - packet.source_channel, + packet.source_channel.clone(), &data.token.denom, ) { // unescrow tokens back to sender let escrow_address = - ctx.get_channel_escrow_address(&packet.source_port, packet.source_channel)?; + ctx.get_channel_escrow_address(&packet.source_port, &packet.source_channel)?; ctx.send_coins(&escrow_address, &sender, &data.token) } diff --git a/modules/src/applications/transfer/relay/on_recv_packet.rs b/modules/src/applications/transfer/relay/on_recv_packet.rs index f6069ee10a..7ebdc4d727 100644 --- a/modules/src/applications/transfer/relay/on_recv_packet.rs +++ b/modules/src/applications/transfer/relay/on_recv_packet.rs @@ -25,11 +25,11 @@ pub fn process_recv_packet( if is_receiver_chain_source( packet.source_port.clone(), - packet.source_channel, + packet.source_channel.clone(), &data.token.denom, ) { // sender chain is not the source, unescrow tokens - let prefix = TracePrefix::new(packet.source_port.clone(), packet.source_channel); + let prefix = TracePrefix::new(packet.source_port.clone(), packet.source_channel.clone()); let coin = { let mut c = data.token; c.denom.remove_trace_prefix(&prefix); @@ -37,7 +37,7 @@ pub fn process_recv_packet( }; let escrow_address = - ctx.get_channel_escrow_address(&packet.destination_port, packet.destination_channel)?; + ctx.get_channel_escrow_address(&packet.destination_port, &packet.destination_channel)?; Ok(Box::new(move |ctx| { let ctx = ctx.downcast_mut::().unwrap(); @@ -46,7 +46,10 @@ pub fn process_recv_packet( })) } else { // sender chain is the source, mint vouchers - let prefix = TracePrefix::new(packet.destination_port.clone(), packet.destination_channel); + let prefix = TracePrefix::new( + packet.destination_port.clone(), + packet.destination_channel.clone(), + ); let coin = { let mut c = data.token; c.denom.add_trace_prefix(prefix); diff --git a/modules/src/applications/transfer/relay/send_transfer.rs b/modules/src/applications/transfer/relay/send_transfer.rs index 6925c6776c..34229e8c7c 100644 --- a/modules/src/applications/transfer/relay/send_transfer.rs +++ b/modules/src/applications/transfer/relay/send_transfer.rs @@ -26,21 +26,26 @@ where return Err(Error::send_disabled()); } + let source_channel_key = (msg.source_port.clone(), msg.source_channel.clone()); let source_channel_end = ctx - .channel_end(&(msg.source_port.clone(), msg.source_channel)) + .channel_end(&source_channel_key) .map_err(Error::ics04_channel)?; let destination_port = source_channel_end.counterparty().port_id().clone(); - let destination_channel = *source_channel_end + let destination_channel = source_channel_end .counterparty() .channel_id() .ok_or_else(|| { - Error::destination_channel_not_found(msg.source_port.clone(), msg.source_channel) - })?; + Error::destination_channel_not_found( + msg.source_port.clone(), + msg.source_channel.clone(), + ) + })? + .clone(); // get the next sequence let sequence = ctx - .get_next_sequence_send(&(msg.source_port.clone(), msg.source_channel)) + .get_next_sequence_send(&source_channel_key) .map_err(Error::ics04_channel)?; let token = msg.token.try_into().map_err(|_| Error::invalid_token())?; @@ -56,9 +61,9 @@ where .try_into() .map_err(|_| Error::parse_account_failure())?; - if is_sender_chain_source(msg.source_port.clone(), msg.source_channel, &denom) { + if is_sender_chain_source(msg.source_port.clone(), msg.source_channel.clone(), &denom) { let escrow_address = - ctx.get_channel_escrow_address(&msg.source_port, msg.source_channel)?; + ctx.get_channel_escrow_address(&msg.source_port, &msg.source_channel)?; ctx.send_coins(&sender, &escrow_address, &coin)?; } else { ctx.burn_coins(&sender, &coin)?; diff --git a/modules/src/clients/ics07_tendermint/client_def.rs b/modules/src/clients/ics07_tendermint/client_def.rs index d81e42e6a7..7a72a65d0a 100644 --- a/modules/src/clients/ics07_tendermint/client_def.rs +++ b/modules/src/clients/ics07_tendermint/client_def.rs @@ -246,7 +246,7 @@ impl ClientDef for TendermintClient { ) -> Result<(), Ics02Error> { client_state.verify_height(height)?; - let path = ChannelEndsPath(port_id.clone(), *channel_id); + let path = ChannelEndsPath(port_id.clone(), channel_id.clone()); let value = expected_channel_end .encode_vec() .map_err(Ics02Error::invalid_channel_end)?; @@ -290,7 +290,7 @@ impl ClientDef for TendermintClient { let commitment_path = CommitmentsPath { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), sequence, }; @@ -322,7 +322,7 @@ impl ClientDef for TendermintClient { let ack_path = AcksPath { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), sequence, }; verify_membership( @@ -355,7 +355,7 @@ impl ClientDef for TendermintClient { .encode(&mut seq_bytes) .expect("buffer size too small"); - let seq_path = SeqRecvsPath(port_id.clone(), *channel_id); + let seq_path = SeqRecvsPath(port_id.clone(), channel_id.clone()); verify_membership( client_state, connection_end.counterparty().prefix(), @@ -383,7 +383,7 @@ impl ClientDef for TendermintClient { let receipt_path = ReceiptsPath { port_id: port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), sequence, }; verify_non_membership( diff --git a/modules/src/core/ics04_channel/context.rs b/modules/src/core/ics04_channel/context.rs index 3102d817bb..c734ca3591 100644 --- a/modules/src/core/ics04_channel/context.rs +++ b/modules/src/core/ics04_channel/context.rs @@ -144,7 +144,7 @@ pub trait ChannelKeeper { fn store_channel_result(&mut self, result: ChannelResult) -> Result<(), Error> { // The handler processed this channel & some modifications occurred, store the new end. self.store_channel( - (result.port_id.clone(), result.channel_id), + (result.port_id.clone(), result.channel_id.clone()), &result.channel_end, )?; @@ -156,12 +156,18 @@ pub trait ChannelKeeper { // Associate also the channel end to its connection. self.store_connection_channels( result.channel_end.connection_hops()[0].clone(), - &(result.port_id.clone(), result.channel_id), + &(result.port_id.clone(), result.channel_id.clone()), )?; // Initialize send, recv, and ack sequence numbers. - self.store_next_sequence_send((result.port_id.clone(), result.channel_id), 1.into())?; - self.store_next_sequence_recv((result.port_id.clone(), result.channel_id), 1.into())?; + self.store_next_sequence_send( + (result.port_id.clone(), result.channel_id.clone()), + 1.into(), + )?; + self.store_next_sequence_recv( + (result.port_id.clone(), result.channel_id.clone()), + 1.into(), + )?; self.store_next_sequence_ack((result.port_id, result.channel_id), 1.into())?; } @@ -172,12 +178,12 @@ pub trait ChannelKeeper { match general_result { PacketResult::Send(res) => { self.store_next_sequence_send( - (res.port_id.clone(), res.channel_id), + (res.port_id.clone(), res.channel_id.clone()), res.seq_number, )?; self.store_packet_commitment( - (res.port_id.clone(), res.channel_id, res.seq), + (res.port_id.clone(), res.channel_id.clone(), res.seq), res.commitment, )?; } @@ -220,9 +226,9 @@ pub trait ChannelKeeper { PacketResult::Timeout(res) => { if let Some(c) = res.channel { //Ordered Channel - self.store_channel((res.port_id.clone(), res.channel_id), &c)?; + self.store_channel((res.port_id.clone(), res.channel_id.clone()), &c)?; } - self.delete_packet_commitment((res.port_id.clone(), res.channel_id, res.seq))?; + self.delete_packet_commitment((res.port_id, res.channel_id, res.seq))?; } } Ok(()) diff --git a/modules/src/core/ics04_channel/events.rs b/modules/src/core/ics04_channel/events.rs index 49ee2d308f..21e74e0a3f 100644 --- a/modules/src/core/ics04_channel/events.rs +++ b/modules/src/core/ics04_channel/events.rs @@ -626,7 +626,7 @@ impl TryFrom for CloseInit { Ok(CloseInit { height: attrs.height, port_id: attrs.port_id.clone(), - channel_id: *channel_id, + channel_id: channel_id.clone(), connection_id: attrs.connection_id.clone(), counterparty_port_id: attrs.counterparty_port_id.clone(), counterparty_channel_id: attrs.counterparty_channel_id, diff --git a/modules/src/core/ics04_channel/handler/acknowledgement.rs b/modules/src/core/ics04_channel/handler/acknowledgement.rs index dccf8c947d..e5d6eb6d67 100644 --- a/modules/src/core/ics04_channel/handler/acknowledgement.rs +++ b/modules/src/core/ics04_channel/handler/acknowledgement.rs @@ -28,21 +28,21 @@ pub fn process( let packet = &msg.packet; let source_channel_end = - ctx.channel_end(&(packet.source_port.clone(), packet.source_channel))?; + ctx.channel_end(&(packet.source_port.clone(), packet.source_channel.clone()))?; if !source_channel_end.state_matches(&State::Open) { - return Err(Error::channel_closed(packet.source_channel)); + return Err(Error::channel_closed(packet.source_channel.clone())); } let counterparty = Counterparty::new( packet.destination_port.clone(), - Some(packet.destination_channel), + Some(packet.destination_channel.clone()), ); if !source_channel_end.counterparty_matches(&counterparty) { return Err(Error::invalid_packet_counterparty( packet.destination_port.clone(), - packet.destination_channel, + packet.destination_channel.clone(), )); } @@ -57,7 +57,7 @@ pub fn process( // Verify packet commitment let packet_commitment = ctx.get_packet_commitment(&( packet.source_port.clone(), - packet.source_channel, + packet.source_channel.clone(), packet.sequence, ))?; @@ -82,8 +82,8 @@ pub fn process( )?; let result = if source_channel_end.order_matches(&Order::Ordered) { - let next_seq_ack = - ctx.get_next_sequence_ack(&(packet.source_port.clone(), packet.source_channel))?; + let next_seq_ack = ctx + .get_next_sequence_ack(&(packet.source_port.clone(), packet.source_channel.clone()))?; if packet.sequence != next_seq_ack { return Err(Error::invalid_packet_sequence( @@ -94,14 +94,14 @@ pub fn process( PacketResult::Ack(AckPacketResult { port_id: packet.source_port.clone(), - channel_id: packet.source_channel, + channel_id: packet.source_channel.clone(), seq: packet.sequence, seq_number: Some(next_seq_ack.increment()), }) } else { PacketResult::Ack(AckPacketResult { port_id: packet.source_port.clone(), - channel_id: packet.source_channel, + channel_id: packet.source_channel.clone(), seq: packet.sequence, seq_number: None, }) @@ -168,7 +168,7 @@ mod tests { Order::default(), Counterparty::new( packet.destination_port.clone(), - Some(packet.destination_channel), + Some(packet.destination_channel.clone()), ), vec![ConnectionId::default()], Version::ics20(), @@ -200,7 +200,7 @@ mod tests { .with_connection(ConnectionId::default(), connection_end) .with_channel( packet.source_port.clone(), - packet.source_channel, + packet.source_channel.clone(), source_channel_end, ) .with_packet_commitment( diff --git a/modules/src/core/ics04_channel/handler/chan_close_confirm.rs b/modules/src/core/ics04_channel/handler/chan_close_confirm.rs index 60cee080f9..7cf4e3ccda 100644 --- a/modules/src/core/ics04_channel/handler/chan_close_confirm.rs +++ b/modules/src/core/ics04_channel/handler/chan_close_confirm.rs @@ -18,11 +18,11 @@ pub(crate) fn process( let mut output = HandlerOutput::builder(); // Retrieve the old channel end and validate it against the message. - let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id))?; + let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id.clone()))?; // Validate that the channel end is in a state where it can be closed. if channel_end.state_matches(&State::Closed) { - return Err(Error::channel_closed(msg.channel_id)); + return Err(Error::channel_closed(msg.channel_id.clone())); } // An OPEN IBC connection running on the local (host) chain should exist. @@ -44,7 +44,8 @@ pub(crate) fn process( // Proof verification in two steps: // 1. Setup: build the Channel as we expect to find it on the other party. - let expected_counterparty = Counterparty::new(msg.port_id.clone(), Some(msg.channel_id)); + let expected_counterparty = + Counterparty::new(msg.port_id.clone(), Some(msg.channel_id.clone())); let counterparty = conn.counterparty(); let ccid = counterparty.connection_id().ok_or_else(|| { @@ -77,13 +78,13 @@ pub(crate) fn process( let result = ChannelResult { port_id: msg.port_id.clone(), - channel_id: msg.channel_id, + channel_id: msg.channel_id.clone(), channel_id_state: ChannelIdState::Reused, channel_end, }; let event_attributes = Attributes { - channel_id: Some(msg.channel_id), + channel_id: Some(msg.channel_id.clone()), height: ctx.host_height(), ..Default::default() }; @@ -146,7 +147,7 @@ mod tests { Order::default(), Counterparty::new( msg_chan_close_confirm.port_id.clone(), - Some(msg_chan_close_confirm.channel_id), + Some(msg_chan_close_confirm.channel_id.clone()), ), vec![conn_id.clone()], Version::default(), @@ -157,7 +158,7 @@ mod tests { .with_connection(conn_id, conn_end) .with_channel( msg_chan_close_confirm.port_id.clone(), - msg_chan_close_confirm.channel_id, + msg_chan_close_confirm.channel_id.clone(), chan_end, ); diff --git a/modules/src/core/ics04_channel/handler/chan_close_init.rs b/modules/src/core/ics04_channel/handler/chan_close_init.rs index 3e503a7753..bb05022a9e 100644 --- a/modules/src/core/ics04_channel/handler/chan_close_init.rs +++ b/modules/src/core/ics04_channel/handler/chan_close_init.rs @@ -16,12 +16,12 @@ pub(crate) fn process( let mut output = HandlerOutput::builder(); // Unwrap the old channel end and validate it against the message. - let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id))?; + let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id.clone()))?; // Validate that the channel end is in a state where it can be closed. if channel_end.state_matches(&State::Closed) { return Err(Error::invalid_channel_state( - msg.channel_id, + msg.channel_id.clone(), channel_end.state, )); } @@ -49,13 +49,13 @@ pub(crate) fn process( let result = ChannelResult { port_id: msg.port_id.clone(), - channel_id: msg.channel_id, + channel_id: msg.channel_id.clone(), channel_id_state: ChannelIdState::Reused, channel_end, }; let event_attributes = Attributes { - channel_id: Some(msg.channel_id), + channel_id: Some(msg.channel_id.clone()), height: ctx.host_height(), ..Default::default() }; @@ -114,7 +114,7 @@ mod tests { Order::default(), Counterparty::new( msg_chan_close_init.port_id.clone(), - Some(msg_chan_close_init.channel_id), + Some(msg_chan_close_init.channel_id.clone()), ), vec![conn_id.clone()], Version::default(), @@ -129,7 +129,7 @@ mod tests { .with_connection(conn_id, conn_end) .with_channel( msg_chan_close_init.port_id.clone(), - msg_chan_close_init.channel_id, + msg_chan_close_init.channel_id.clone(), chan_end, ) }; diff --git a/modules/src/core/ics04_channel/handler/chan_open_ack.rs b/modules/src/core/ics04_channel/handler/chan_open_ack.rs index e3fe9adc19..918c225ec7 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_ack.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_ack.rs @@ -18,12 +18,12 @@ pub(crate) fn process( let mut output = HandlerOutput::builder(); // Unwrap the old channel end and validate it against the message. - let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id))?; + let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id.clone()))?; // Validate that the channel end is in a state where it can be ack. if !channel_end.state_matches(&State::Init) && !channel_end.state_matches(&State::TryOpen) { return Err(Error::invalid_channel_state( - msg.channel_id, + msg.channel_id.clone(), channel_end.state, )); } @@ -48,7 +48,8 @@ pub(crate) fn process( // Proof verification in two steps: // 1. Setup: build the Channel as we expect to find it on the other party. - let expected_counterparty = Counterparty::new(msg.port_id.clone(), Some(msg.channel_id)); + let expected_counterparty = + Counterparty::new(msg.port_id.clone(), Some(msg.channel_id.clone())); let counterparty = conn.counterparty(); let ccid = counterparty.connection_id().ok_or_else(|| { @@ -66,7 +67,7 @@ pub(crate) fn process( ); // set the counterparty channel id to verify against it - channel_end.set_counterparty_channel_id(msg.counterparty_channel_id); + channel_end.set_counterparty_channel_id(msg.counterparty_channel_id.clone()); //2. Verify proofs verify_channel_proofs( @@ -86,13 +87,13 @@ pub(crate) fn process( let result = ChannelResult { port_id: msg.port_id.clone(), - channel_id: msg.channel_id, + channel_id: msg.channel_id.clone(), channel_id_state: ChannelIdState::Reused, channel_end, }; let event_attributes = Attributes { - channel_id: Some(msg.channel_id), + channel_id: Some(msg.channel_id.clone()), height: ctx.host_height(), ..Default::default() }; @@ -194,7 +195,10 @@ mod tests { let chan_end = ChannelEnd::new( State::Init, *msg_chan_try.channel.ordering(), - Counterparty::new(msg_chan_ack.port_id.clone(), Some(msg_chan_ack.channel_id)), + Counterparty::new( + msg_chan_ack.port_id.clone(), + Some(msg_chan_ack.channel_id.clone()), + ), connection_vec0.clone(), msg_chan_try.channel.version().clone(), ); @@ -202,7 +206,10 @@ mod tests { let failed_chan_end = ChannelEnd::new( State::Open, *msg_chan_try.channel.ordering(), - Counterparty::new(msg_chan_ack.port_id.clone(), Some(msg_chan_ack.channel_id)), + Counterparty::new( + msg_chan_ack.port_id.clone(), + Some(msg_chan_ack.channel_id.clone()), + ), connection_vec0, msg_chan_try.channel.version().clone(), ); @@ -224,7 +231,7 @@ mod tests { ) .with_channel( msg_chan_ack.port_id.clone(), - msg_chan_ack.channel_id, + msg_chan_ack.channel_id.clone(), failed_chan_end, ), msg: ChannelMsg::ChannelOpenAck(msg_chan_ack.clone()), @@ -240,7 +247,7 @@ mod tests { ) .with_channel( msg_chan_ack.port_id.clone(), - msg_chan_ack.channel_id, + msg_chan_ack.channel_id.clone(), chan_end.clone(), ), msg: ChannelMsg::ChannelOpenAck(msg_chan_ack.clone()), @@ -253,7 +260,7 @@ mod tests { .with_connection(cid.clone(), conn_end.clone()) .with_channel( msg_chan_ack.port_id.clone(), - msg_chan_ack.channel_id, + msg_chan_ack.channel_id.clone(), chan_end.clone(), ), msg: ChannelMsg::ChannelOpenAck(msg_chan_ack.clone()), @@ -269,7 +276,7 @@ mod tests { .with_connection(cid, conn_end) .with_channel( msg_chan_ack.port_id.clone(), - msg_chan_ack.channel_id, + msg_chan_ack.channel_id.clone(), chan_end, ), msg: ChannelMsg::ChannelOpenAck(msg_chan_ack), diff --git a/modules/src/core/ics04_channel/handler/chan_open_confirm.rs b/modules/src/core/ics04_channel/handler/chan_open_confirm.rs index 37b3d1744a..7c5c575227 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_confirm.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_confirm.rs @@ -18,12 +18,12 @@ pub(crate) fn process( let mut output = HandlerOutput::builder(); // Unwrap the old channel end and validate it against the message. - let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id))?; + let mut channel_end = ctx.channel_end(&(msg.port_id.clone(), msg.channel_id.clone()))?; // Validate that the channel end is in a state where it can be confirmed. if !channel_end.state_matches(&State::TryOpen) { return Err(Error::invalid_channel_state( - msg.channel_id, + msg.channel_id.clone(), channel_end.state, )); } @@ -47,7 +47,8 @@ pub(crate) fn process( // Proof verification in two steps: // 1. Setup: build the Channel as we expect to find it on the other party. - let expected_counterparty = Counterparty::new(msg.port_id.clone(), Some(msg.channel_id)); + let expected_counterparty = + Counterparty::new(msg.port_id.clone(), Some(msg.channel_id.clone())); let connection_counterparty = conn.counterparty(); let ccid = connection_counterparty.connection_id().ok_or_else(|| { @@ -81,13 +82,13 @@ pub(crate) fn process( let result = ChannelResult { port_id: msg.port_id.clone(), - channel_id: msg.channel_id, + channel_id: msg.channel_id.clone(), channel_id_state: ChannelIdState::Reused, channel_end, }; let event_attributes = Attributes { - channel_id: Some(msg.channel_id), + channel_id: Some(msg.channel_id.clone()), height: ctx.host_height(), ..Default::default() }; @@ -159,7 +160,7 @@ mod tests { Order::default(), Counterparty::new( msg_chan_confirm.port_id.clone(), - Some(msg_chan_confirm.channel_id), + Some(msg_chan_confirm.channel_id.clone()), ), vec![conn_id.clone()], Version::default(), @@ -175,7 +176,7 @@ mod tests { .with_connection(conn_id, conn_end) .with_channel( msg_chan_confirm.port_id.clone(), - msg_chan_confirm.channel_id, + msg_chan_confirm.channel_id.clone(), chan_end, ), msg: ChannelMsg::ChannelOpenConfirm(msg_chan_confirm), diff --git a/modules/src/core/ics04_channel/handler/chan_open_init.rs b/modules/src/core/ics04_channel/handler/chan_open_init.rs index 9a7bff9ff7..40d1cdddc7 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_init.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_init.rs @@ -58,7 +58,7 @@ pub(crate) fn process( let result = ChannelResult { port_id: msg.port_id.clone(), - channel_id: chan_id, + channel_id: chan_id.clone(), channel_end: new_channel_end, channel_id_state: ChannelIdState::Generated, }; diff --git a/modules/src/core/ics04_channel/handler/chan_open_try.rs b/modules/src/core/ics04_channel/handler/chan_open_try.rs index d4bba28f5c..a289beba98 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_try.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_try.rs @@ -22,7 +22,7 @@ pub(crate) fn process( // Unwrap the old channel end (if any) and validate it against the message. let (mut new_channel_end, channel_id) = match &msg.previous_channel_id { Some(prev_id) => { - let old_channel_end = ctx.channel_end(&(msg.port_id.clone(), *prev_id))?; + let old_channel_end = ctx.channel_end(&(msg.port_id.clone(), prev_id.clone()))?; // Validate that existing channel end matches with the one we're trying to establish. if old_channel_end.state_matches(&State::Init) @@ -32,10 +32,10 @@ pub(crate) fn process( && old_channel_end.version_matches(msg.channel.version()) { // A ChannelEnd already exists and all validation passed. - Ok((old_channel_end, *prev_id)) + Ok((old_channel_end, prev_id.clone())) } else { // A ConnectionEnd already exists and validation failed. - Err(Error::channel_mismatch(*prev_id)) + Err(Error::channel_mismatch(prev_id.clone())) } } // No previous channel id was supplied. Create a new channel end & an identifier. @@ -129,7 +129,7 @@ pub(crate) fn process( } else { ChannelIdState::Reused }, - channel_id, + channel_id: channel_id.clone(), channel_end: new_channel_end, }; @@ -209,7 +209,7 @@ mod tests { // this channel should depend on connection `conn_id`. let chan_id = ChannelId::new(24); let hops = vec![conn_id.clone()]; - msg.previous_channel_id = Some(chan_id); + msg.previous_channel_id = Some(chan_id.clone()); msg.channel.connection_hops = hops; // This message does not assume a channel should already be initialized. @@ -256,7 +256,7 @@ mod tests { want_pass: false, match_error: { let port_id = msg.port_id.clone(); - let channel_id = chan_id; + let channel_id = chan_id.clone(); Box::new(move |e| match e { error::ErrorDetail::ChannelNotFound(e) => { assert_eq!(e.port_id, port_id); @@ -296,11 +296,11 @@ mod tests { ctx: context .clone() .with_connection(conn_id.clone(), conn_end.clone()) - .with_channel(msg.port_id.clone(), chan_id, incorrect_chan_end_ver), + .with_channel(msg.port_id.clone(), chan_id.clone(), incorrect_chan_end_ver), msg: ChannelMsg::ChannelOpenTry(msg.clone()), want_pass: false, match_error: { - let channel_id = chan_id; + let channel_id = chan_id.clone(); Box::new(move |e| match e { error::ErrorDetail::ChannelMismatch(e) => { assert_eq!(e.channel_id, channel_id); @@ -316,11 +316,15 @@ mod tests { ctx: context .clone() .with_connection(conn_id.clone(), conn_end.clone()) - .with_channel(msg.port_id.clone(), chan_id, incorrect_chan_end_hops), + .with_channel( + msg.port_id.clone(), + chan_id.clone(), + incorrect_chan_end_hops, + ), msg: ChannelMsg::ChannelOpenTry(msg.clone()), want_pass: false, match_error: { - let channel_id = chan_id; + let channel_id = chan_id.clone(); Box::new(move |e| match e { error::ErrorDetail::ChannelMismatch(e) => { assert_eq!(e.channel_id, channel_id); @@ -336,7 +340,11 @@ mod tests { ctx: context .clone() .with_connection(conn_id.clone(), conn_end.clone()) - .with_channel(msg.port_id.clone(), chan_id, correct_chan_end.clone()), + .with_channel( + msg.port_id.clone(), + chan_id.clone(), + correct_chan_end.clone(), + ), msg: ChannelMsg::ChannelOpenTry(msg.clone()), want_pass: false, match_error: Box::new(|e| match e { diff --git a/modules/src/core/ics04_channel/handler/recv_packet.rs b/modules/src/core/ics04_channel/handler/recv_packet.rs index 37c3db9011..5ae4cd65ef 100644 --- a/modules/src/core/ics04_channel/handler/recv_packet.rs +++ b/modules/src/core/ics04_channel/handler/recv_packet.rs @@ -32,22 +32,27 @@ pub fn process(ctx: &dyn ChannelReader, msg: &MsgRecvPacket) -> HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult HandlerResult { let mut output = HandlerOutput::builder(); - let dest_channel_end = - ctx.channel_end(&(packet.destination_port.clone(), packet.destination_channel))?; + let dest_channel_end = ctx.channel_end(&( + packet.destination_port.clone(), + packet.destination_channel.clone(), + ))?; if !dest_channel_end.state_matches(&State::Open) { return Err(Error::invalid_channel_state( @@ -40,7 +42,7 @@ pub fn process( // set on the store and return an error if so. match ctx.get_packet_acknowledgement(&( packet.destination_port.clone(), - packet.destination_channel, + packet.destination_channel.clone(), packet.sequence, )) { Ok(_) => return Err(Error::acknowledgement_exists(packet.sequence)), @@ -55,7 +57,7 @@ pub fn process( let result = PacketResult::WriteAck(WriteAckPacketResult { port_id: packet.source_port.clone(), - channel_id: packet.source_channel, + channel_id: packet.source_channel.clone(), seq: packet.sequence, ack_commitment: ctx.ack_commitment(ack.clone().into()), }); @@ -116,7 +118,10 @@ mod tests { let dest_channel_end = ChannelEnd::new( State::Open, Order::default(), - Counterparty::new(packet.source_port.clone(), Some(packet.source_channel)), + Counterparty::new( + packet.source_port.clone(), + Some(packet.source_channel.clone()), + ), vec![ConnectionId::default()], Version::ics20(), ); @@ -149,7 +154,7 @@ mod tests { .with_connection(ConnectionId::default(), connection_end.clone()) .with_channel( packet.destination_port.clone(), - packet.destination_channel, + packet.destination_channel.clone(), dest_channel_end.clone(), ), packet: packet.clone(), diff --git a/modules/src/core/ics04_channel/msgs/chan_close_confirm.rs b/modules/src/core/ics04_channel/msgs/chan_close_confirm.rs index f075a4c0b2..48b641576a 100644 --- a/modules/src/core/ics04_channel/msgs/chan_close_confirm.rs +++ b/modules/src/core/ics04_channel/msgs/chan_close_confirm.rs @@ -187,7 +187,7 @@ mod tests { name: "Bad channel, name too long".to_string(), raw: RawMsgChannelCloseConfirm { channel_id: - "channel-12839128379182739812739879" + "channel-128391283791827398127398791283912837918273981273987912839" .to_string(), ..default_raw_msg.clone() }, diff --git a/modules/src/core/ics04_channel/msgs/chan_close_init.rs b/modules/src/core/ics04_channel/msgs/chan_close_init.rs index ceb85b5421..846d66e794 100644 --- a/modules/src/core/ics04_channel/msgs/chan_close_init.rs +++ b/modules/src/core/ics04_channel/msgs/chan_close_init.rs @@ -156,7 +156,7 @@ mod tests { Test { name: "Bad channel, name too long".to_string(), raw: RawMsgChannelCloseInit { - channel_id: "channel-12839128379182739812739879".to_string(), + channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), ..default_raw_msg }, want_pass: false, diff --git a/modules/src/core/ics04_channel/msgs/chan_open_ack.rs b/modules/src/core/ics04_channel/msgs/chan_open_ack.rs index 25b4ae1088..8d6dfef831 100644 --- a/modules/src/core/ics04_channel/msgs/chan_open_ack.rs +++ b/modules/src/core/ics04_channel/msgs/chan_open_ack.rs @@ -200,7 +200,7 @@ mod tests { Test { name: "Bad channel, name too long".to_string(), raw: RawMsgChannelOpenAck { - channel_id: "channel-12839128379182739812739879".to_string(), + channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), ..default_raw_msg.clone() }, want_pass: false, @@ -224,7 +224,7 @@ mod tests { Test { name: "[Counterparty] Bad channel, name too long".to_string(), raw: RawMsgChannelOpenAck { - counterparty_channel_id: "channel-12839128379182739812739879".to_string(), + counterparty_channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), ..default_raw_msg.clone() }, want_pass: false, diff --git a/modules/src/core/ics04_channel/msgs/chan_open_confirm.rs b/modules/src/core/ics04_channel/msgs/chan_open_confirm.rs index a37bc84c8e..c7a547759e 100644 --- a/modules/src/core/ics04_channel/msgs/chan_open_confirm.rs +++ b/modules/src/core/ics04_channel/msgs/chan_open_confirm.rs @@ -180,7 +180,7 @@ mod tests { Test { name: "Bad channel, name too long".to_string(), raw: RawMsgChannelOpenConfirm { - channel_id: "channel-12839128379182739812739879".to_string(), + channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), ..default_raw_msg.clone() }, want_pass: false, diff --git a/modules/src/core/ics04_channel/msgs/chan_open_try.rs b/modules/src/core/ics04_channel/msgs/chan_open_try.rs index 358c0c979d..6dfb2c874e 100644 --- a/modules/src/core/ics04_channel/msgs/chan_open_try.rs +++ b/modules/src/core/ics04_channel/msgs/chan_open_try.rs @@ -227,7 +227,7 @@ mod tests { Test { name: "Bad channel, name too long".to_string(), raw: RawMsgChannelOpenTry { - previous_channel_id: "channel-12839128379182739812739879".to_string(), + previous_channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), ..default_raw_msg.clone() }, want_pass: false, diff --git a/modules/src/core/ics04_channel/packet.rs b/modules/src/core/ics04_channel/packet.rs index 6efc76a7ea..efd41a1168 100644 --- a/modules/src/core/ics04_channel/packet.rs +++ b/modules/src/core/ics04_channel/packet.rs @@ -467,7 +467,7 @@ mod tests { Test { name: "Bad src channel, name too long".to_string(), raw: RawPacket { - source_channel: "channel-12839128379182739812739879".to_string(), + source_channel: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), ..default_raw_packet.clone() }, want_pass: false, @@ -491,7 +491,7 @@ mod tests { Test { name: "Bad dst channel, name too long".to_string(), raw: RawPacket { - destination_channel: "channel-12839128379182739812739879".to_string(), + destination_channel: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), ..default_raw_packet.clone() }, want_pass: false, diff --git a/modules/src/core/ics24_host/error.rs b/modules/src/core/ics24_host/error.rs index de71ad7974..0221414211 100644 --- a/modules/src/core/ics24_host/error.rs +++ b/modules/src/core/ics24_host/error.rs @@ -1,6 +1,4 @@ -use core::num::ParseIntError; - -use flex_error::{define_error, TraceError}; +use flex_error::define_error; use serde::Serialize; use crate::prelude::*; @@ -32,13 +30,6 @@ define_error! { { id: String } | e | { format_args!("chain identifiers are expected to be in epoch format {0}", e.id) }, - ChannelIdInvalidFormat - | _ | { "channel identifiers are expected to be in `channel-{N}` format" }, - - ChannelIdParseFailure - [ TraceError ] - | _ | { "failed to parse channel identifier" }, - InvalidCounterpartyChannelId |_| { "Invalid channel id in counterparty" } } diff --git a/modules/src/core/ics24_host/identifier.rs b/modules/src/core/ics24_host/identifier.rs index 21f53b9363..230c9622ea 100644 --- a/modules/src/core/ics24_host/identifier.rs +++ b/modules/src/core/ics24_host/identifier.rs @@ -2,7 +2,7 @@ use core::convert::{From, Infallible}; use core::fmt::{self, Debug, Display, Formatter}; use core::str::FromStr; -use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Deserialize, Serialize}; use super::validate::*; use crate::core::ics02_client::client_type::ClientType; @@ -335,10 +335,12 @@ impl Default for PortId { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ChannelId(u64); +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +pub struct ChannelId(String); impl ChannelId { + const PREFIX: &'static str = "channel-"; + /// Builds a new channel identifier. Like client and connection identifiers, channel ids are /// deterministically formed from two elements: a prefix `prefix`, and a monotonically /// increasing `counter`, separated by a dash "-". @@ -351,28 +353,25 @@ impl ChannelId { /// assert_eq!(chan_id.to_string(), "channel-27"); /// ``` pub fn new(counter: u64) -> Self { - Self(counter) + let id = format!("{}{}", Self::PREFIX, counter); + Self(id) } - pub fn sequence(&self) -> u64 { - self.0 + /// Get this identifier as a borrowed `&str` + pub fn as_str(&self) -> &str { + &self.0 } - const fn prefix() -> &'static str { - "channel-" + /// Get this identifier as a borrowed byte slice + pub fn as_bytes(&self) -> &[u8] { + self.0.as_bytes() } } /// This implementation provides a `to_string` method. impl Display for ChannelId { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "{}{}", Self::prefix(), self.0) - } -} - -impl Debug for ChannelId { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { - f.debug_tuple("ChannelId").field(&self.to_string()).finish() + write!(f, "{}", self.0) } } @@ -380,37 +379,33 @@ impl FromStr for ChannelId { type Err = ValidationError; fn from_str(s: &str) -> Result { - let s = s - .strip_prefix(Self::prefix()) - .ok_or_else(ValidationError::channel_id_invalid_format)?; - let counter = u64::from_str(s).map_err(ValidationError::channel_id_parse_failure)?; - Ok(Self(counter)) + validate_channel_identifier(s).map(|_| Self(s.to_string())) } } -impl Default for ChannelId { - fn default() -> Self { - Self::new(0) +impl AsRef for ChannelId { + fn as_ref(&self) -> &str { + &self.0 } } -impl Serialize for ChannelId { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.collect_str(self) +impl Default for ChannelId { + fn default() -> Self { + Self::new(0) } } -impl<'de> Deserialize<'de> for ChannelId { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - String::deserialize(deserializer)? - .parse() - .map_err(de::Error::custom) +/// Equality check against string literal (satisfies &ChannelId == &str). +/// ``` +/// use core::str::FromStr; +/// use ibc::core::ics24_host::identifier::ChannelId; +/// let channel_id = ChannelId::from_str("channelId-0"); +/// assert!(channel_id.is_ok()); +/// channel_id.map(|id| {assert_eq!(&id, "channelId-0")}); +/// ``` +impl PartialEq for ChannelId { + fn eq(&self, other: &str) -> bool { + self.as_str().eq(other) } } diff --git a/modules/src/core/ics24_host/validate.rs b/modules/src/core/ics24_host/validate.rs index 722d35b124..0bc4163bb2 100644 --- a/modules/src/core/ics24_host/validate.rs +++ b/modules/src/core/ics24_host/validate.rs @@ -67,11 +67,19 @@ pub fn validate_port_identifier(id: &str) -> Result<(), Error> { validate_identifier(id, 2, 128) } +/// Default validator function for Channel identifiers. +/// +/// A valid identifier must be between 8-64 characters and only contain +/// alphabetic characters, +pub fn validate_channel_identifier(id: &str) -> Result<(), Error> { + validate_identifier(id, 8, 64) +} + #[cfg(test)] mod tests { use crate::core::ics24_host::validate::{ - validate_client_identifier, validate_connection_identifier, validate_identifier, - validate_port_identifier, + validate_channel_identifier, validate_client_identifier, validate_connection_identifier, + validate_identifier, validate_port_identifier, }; use test_log::test; @@ -107,6 +115,22 @@ mod tests { assert!(id.is_err()) } + #[test] + fn parse_invalid_channel_id_min() { + // invalid channel id, must be at least 8 characters + let id = validate_channel_identifier("channel"); + assert!(id.is_err()) + } + + #[test] + fn parse_channel_id_max() { + // invalid channel id (test string length is 65) + let id = validate_channel_identifier( + "ihhankr30iy4nna65hjl2wjod7182io1t2s7u3ip3wqtbbn1sl0rgcntqc540r36r", + ); + assert!(id.is_err()) + } + #[test] fn parse_invalid_client_id_min() { // invalid min client id diff --git a/modules/src/mock/context.rs b/modules/src/mock/context.rs index 644a059cbd..c868b8f020 100644 --- a/modules/src/mock/context.rs +++ b/modules/src/mock/context.rs @@ -657,7 +657,10 @@ impl ChannelReader for MockContext { fn channel_end(&self, pcid: &(PortId, ChannelId)) -> Result { match self.ibc_store.lock().unwrap().channels.get(pcid) { Some(channel_end) => Ok(channel_end.clone()), - None => Err(Ics04Error::channel_not_found(pcid.0.clone(), pcid.1)), + None => Err(Ics04Error::channel_not_found( + pcid.0.clone(), + pcid.1.clone(), + )), } } diff --git a/modules/src/test_utils.rs b/modules/src/test_utils.rs index d8be3ac7d0..15bddf2f12 100644 --- a/modules/src/test_utils.rs +++ b/modules/src/test_utils.rs @@ -240,7 +240,7 @@ impl ChannelReader for DummyTransferModule { fn channel_end(&self, pcid: &(PortId, ChannelId)) -> Result { match self.ibc_store.lock().unwrap().channels.get(pcid) { Some(channel_end) => Ok(channel_end.clone()), - None => Err(Error::channel_not_found(pcid.0.clone(), pcid.1)), + None => Err(Error::channel_not_found(pcid.0.clone(), pcid.1.clone())), } } 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,