Skip to content

Commit

Permalink
Model ChannelId as newtype u64 and improve validation (informalsyst…
Browse files Browse the repository at this point in the history
  • Loading branch information
hu55a1n1 authored Apr 8, 2022
1 parent cc91e30 commit f70748d
Show file tree
Hide file tree
Showing 24 changed files with 106 additions and 134 deletions.
1 change: 1 addition & 0 deletions .changelog/unreleased/improvements/ibc/2068-chan-id-u64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Improve `ChannelId` validation. ([#2068](https://github.com/informalsystems/ibc-rs/issues/2068))
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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.clone(),
src_channel_id: self.channel_id,
};
let fwd_link = match Link::new_from_opts(chains.src.clone(), chains.dst, opts, false) {
Ok(link) => link,
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/query/channel_ends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn do_run<Chain: ChainHandle>(cmd: &QueryChannelEndsCmd) -> Result<(), Box<dyn s

let chain_id = cmd.chain_id.clone();
let port_id = cmd.port_id.clone();
let channel_id = cmd.channel_id.clone();
let channel_id = cmd.channel_id;

let mut registry = <Registry<Chain>>::new((*config).clone());
let chain = registry.get_or_spawn(&chain_id)?;
Expand Down
20 changes: 10 additions & 10 deletions relayer-cli/src/commands/tx/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ impl Runnable for TxRawChanOpenTryCmd {
ClientId::default(),
ConnectionId::default(),
self.src_port_id.clone(),
Some(self.src_chan_id.clone()),
Some(self.src_chan_id),
None,
),
b_side: ChannelSide::new(
chains.dst,
dst_connection.client_id().clone(),
self.dst_conn_id.clone(),
self.dst_port_id.clone(),
self.dst_chan_id.clone(),
self.dst_chan_id,
None,
),
}
Expand Down Expand Up @@ -242,15 +242,15 @@ impl Runnable for TxRawChanOpenAckCmd {
ClientId::default(),
ConnectionId::default(),
self.src_port_id.clone(),
Some(self.src_chan_id.clone()),
Some(self.src_chan_id),
None,
),
b_side: ChannelSide::new(
chains.dst,
dst_connection.client_id().clone(),
self.dst_conn_id.clone(),
self.dst_port_id.clone(),
Some(self.dst_chan_id.clone()),
Some(self.dst_chan_id),
None,
),
}
Expand Down Expand Up @@ -310,15 +310,15 @@ impl Runnable for TxRawChanOpenConfirmCmd {
ClientId::default(),
ConnectionId::default(),
self.src_port_id.clone(),
Some(self.src_chan_id.clone()),
Some(self.src_chan_id),
None,
),
b_side: ChannelSide::new(
chains.dst,
dst_connection.client_id().clone(),
self.dst_conn_id.clone(),
self.dst_port_id.clone(),
Some(self.dst_chan_id.clone()),
Some(self.dst_chan_id),
None,
),
}
Expand Down Expand Up @@ -378,15 +378,15 @@ impl Runnable for TxRawChanCloseInitCmd {
ClientId::default(),
ConnectionId::default(),
self.src_port_id.clone(),
Some(self.src_chan_id.clone()),
Some(self.src_chan_id),
None,
),
b_side: ChannelSide::new(
chains.dst,
dst_connection.client_id().clone(),
self.dst_conn_id.clone(),
self.dst_port_id.clone(),
Some(self.dst_chan_id.clone()),
Some(self.dst_chan_id),
None,
),
}
Expand Down Expand Up @@ -446,15 +446,15 @@ impl Runnable for TxRawChanCloseConfirmCmd {
ClientId::default(),
ConnectionId::default(),
self.src_port_id.clone(),
Some(self.src_chan_id.clone()),
Some(self.src_chan_id),
None,
),
b_side: ChannelSide::new(
chains.dst,
dst_connection.client_id().clone(),
self.dst_conn_id.clone(),
self.dst_port_id.clone(),
Some(self.dst_chan_id.clone()),
Some(self.dst_chan_id),
None,
),
}
Expand Down
4 changes: 2 additions & 2 deletions relayer-cli/src/commands/tx/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Runnable for TxRawPacketRecvCmd {

let opts = LinkParameters {
src_port_id: self.src_port_id.clone(),
src_channel_id: self.src_channel_id.clone(),
src_channel_id: self.src_channel_id,
};
let link = match Link::new_from_opts(chains.src, chains.dst, opts, false) {
Ok(link) => link,
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Runnable for TxRawPacketAckCmd {

let opts = LinkParameters {
src_port_id: self.src_port_id.clone(),
src_channel_id: self.src_channel_id.clone(),
src_channel_id: self.src_channel_id,
};
let link = match Link::new_from_opts(chains.src, chains.dst, opts, false) {
Ok(link) => link,
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/tx/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl TxIcs20MsgTransferCmd {

let opts = TransferOptions {
packet_src_port_id: self.src_port_id.clone(),
packet_src_channel_id: self.src_channel_id.clone(),
packet_src_channel_id: self.src_channel_id,
amount: self.amount,
denom,
receiver: self.receiver.clone(),
Expand Down
12 changes: 2 additions & 10 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,11 +1574,7 @@ impl ChainEndpoint for CosmosSdkChain {
crate::time!("query_channel");
crate::telemetry!(query, self.id(), "query_channel");

let res = self.query(
ChannelEndsPath(port_id.clone(), channel_id.clone()),
height,
false,
)?;
let res = self.query(ChannelEndsPath(port_id.clone(), *channel_id), height, false)?;
let channel_end = ChannelEnd::decode_vec(&res.value).map_err(Error::decode)?;

Ok(channel_end)
Expand Down Expand Up @@ -2017,11 +2013,7 @@ impl ChainEndpoint for CosmosSdkChain {
channel_id: &ChannelId,
height: ICSHeight,
) -> Result<(ChannelEnd, MerkleProof), Error> {
let res = self.query(
ChannelEndsPath(port_id.clone(), channel_id.clone()),
height,
true,
)?;
let res = self.query(ChannelEndsPath(port_id.clone(), *channel_id), height, true)?;

let channel_end = ChannelEnd::decode_vec(&res.value).map_err(Error::decode)?;

Expand Down
10 changes: 5 additions & 5 deletions relayer/src/chain/counterparty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ pub fn channel_connection_client(
if channel_end.state_matches(&State::Uninitialized) {
return Err(Error::channel_uninitialized(
port_id.clone(),
channel_id.clone(),
*channel_id,
chain.id(),
));
}

let connection_id = channel_end
.connection_hops()
.first()
.ok_or_else(|| Error::missing_connection_hops(channel_id.clone(), chain.id()))?;
.ok_or_else(|| Error::missing_connection_hops(*channel_id, chain.id()))?;

let connection_end = chain
.query_connection(connection_id, Height::zero())
Expand All @@ -152,7 +152,7 @@ pub fn channel_connection_client(
if !connection_end.is_open() {
return Err(Error::connection_not_open(
connection_id.clone(),
channel_id.clone(),
*channel_id,
chain.id(),
));
}
Expand All @@ -164,7 +164,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.clone(), channel_end);
let channel = IdentifiedChannelEnd::new(port_id.clone(), *channel_id, channel_end);

Ok(ChannelConnectionClient::new(channel, connection, client))
}
Expand Down Expand Up @@ -230,7 +230,7 @@ pub fn channel_on_destination(
)
.map(|c| IdentifiedChannelEnd {
port_id: channel.channel_end.counterparty().port_id().clone(),
channel_id: remote_channel_id.clone(),
channel_id: *remote_channel_id,
channel_end: c,
})
.map_err(Error::relayer)?;
Expand Down
6 changes: 3 additions & 3 deletions relayer/src/chain/handle/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl ChainHandle for BaseChainHandle {
) -> Result<ChannelEnd, Error> {
self.send(|reply_to| ChainRequest::QueryChannel {
port_id: port_id.clone(),
channel_id: channel_id.clone(),
channel_id: *channel_id,
height,
reply_to,
})
Expand Down Expand Up @@ -392,7 +392,7 @@ impl ChainHandle for BaseChainHandle {
) -> Result<Proofs, Error> {
self.send(|reply_to| ChainRequest::BuildChannelProofs {
port_id: port_id.clone(),
channel_id: channel_id.clone(),
channel_id: *channel_id,
height,
reply_to,
})
Expand All @@ -409,7 +409,7 @@ impl ChainHandle for BaseChainHandle {
self.send(|reply_to| ChainRequest::BuildPacketProofs {
packet_type,
port_id: port_id.clone(),
channel_id: channel_id.clone(),
channel_id: *channel_id,
sequence,
height,
reply_to,
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/chain/handle/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<Handle: ChainHandle> ChainHandle for CachingChainHandle<Handle> {
let handle = self.inner();
if height.is_zero() {
let (result, in_cache) = self.cache.get_or_try_insert_channel_with(
&PortChannelId::new(channel_id.clone(), port_id.clone()),
&PortChannelId::new(*channel_id, port_id.clone()),
|| handle.query_channel(port_id, channel_id, height),
)?;

Expand Down
Loading

0 comments on commit f70748d

Please sign in to comment.