Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pass ChannelId by value instead of reference since it impls Copy #542

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/537-channel-id-u64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Crate] Pass ChannelId by value instead of reference since it impls Copy
([#537](https://github.com/cosmos/ibc-rs/issues/537))
2 changes: 1 addition & 1 deletion crates/ibc/src/applications/transfer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub(crate) mod test {
let connection_hops = vec![ConnectionId::new(1)];
let port_id = PortId::transfer();
let channel_id = ChannelId::new(1);
let counterparty = Counterparty::new(port_id.clone(), Some(channel_id.clone()));
let counterparty = Counterparty::new(port_id.clone(), Some(channel_id));

(
ctx,
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn refund_packet_token_execute(

if is_sender_chain_source(
packet.port_id_on_a.clone(),
packet.chan_id_on_a.clone(),
packet.chan_id_on_a,
&data.token.denom,
) {
// unescrow tokens back to sender
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn refund_packet_token_validate(

if is_sender_chain_source(
packet.port_id_on_a.clone(),
packet.chan_id_on_a.clone(),
packet.chan_id_on_a,
&data.token.denom,
) {
let escrow_address =
Expand Down
6 changes: 3 additions & 3 deletions crates/ibc/src/applications/transfer/relay/on_recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub fn process_recv_packet_execute<Ctx: TokenTransferExecutionContext>(

let extras = if is_receiver_chain_source(
packet.port_id_on_a.clone(),
packet.chan_id_on_a.clone(),
packet.chan_id_on_a,
&data.token.denom,
) {
// sender chain is not the source, unescrow tokens
let prefix = TracePrefix::new(packet.port_id_on_a.clone(), packet.chan_id_on_a.clone());
let prefix = TracePrefix::new(packet.port_id_on_a.clone(), packet.chan_id_on_a);
let coin = {
let mut c = data.token;
c.denom.remove_trace_prefix(&prefix);
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn process_recv_packet_execute<Ctx: TokenTransferExecutionContext>(
ModuleExtras::empty()
} else {
// sender chain is the source, mint vouchers
let prefix = TracePrefix::new(packet.port_id_on_b.clone(), packet.chan_id_on_b.clone());
let prefix = TracePrefix::new(packet.port_id_on_b.clone(), packet.chan_id_on_b);
let coin = {
let mut c = data.token;
c.denom.add_trace_prefix(prefix);
Expand Down
32 changes: 14 additions & 18 deletions crates/ibc/src/applications/transfer/relay/send_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ where
.map_err(TokenTransferError::ContextError)?;

let port_id_on_b = chan_end_on_a.counterparty().port_id().clone();
let chan_id_on_b = chan_end_on_a
.counterparty()
.channel_id()
.ok_or_else(|| TokenTransferError::DestinationChannelNotFound {
let chan_id_on_b = chan_end_on_a.counterparty().channel_id().ok_or_else(|| {
TokenTransferError::DestinationChannelNotFound {
port_id: msg.port_id_on_a.clone(),
channel_id: msg.chan_id_on_a.clone(),
})?
.clone();
channel_id: msg.chan_id_on_a,
}
})?;

let seq_send_path_on_a = SeqSendPath::new(&msg.port_id_on_a, &msg.chan_id_on_a);
let sequence = ctx_a
Expand All @@ -70,7 +68,7 @@ where
.try_into()
.map_err(|_| TokenTransferError::ParseAccountFailure)?;

if is_sender_chain_source(msg.port_id_on_a.clone(), msg.chan_id_on_a.clone(), &denom) {
if is_sender_chain_source(msg.port_id_on_a.clone(), msg.chan_id_on_a, &denom) {
let escrow_address = ctx_a.get_escrow_account(&msg.port_id_on_a, &msg.chan_id_on_a)?;
ctx_a.send_coins_validate(&sender, &escrow_address, &coin)?;
} else {
Expand All @@ -91,7 +89,7 @@ where
port_id_on_a: msg.port_id_on_a,
chan_id_on_a: msg.chan_id_on_a,
port_id_on_b,
chan_id_on_b,
chan_id_on_b: *chan_id_on_b,
data,
timeout_height_on_b: msg.timeout_height_on_b,
timeout_timestamp_on_b: msg.timeout_timestamp_on_b,
Expand All @@ -116,14 +114,12 @@ where
.map_err(TokenTransferError::ContextError)?;

let port_on_b = chan_end_on_a.counterparty().port_id().clone();
let chan_on_b = chan_end_on_a
.counterparty()
.channel_id()
.ok_or_else(|| TokenTransferError::DestinationChannelNotFound {
let chan_on_b = chan_end_on_a.counterparty().channel_id().ok_or_else(|| {
TokenTransferError::DestinationChannelNotFound {
port_id: msg.port_id_on_a.clone(),
channel_id: msg.chan_id_on_a.clone(),
})?
.clone();
channel_id: msg.chan_id_on_a,
}
})?;

// get the next sequence
let seq_send_path_on_a = SeqSendPath::new(&msg.port_id_on_a, &msg.chan_id_on_a);
Expand All @@ -147,7 +143,7 @@ where
.try_into()
.map_err(|_| TokenTransferError::ParseAccountFailure)?;

if is_sender_chain_source(msg.port_id_on_a.clone(), msg.chan_id_on_a.clone(), &denom) {
if is_sender_chain_source(msg.port_id_on_a.clone(), msg.chan_id_on_a, &denom) {
let escrow_address = ctx_a.get_escrow_account(&msg.port_id_on_a, &msg.chan_id_on_a)?;
ctx_a.send_coins_execute(&sender, &escrow_address, &coin)?;
} else {
Expand All @@ -168,7 +164,7 @@ where
port_id_on_a: msg.port_id_on_a,
chan_id_on_a: msg.chan_id_on_a,
port_id_on_b: port_on_b,
chan_id_on_b: chan_on_b,
chan_id_on_b: *chan_on_b,
data,
timeout_height_on_b: msg.timeout_height_on_b,
timeout_timestamp_on_b: msg.timeout_timestamp_on_b,
Expand Down
11 changes: 4 additions & 7 deletions crates/ibc/src/core/context/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where
{
let commitment_path_on_a = CommitmentPath {
port_id: msg.packet.port_id_on_a.clone(),
channel_id: msg.packet.chan_id_on_a.clone(),
channel_id: msg.packet.chan_id_on_a,
sequence: msg.packet.seq_on_a,
};
ctx_a.delete_packet_commitment(&commitment_path_on_a)?;
Expand Down Expand Up @@ -177,10 +177,7 @@ mod tests {
let chan_end_on_a_unordered = ChannelEnd::new(
State::Open,
Order::Unordered,
Counterparty::new(
packet.port_id_on_b.clone(),
Some(packet.chan_id_on_b.clone()),
),
Counterparty::new(packet.port_id_on_b.clone(), Some(packet.chan_id_on_b)),
vec![ConnectionId::default()],
Version::new("ics20-1".to_string()),
);
Expand Down Expand Up @@ -236,7 +233,7 @@ mod tests {
.with_connection(ConnectionId::default(), conn_end_on_a)
.with_packet_commitment(
msg.packet.port_id_on_a.clone(),
msg.packet.chan_id_on_a.clone(),
msg.packet.chan_id_on_a,
msg.packet.seq_on_a,
packet_commitment,
);
Expand Down Expand Up @@ -272,7 +269,7 @@ mod tests {
.with_connection(ConnectionId::default(), conn_end_on_a)
.with_packet_commitment(
msg.packet.port_id_on_a.clone(),
msg.packet.chan_id_on_a.clone(),
msg.packet.chan_id_on_a,
msg.packet.seq_on_a,
packet_commitment,
);
Expand Down
7 changes: 3 additions & 4 deletions crates/ibc/src/core/context/chan_close_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ where
let chan_id_on_a = chan_end_on_b
.counterparty()
.channel_id
.clone()
.ok_or(ContextError::ChannelError(ChannelError::Other {
description:
"internal error: ChannelEnd doesn't have a counterparty channel id in CloseInit"
Expand All @@ -73,7 +72,7 @@ where

IbcEvent::CloseConfirmChannel(CloseConfirm::new(
msg.port_id_on_b.clone(),
msg.chan_id_on_b.clone(),
msg.chan_id_on_b,
port_id_on_a,
chan_id_on_a,
conn_id_on_b,
Expand Down Expand Up @@ -145,7 +144,7 @@ mod tests {
Order::default(),
Counterparty::new(
msg_chan_close_confirm.port_id_on_b.clone(),
Some(msg_chan_close_confirm.chan_id_on_b.clone()),
Some(msg_chan_close_confirm.chan_id_on_b),
),
vec![conn_id.clone()],
Version::default(),
Expand All @@ -156,7 +155,7 @@ mod tests {
.with_connection(conn_id, conn_end)
.with_channel(
msg_chan_close_confirm.port_id_on_b.clone(),
msg_chan_close_confirm.chan_id_on_b.clone(),
msg_chan_close_confirm.chan_id_on_b,
chan_end,
);

Expand Down
7 changes: 3 additions & 4 deletions crates/ibc/src/core/context/chan_close_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ where
let chan_id_on_b = chan_end_on_a
.counterparty()
.channel_id
.clone()
.ok_or(ContextError::ChannelError(ChannelError::Other {
description:
"internal error: ChannelEnd doesn't have a counterparty channel id in CloseInit"
Expand All @@ -73,7 +72,7 @@ where

IbcEvent::CloseInitChannel(CloseInit::new(
msg.port_id_on_a.clone(),
msg.chan_id_on_a.clone(),
msg.chan_id_on_a,
port_id_on_b,
chan_id_on_b,
conn_id_on_a,
Expand Down Expand Up @@ -141,7 +140,7 @@ mod tests {
Order::default(),
Counterparty::new(
msg_chan_close_init.port_id_on_a.clone(),
Some(msg_chan_close_init.chan_id_on_a.clone()),
Some(msg_chan_close_init.chan_id_on_a),
),
vec![conn_id.clone()],
Version::default(),
Expand All @@ -160,7 +159,7 @@ mod tests {
.with_connection(conn_id, conn_end)
.with_channel(
msg_chan_close_init.port_id_on_a.clone(),
msg_chan_close_init.chan_id_on_a.clone(),
msg_chan_close_init.chan_id_on_a,
chan_end,
)
};
Expand Down
12 changes: 4 additions & 8 deletions crates/ibc/src/core/context/chan_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where

chan_end_on_a.set_state(State::Open);
chan_end_on_a.set_version(msg.version_on_b.clone());
chan_end_on_a.set_counterparty_channel_id(msg.chan_id_on_b.clone());
chan_end_on_a.set_counterparty_channel_id(msg.chan_id_on_b);

chan_end_on_a
};
Expand All @@ -70,7 +70,7 @@ where

IbcEvent::OpenAckChannel(OpenAck::new(
msg.port_id_on_a.clone(),
msg.chan_id_on_a.clone(),
msg.chan_id_on_a,
port_id_on_b,
msg.chan_id_on_b,
conn_id_on_a,
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
let chan_end_on_a = ChannelEnd::new(
State::Init,
Order::Unordered,
Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_b.clone())),
Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_b)),
vec![conn_id_on_a.clone()],
msg.version_on_b.clone(),
);
Expand Down Expand Up @@ -191,11 +191,7 @@ mod tests {
let mut context = context
.with_client(&client_id_on_a, Height::new(0, proof_height).unwrap())
.with_connection(conn_id_on_a, conn_end_on_a)
.with_channel(
msg.port_id_on_a.clone(),
msg.chan_id_on_a.clone(),
chan_end_on_a,
);
.with_channel(msg.port_id_on_a.clone(), msg.chan_id_on_a, chan_end_on_a);

let res = chan_open_ack_execute(&mut context, module_id, msg);

Expand Down
3 changes: 1 addition & 2 deletions crates/ibc/src/core/context/chan_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ where
let chan_id_on_a = chan_end_on_b
.counterparty()
.channel_id
.clone()
.ok_or(ContextError::ChannelError(ChannelError::Other {
description:
"internal error: ChannelEnd doesn't have a counterparty channel id in OpenConfirm"
Expand All @@ -74,7 +73,7 @@ where

let core_event = IbcEvent::OpenConfirmChannel(OpenConfirm::new(
msg.port_id_on_b.clone(),
msg.chan_id_on_b.clone(),
msg.chan_id_on_b,
port_id_on_a,
chan_id_on_a,
conn_id_on_b,
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/core/context/chan_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
));
let core_event = IbcEvent::OpenInitChannel(OpenInit::new(
msg.port_id_on_a.clone(),
chan_id_on_a.clone(),
chan_id_on_a,
msg.port_id_on_b,
conn_id_on_a,
version,
Expand Down
10 changes: 5 additions & 5 deletions crates/ibc/src/core/context/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ where
&msg.connection_hops_on_b,
&msg.port_id_on_b,
&chan_id_on_b,
&Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a.clone())),
&Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a)),
&msg.version_supported_on_a,
)?;

Expand All @@ -56,7 +56,7 @@ where
&msg.connection_hops_on_b,
&msg.port_id_on_b,
&chan_id_on_b,
&Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a.clone())),
&Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a)),
&msg.version_supported_on_a,
)?;

Expand All @@ -67,7 +67,7 @@ where
let chan_end_on_b = ChannelEnd::new(
State::TryOpen,
msg.ordering,
Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a.clone())),
Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a)),
msg.connection_hops_on_b.clone(),
version.clone(),
);
Expand Down Expand Up @@ -95,9 +95,9 @@ where

let core_event = IbcEvent::OpenTryChannel(OpenTry::new(
msg.port_id_on_b.clone(),
chan_id_on_b.clone(),
chan_id_on_b,
msg.port_id_on_a.clone(),
msg.chan_id_on_a.clone(),
msg.chan_id_on_a,
conn_id_on_b,
version,
));
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/core/context/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
Order::Unordered => {
let receipt_path_on_b = ReceiptPath {
port_id: msg.packet.port_id_on_b.clone(),
channel_id: msg.packet.chan_id_on_b.clone(),
channel_id: msg.packet.chan_id_on_b,
sequence: msg.packet.seq_on_a,
};

Expand Down
Loading