From 50f267e4ebeafc03bcb8acc1799ca16288f410f3 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 24 Jul 2023 15:03:12 +0200 Subject: [PATCH 01/26] Add missing CLIs for channel upgrade --- crates/relayer-cli/src/commands/tx.rs | 6 + crates/relayer-cli/src/commands/tx/channel.rs | 398 +++++++++++++++++- .../src/core/ics04_channel/timeout.rs | 20 +- 3 files changed, 408 insertions(+), 16 deletions(-) diff --git a/crates/relayer-cli/src/commands/tx.rs b/crates/relayer-cli/src/commands/tx.rs index 6d65e6f976..814f1e4670 100644 --- a/crates/relayer-cli/src/commands/tx.rs +++ b/crates/relayer-cli/src/commands/tx.rs @@ -50,6 +50,12 @@ pub enum TxCmd { /// Relay the channel upgrade attempt (ChannelUpgradeTry) ChanUpgradeTry(channel::TxChanUpgradeTryCmd), + /// Relay the channel upgrade attempt (ChannelUpgradeAck) + ChanUpgradeAck(channel::TxChanUpgradeAckCmd), + + /// Relay the channel upgrade attempt (ChannelUpgradeOpen) + ChanUpgradeOpen(channel::TxChanUpgradeOpenCmd), + /// Send a fungible token transfer test transaction (ICS20 MsgTransfer) FtTransfer(transfer::TxIcs20MsgTransferCmd), diff --git a/crates/relayer-cli/src/commands/tx/channel.rs b/crates/relayer-cli/src/commands/tx/channel.rs index e54bc7ffd9..abe03c275c 100644 --- a/crates/relayer-cli/src/commands/tx/channel.rs +++ b/crates/relayer-cli/src/commands/tx/channel.rs @@ -1,3 +1,5 @@ +use core::time::Duration; + use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; @@ -744,26 +746,36 @@ pub struct TxChanUpgradeInitCmd { value_name = "TIMEOUT_TIMESTAMP", help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." )] - timeout_timestamp: Option, + timeout_timestamp: u64, } impl Runnable for TxChanUpgradeInitCmd { fn run(&self) { let config = app_config(); + let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) { + Ok(chains) => chains, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + let dst_chain_status = chains.dst.query_application_status().unwrap(); + + let timeout_timestamp = if self.timeout_timestamp > 0 { + Some( + (dst_chain_status.timestamp + Duration::from_secs(self.timeout_timestamp)).unwrap(), + ) + } else { + None + }; + // Check that at least one of timeout_height and timeout_timestamp has been provided - let Ok(timeout) = UpgradeTimeout::new(self.timeout_height, self.timeout_timestamp) else { + let Ok(timeout) = UpgradeTimeout::new(self.timeout_height, timeout_timestamp) else { Output::error( "At least one of --timeout-height or --timeout-timestamp must be specified.", ) .exit(); }; - let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) { - Ok(chains) => chains, - Err(e) => Output::error(format!("{}", e)).exit(), - }; - // Fetch the Channel that will facilitate the communication between the channel ends // being upgraded. This channel is assumed to already exist on the destination chain. let channel = Channel { @@ -808,9 +820,9 @@ impl Runnable for TxChanUpgradeInitCmd { /// Relay the channel upgrade attempt (ChannelUpgradeTry) /// /// Build and send a `ChannelUpgradeTry` message in response to -/// a `ChannelUpgradeInnit` message, signaling the chain's intent to +/// a `ChannelUpgradeInit` message, signaling the chain's intent to /// cooperate with the source chain on upgrading the specified channel -/// and initiating the upgrade handshake. +/// and initiating the upgrade handshake. #[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] pub struct TxChanUpgradeTryCmd { #[clap( @@ -876,10 +888,376 @@ pub struct TxChanUpgradeTryCmd { help = "Identifier of the destination channel (optional)" )] dst_chan_id: Option, + + #[clap( + long = "timeout-height", + required = false, + value_name = "TIMEOUT_HEIGHT", + help = "Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified." + )] + timeout_height: Option, + + #[clap( + long = "timeout-timestamp", + required = false, + value_name = "TIMEOUT_TIMESTAMP", + help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." + )] + timeout_timestamp: Option, } impl Runnable for TxChanUpgradeTryCmd { - fn run(&self) {} + fn run(&self) { + let config = app_config(); + + // Check that at least one of timeout_height and timeout_timestamp has been provided + let Ok(timeout) = UpgradeTimeout::new(self.timeout_height, self.timeout_timestamp) else { + Output::error( + "At least one of --timeout-height or --timeout-timestamp must be specified.", + ) + .exit(); + }; + + let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) { + Ok(chains) => chains, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + // Retrieve the connection + let dst_connection = match chains.dst.query_connection( + QueryConnectionRequest { + connection_id: self.dst_conn_id.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) { + Ok((connection, _)) => connection, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + // Fetch the Channel that will facilitate the communication between the channel ends + // being upgraded. This channel is assumed to already exist on the destination chain. + let channel = Channel { + connection_delay: Default::default(), + ordering: Ordering::default(), + a_side: ChannelSide::new( + chains.src, + ClientId::default(), + ConnectionId::default(), + self.src_port_id.clone(), + Some(self.src_chan_id.clone()), + 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(), + None, + ), + }; + + info!("message ChanUpgradeTry: {}", channel); + + let res: Result = channel + .build_chan_upgrade_try_and_send(timeout) + .map_err(Error::channel); + + match res { + Ok(receipt) => Output::success(receipt).exit(), + Err(e) => Output::error(e).exit(), + } + } +} + +/// Relay the channel upgrade attempt (ChannelUpgradeAck) +/// +/// Build and send a `ChannelUpgradeAck` message in response to +/// a `ChannelUpgradeTry` message in order to continue the channel +/// upgrade handshake. +#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] +pub struct TxChanUpgradeAckCmd { + #[clap( + long = "dst-chain", + required = true, + value_name = "DST_CHAIN_ID", + help_heading = "REQUIRED", + help = "Identifier of the destination chain" + )] + dst_chain_id: ChainId, + + #[clap( + long = "src-chain", + required = true, + value_name = "SRC_CHAIN_ID", + help_heading = "REQUIRED", + help = "Identifier of the source chain" + )] + src_chain_id: ChainId, + + #[clap( + long = "dst-connection", + visible_alias = "dst-conn", + required = true, + value_name = "DST_CONNECTION_ID", + help_heading = "REQUIRED", + help = "Identifier of the destination connection" + )] + dst_conn_id: ConnectionId, + + #[clap( + long = "dst-port", + required = true, + value_name = "DST_PORT_ID", + help_heading = "REQUIRED", + help = "Identifier of the destination port" + )] + dst_port_id: PortId, + + #[clap( + long = "src-port", + required = true, + value_name = "SRC_PORT_ID", + help_heading = "REQUIRED", + help = "Identifier of the source port" + )] + src_port_id: PortId, + + #[clap( + long = "src-channel", + visible_alias = "src-chan", + required = true, + value_name = "SRC_CHANNEL_ID", + help_heading = "REQUIRED", + help = "Identifier of the source channel (required)" + )] + src_chan_id: ChannelId, + + #[clap( + long = "dst-channel", + visible_alias = "dst-chan", + value_name = "DST_CHANNEL_ID", + help = "Identifier of the destination channel (optional)" + )] + dst_chan_id: Option, + + #[clap( + long = "timeout-height", + required = false, + value_name = "TIMEOUT_HEIGHT", + help = "Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified." + )] + timeout_height: Option, + + #[clap( + long = "timeout-timestamp", + required = false, + value_name = "TIMEOUT_TIMESTAMP", + help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." + )] + timeout_timestamp: Option, +} + +impl Runnable for TxChanUpgradeAckCmd { + fn run(&self) { + let config = app_config(); + + let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) { + Ok(chains) => chains, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + // Retrieve the connection + let dst_connection = match chains.dst.query_connection( + QueryConnectionRequest { + connection_id: self.dst_conn_id.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) { + Ok((connection, _)) => connection, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + // Fetch the Channel that will facilitate the communication between the channel ends + // being upgraded. This channel is assumed to already exist on the destination chain. + let channel = Channel { + connection_delay: Default::default(), + ordering: Ordering::default(), + a_side: ChannelSide::new( + chains.src, + ClientId::default(), + ConnectionId::default(), + self.src_port_id.clone(), + Some(self.src_chan_id.clone()), + 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(), + None, + ), + }; + + info!("message ChanUpgradeAck: {}", channel); + + let res: Result = channel + .build_chan_upgrade_ack_and_send() + .map_err(Error::channel); + + match res { + Ok(receipt) => Output::success(receipt).exit(), + Err(e) => Output::error(e).exit(), + } + } +} + +/// Relay the channel upgrade attempt (ChannelUpgradeOpen) +/// +/// Build and send a `ChannelUpgradeOpen` message to finalize +/// the channel upgrade handshake. +#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] +pub struct TxChanUpgradeOpenCmd { + #[clap( + long = "dst-chain", + required = true, + value_name = "DST_CHAIN_ID", + help_heading = "REQUIRED", + help = "Identifier of the destination chain" + )] + dst_chain_id: ChainId, + + #[clap( + long = "src-chain", + required = true, + value_name = "SRC_CHAIN_ID", + help_heading = "REQUIRED", + help = "Identifier of the source chain" + )] + src_chain_id: ChainId, + + #[clap( + long = "dst-connection", + visible_alias = "dst-conn", + required = true, + value_name = "DST_CONNECTION_ID", + help_heading = "REQUIRED", + help = "Identifier of the destination connection" + )] + dst_conn_id: ConnectionId, + + #[clap( + long = "dst-port", + required = true, + value_name = "DST_PORT_ID", + help_heading = "REQUIRED", + help = "Identifier of the destination port" + )] + dst_port_id: PortId, + + #[clap( + long = "src-port", + required = true, + value_name = "SRC_PORT_ID", + help_heading = "REQUIRED", + help = "Identifier of the source port" + )] + src_port_id: PortId, + + #[clap( + long = "src-channel", + visible_alias = "src-chan", + required = true, + value_name = "SRC_CHANNEL_ID", + help_heading = "REQUIRED", + help = "Identifier of the source channel (required)" + )] + src_chan_id: ChannelId, + + #[clap( + long = "dst-channel", + visible_alias = "dst-chan", + value_name = "DST_CHANNEL_ID", + help = "Identifier of the destination channel (optional)" + )] + dst_chan_id: Option, + + #[clap( + long = "timeout-height", + required = false, + value_name = "TIMEOUT_HEIGHT", + help = "Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified." + )] + timeout_height: Option, + + #[clap( + long = "timeout-timestamp", + required = false, + value_name = "TIMEOUT_TIMESTAMP", + help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." + )] + timeout_timestamp: Option, +} + +impl Runnable for TxChanUpgradeOpenCmd { + fn run(&self) { + let config = app_config(); + + let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) { + Ok(chains) => chains, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + // Retrieve the connection + let dst_connection = match chains.dst.query_connection( + QueryConnectionRequest { + connection_id: self.dst_conn_id.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) { + Ok((connection, _)) => connection, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + // Fetch the Channel that will facilitate the communication between the channel ends + // being upgraded. This channel is assumed to already exist on the destination chain. + let channel = Channel { + connection_delay: Default::default(), + ordering: Ordering::default(), + a_side: ChannelSide::new( + chains.src, + ClientId::default(), + ConnectionId::default(), + self.src_port_id.clone(), + Some(self.src_chan_id.clone()), + 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(), + None, + ), + }; + + info!("message ChanUpgradeOpen: {}", channel); + + let res: Result = channel + .build_chan_upgrade_open_and_send() + .map_err(Error::channel); + + match res { + Ok(receipt) => Output::success(receipt).exit(), + Err(e) => Output::error(e).exit(), + } + } } #[cfg(test)] diff --git a/crates/relayer-types/src/core/ics04_channel/timeout.rs b/crates/relayer-types/src/core/ics04_channel/timeout.rs index 29d83551c8..2b95da0535 100644 --- a/crates/relayer-types/src/core/ics04_channel/timeout.rs +++ b/crates/relayer-types/src/core/ics04_channel/timeout.rs @@ -229,17 +229,25 @@ impl TryFrom for UpgradeTimeout { type Error = ChannelError; fn try_from(value: RawUpgradeTimeout) -> Result { - let timeout_height = value - .height - .map(Height::try_from) - .transpose() - .map_err(|_| Self::Error::invalid_timeout_height())?; + let raw_timeout_height = value.height.map(Height::try_from).transpose(); - let timeout_timestamp = Timestamp::from_nanoseconds(value.timestamp) + let raw_timeout_timestamp = Timestamp::from_nanoseconds(value.timestamp) .map_err(|_| Self::Error::invalid_timeout_timestamp) .ok() .filter(|ts| ts.nanoseconds() > 0); + let (timeout_height, timeout_timestamp) = match (raw_timeout_height, raw_timeout_timestamp) + { + (Ok(timeout_height), Some(timeout_timestamp)) => { + (timeout_height, Some(timeout_timestamp)) + } + (Ok(timeout_height), None) => (timeout_height, None), + (Err(_), Some(timeout_timestamp)) => (None, Some(timeout_timestamp)), + (Err(e), None) => { + return Err(e).map_err(|_| Self::Error::invalid_timeout_height()); + } + }; + Self::new(timeout_height, timeout_timestamp) } } From 80635bb0113074f68c95c08402c4e796a12dc81c Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 24 Jul 2023 15:17:11 +0200 Subject: [PATCH 02/26] Update CLI template --- .../commands/hermes/tx/chan-upgrade-ack_1.md | 1 + .../commands/hermes/tx/chan-upgrade-open_1.md | 1 + guide/src/templates/help_templates/tx.md | 2 + .../help_templates/tx/chan-upgrade-ack.md | 39 +++++++++++++++++++ .../help_templates/tx/chan-upgrade-open.md | 39 +++++++++++++++++++ .../help_templates/tx/chan-upgrade-try.md | 8 ++++ 6 files changed, 90 insertions(+) create mode 100644 guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md create mode 100644 guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md create mode 100644 guide/src/templates/help_templates/tx/chan-upgrade-ack.md create mode 100644 guide/src/templates/help_templates/tx/chan-upgrade-open.md diff --git a/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md b/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md new file mode 100644 index 0000000000..108682306d --- /dev/null +++ b/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md @@ -0,0 +1 @@ +[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-ack[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md b/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md new file mode 100644 index 0000000000..1ace17969e --- /dev/null +++ b/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md @@ -0,0 +1 @@ +[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-open[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] \ No newline at end of file diff --git a/guide/src/templates/help_templates/tx.md b/guide/src/templates/help_templates/tx.md index f968b2655d..95e55b08aa 100644 --- a/guide/src/templates/help_templates/tx.md +++ b/guide/src/templates/help_templates/tx.md @@ -14,7 +14,9 @@ SUBCOMMANDS: chan-open-confirm Confirm opening of a channel (ChannelOpenConfirm) chan-open-init Initialize a channel (ChannelOpenInit) chan-open-try Relay the channel attempt (ChannelOpenTry) + chan-upgrade-ack Relay the channel upgrade attempt (ChannelUpgradeAck) chan-upgrade-init Initiate a channel upgrade (ChannelUpgradeInit) + chan-upgrade-open Relay the channel upgrade attempt (ChannelUpgradeOpen) chan-upgrade-try Relay the channel upgrade attempt (ChannelUpgradeTry) conn-ack Relay acknowledgment of a connection attempt (ConnectionOpenAck) conn-confirm Confirm opening of a connection (ConnectionOpenConfirm) diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-ack.md b/guide/src/templates/help_templates/tx/chan-upgrade-ack.md new file mode 100644 index 0000000000..22bf37cbf8 --- /dev/null +++ b/guide/src/templates/help_templates/tx/chan-upgrade-ack.md @@ -0,0 +1,39 @@ +DESCRIPTION: +Relay the channel upgrade attempt (ChannelUpgradeAck) + +USAGE: + hermes tx chan-upgrade-ack [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel + +OPTIONS: + --dst-channel + Identifier of the destination channel (optional) [aliases: dst-chan] + + -h, --help + Print help information + + --timeout-height + Height that, once it has been surpassed on the originating chain, the upgrade will time + out. Required if no timeout timestamp is specified. + + --timeout-timestamp + Timestamp that, once it has been surpassed on the originating chain, the upgrade will + time out. Required if no timeout height is specified. + +REQUIRED: + --dst-chain + Identifier of the destination chain + + --dst-connection + Identifier of the destination connection [aliases: dst-conn] + + --dst-port + Identifier of the destination port + + --src-chain + Identifier of the source chain + + --src-channel + Identifier of the source channel (required) [aliases: src-chan] + + --src-port + Identifier of the source port diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-open.md b/guide/src/templates/help_templates/tx/chan-upgrade-open.md new file mode 100644 index 0000000000..2cf31a01c7 --- /dev/null +++ b/guide/src/templates/help_templates/tx/chan-upgrade-open.md @@ -0,0 +1,39 @@ +DESCRIPTION: +Relay the channel upgrade attempt (ChannelUpgradeOpen) + +USAGE: + hermes tx chan-upgrade-open [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel + +OPTIONS: + --dst-channel + Identifier of the destination channel (optional) [aliases: dst-chan] + + -h, --help + Print help information + + --timeout-height + Height that, once it has been surpassed on the originating chain, the upgrade will time + out. Required if no timeout timestamp is specified. + + --timeout-timestamp + Timestamp that, once it has been surpassed on the originating chain, the upgrade will + time out. Required if no timeout height is specified. + +REQUIRED: + --dst-chain + Identifier of the destination chain + + --dst-connection + Identifier of the destination connection [aliases: dst-conn] + + --dst-port + Identifier of the destination port + + --src-chain + Identifier of the source chain + + --src-channel + Identifier of the source channel (required) [aliases: src-chan] + + --src-port + Identifier of the source port diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-try.md b/guide/src/templates/help_templates/tx/chan-upgrade-try.md index 750d567599..342595387b 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-try.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-try.md @@ -11,6 +11,14 @@ OPTIONS: -h, --help Print help information + --timeout-height + Height that, once it has been surpassed on the originating chain, the upgrade will time + out. Required if no timeout timestamp is specified. + + --timeout-timestamp + Timestamp that, once it has been surpassed on the originating chain, the upgrade will + time out. Required if no timeout height is specified. + REQUIRED: --dst-chain Identifier of the destination chain From edb3610b3cf4db5d8042c52f9208f418c911ace7 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Thu, 3 Aug 2023 11:18:25 +0200 Subject: [PATCH 03/26] Add cargo patch for check-guide test --- crates/relayer-cli/src/commands/tx/channel.rs | 1 + tools/check-guide/Cargo.lock | 4 +--- tools/check-guide/Cargo.toml | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/relayer-cli/src/commands/tx/channel.rs b/crates/relayer-cli/src/commands/tx/channel.rs index abe03c275c..86495d6f2c 100644 --- a/crates/relayer-cli/src/commands/tx/channel.rs +++ b/crates/relayer-cli/src/commands/tx/channel.rs @@ -884,6 +884,7 @@ pub struct TxChanUpgradeTryCmd { #[clap( long = "dst-channel", visible_alias = "dst-chan", + required = true, value_name = "DST_CHANNEL_ID", help = "Identifier of the destination channel (optional)" )] diff --git a/tools/check-guide/Cargo.lock b/tools/check-guide/Cargo.lock index 4dfc564388..e6128cb533 100644 --- a/tools/check-guide/Cargo.lock +++ b/tools/check-guide/Cargo.lock @@ -1735,8 +1735,7 @@ dependencies = [ [[package]] name = "ibc-proto" version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c888103095b45bee90cb9104513ade30abd69902153b0682b5ad81940ae1f865" +source = "git+https://github.com/cosmos/ibc-proto-rs.git?branch=romac/channel-upgrade-only#9e0ecb6f3c4b736e3ff95e1518f19deeead1a675" dependencies = [ "base64 0.21.2", "bytes", @@ -1815,7 +1814,6 @@ name = "ibc-relayer-cli" version = "1.6.0" dependencies = [ "abscissa_core", - "atty", "clap 3.2.25", "clap_complete 3.2.5", "color-eyre", diff --git a/tools/check-guide/Cargo.toml b/tools/check-guide/Cargo.toml index 59b5956262..f2ca100366 100644 --- a/tools/check-guide/Cargo.toml +++ b/tools/check-guide/Cargo.toml @@ -13,3 +13,6 @@ lazy_static = "1.4.0" mdbook-template = "1.1.0" regex = "1" walkdir = "2.3.3" + +[patch.crates-io] +ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", branch = "romac/channel-upgrade-only" } \ No newline at end of file From 05b08d03ee980704944d8b8d7c5333d41a2a31b0 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Thu, 3 Aug 2023 11:19:19 +0200 Subject: [PATCH 04/26] Add documentation TODO to check-guide Cargo.toml --- tools/check-guide/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/check-guide/Cargo.toml b/tools/check-guide/Cargo.toml index f2ca100366..2281be90da 100644 --- a/tools/check-guide/Cargo.toml +++ b/tools/check-guide/Cargo.toml @@ -14,5 +14,6 @@ mdbook-template = "1.1.0" regex = "1" walkdir = "2.3.3" +# TODO remove once simapp v8 is released [patch.crates-io] ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", branch = "romac/channel-upgrade-only" } \ No newline at end of file From 2c65075fbd4c24c4b947a633116a46ed0a13712a Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Thu, 3 Aug 2023 11:47:00 +0200 Subject: [PATCH 05/26] Set dst-channel flag to required for channel upgrade CLIs and updated templates --- crates/relayer-cli/src/commands/tx/channel.rs | 5 +++++ .../templates/commands/hermes/tx/chan-upgrade-ack_1.md | 2 +- .../templates/commands/hermes/tx/chan-upgrade-open_1.md | 2 +- .../templates/commands/hermes/tx/chan-upgrade-try_1.md | 2 +- guide/src/templates/help_templates/tx/chan-upgrade-ack.md | 8 ++++---- .../src/templates/help_templates/tx/chan-upgrade-open.md | 8 ++++---- guide/src/templates/help_templates/tx/chan-upgrade-try.md | 8 ++++---- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/relayer-cli/src/commands/tx/channel.rs b/crates/relayer-cli/src/commands/tx/channel.rs index 86495d6f2c..a4c27c4fc8 100644 --- a/crates/relayer-cli/src/commands/tx/channel.rs +++ b/crates/relayer-cli/src/commands/tx/channel.rs @@ -885,6 +885,7 @@ pub struct TxChanUpgradeTryCmd { long = "dst-channel", visible_alias = "dst-chan", required = true, + help_heading = "REQUIRED", value_name = "DST_CHANNEL_ID", help = "Identifier of the destination channel (optional)" )] @@ -1038,6 +1039,8 @@ pub struct TxChanUpgradeAckCmd { #[clap( long = "dst-channel", visible_alias = "dst-chan", + required = true, + help_heading = "REQUIRED", value_name = "DST_CHANNEL_ID", help = "Identifier of the destination channel (optional)" )] @@ -1182,6 +1185,8 @@ pub struct TxChanUpgradeOpenCmd { #[clap( long = "dst-channel", visible_alias = "dst-chan", + required = true, + help_heading = "REQUIRED", value_name = "DST_CHANNEL_ID", help = "Identifier of the destination channel (optional)" )] diff --git a/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md b/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md index 108682306d..c025e411bc 100644 --- a/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md +++ b/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md @@ -1 +1 @@ -[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-ack[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] \ No newline at end of file +[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-ack[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] --dst-channel [[#DST_CHANNEL_ID]] \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md b/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md index 1ace17969e..2b8294ec28 100644 --- a/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md +++ b/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md @@ -1 +1 @@ -[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-open[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] \ No newline at end of file +[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-open[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] --dst-channel [[#DST_CHANNEL_ID]] \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/tx/chan-upgrade-try_1.md b/guide/src/templates/commands/hermes/tx/chan-upgrade-try_1.md index 6dd8adecaa..e33ec14407 100644 --- a/guide/src/templates/commands/hermes/tx/chan-upgrade-try_1.md +++ b/guide/src/templates/commands/hermes/tx/chan-upgrade-try_1.md @@ -1 +1 @@ -[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-try[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] \ No newline at end of file +[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-try[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] --dst-channel [[#DST_CHANNEL_ID]] \ No newline at end of file diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-ack.md b/guide/src/templates/help_templates/tx/chan-upgrade-ack.md index 22bf37cbf8..1b17e8f128 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-ack.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-ack.md @@ -2,12 +2,9 @@ DESCRIPTION: Relay the channel upgrade attempt (ChannelUpgradeAck) USAGE: - hermes tx chan-upgrade-ack [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel + hermes tx chan-upgrade-ack [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel --dst-channel OPTIONS: - --dst-channel - Identifier of the destination channel (optional) [aliases: dst-chan] - -h, --help Print help information @@ -23,6 +20,9 @@ REQUIRED: --dst-chain Identifier of the destination chain + --dst-channel + Identifier of the destination channel (optional) [aliases: dst-chan] + --dst-connection Identifier of the destination connection [aliases: dst-conn] diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-open.md b/guide/src/templates/help_templates/tx/chan-upgrade-open.md index 2cf31a01c7..f7c84c37e1 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-open.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-open.md @@ -2,12 +2,9 @@ DESCRIPTION: Relay the channel upgrade attempt (ChannelUpgradeOpen) USAGE: - hermes tx chan-upgrade-open [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel + hermes tx chan-upgrade-open [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel --dst-channel OPTIONS: - --dst-channel - Identifier of the destination channel (optional) [aliases: dst-chan] - -h, --help Print help information @@ -23,6 +20,9 @@ REQUIRED: --dst-chain Identifier of the destination chain + --dst-channel + Identifier of the destination channel (optional) [aliases: dst-chan] + --dst-connection Identifier of the destination connection [aliases: dst-conn] diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-try.md b/guide/src/templates/help_templates/tx/chan-upgrade-try.md index 342595387b..cfcb556872 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-try.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-try.md @@ -2,12 +2,9 @@ DESCRIPTION: Relay the channel upgrade attempt (ChannelUpgradeTry) USAGE: - hermes tx chan-upgrade-try [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel + hermes tx chan-upgrade-try [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel --dst-channel OPTIONS: - --dst-channel - Identifier of the destination channel (optional) [aliases: dst-chan] - -h, --help Print help information @@ -23,6 +20,9 @@ REQUIRED: --dst-chain Identifier of the destination chain + --dst-channel + Identifier of the destination channel (optional) [aliases: dst-chan] + --dst-connection Identifier of the destination connection [aliases: dst-conn] From fa8595f11f49c13642b4f213968f5e30ebd6c61b Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 7 Aug 2023 15:09:55 +0200 Subject: [PATCH 06/26] Clean channel upgrade CLIs --- crates/relayer-cli/src/commands/tx/channel.rs | 98 ++++++++----------- 1 file changed, 39 insertions(+), 59 deletions(-) diff --git a/crates/relayer-cli/src/commands/tx/channel.rs b/crates/relayer-cli/src/commands/tx/channel.rs index a4c27c4fc8..3133d03062 100644 --- a/crates/relayer-cli/src/commands/tx/channel.rs +++ b/crates/relayer-cli/src/commands/tx/channel.rs @@ -1,7 +1,7 @@ -use core::time::Duration; - use abscissa_core::clap::Parser; -use abscissa_core::{Command, Runnable}; +use abscissa_core::Command; +use abscissa_core::Runnable; +use humantime::Duration as HumanDuration; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{IncludeProof, QueryConnectionRequest, QueryHeight}; @@ -15,7 +15,6 @@ use ibc_relayer_types::core::ics24_host::identifier::{ ChainId, ChannelId, ClientId, ConnectionId, PortId, }; use ibc_relayer_types::events::IbcEvent; -use ibc_relayer_types::timestamp::Timestamp; use ibc_relayer_types::Height; use crate::cli_utils::ChainHandlePair; @@ -741,12 +740,12 @@ pub struct TxChanUpgradeInitCmd { timeout_height: Option, #[clap( - long = "timeout-timestamp", + long = "timeout-time", required = false, - value_name = "TIMEOUT_TIMESTAMP", - help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." + value_name = "TIMEOUT_TIME", + help = "Timeout in human readable format since current that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." )] - timeout_timestamp: u64, + timeout_time: Option, } impl Runnable for TxChanUpgradeInitCmd { @@ -758,16 +757,15 @@ impl Runnable for TxChanUpgradeInitCmd { Err(e) => Output::error(format!("{}", e)).exit(), }; - let dst_chain_status = chains.dst.query_application_status().unwrap(); - - let timeout_timestamp = if self.timeout_timestamp > 0 { - Some( - (dst_chain_status.timestamp + Duration::from_secs(self.timeout_timestamp)).unwrap(), - ) - } else { - None + let dst_chain_status = match chains.dst.query_application_status() { + Ok(application_status) => application_status, + Err(e) => Output::error(format!("query_application_status error {}", e)).exit(), }; + let timeout_timestamp = self + .timeout_time + .map(|timeout_time| (dst_chain_status.timestamp + *timeout_time).unwrap()); + // Check that at least one of timeout_height and timeout_timestamp has been provided let Ok(timeout) = UpgradeTimeout::new(self.timeout_height, timeout_timestamp) else { Output::error( @@ -900,20 +898,34 @@ pub struct TxChanUpgradeTryCmd { timeout_height: Option, #[clap( - long = "timeout-timestamp", + long = "timeout-time", required = false, - value_name = "TIMEOUT_TIMESTAMP", - help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." + value_name = "TIMEOUT_TIME", + help = "Timeout in human readable format since current that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." )] - timeout_timestamp: Option, + timeout_time: Option, } impl Runnable for TxChanUpgradeTryCmd { fn run(&self) { let config = app_config(); + let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) { + Ok(chains) => chains, + Err(e) => Output::error(format!("{}", e)).exit(), + }; + + let dst_chain_status = match chains.dst.query_application_status() { + Ok(application_status) => application_status, + Err(e) => Output::error(format!("query_application_status error {}", e)).exit(), + }; + + let timeout_timestamp = self + .timeout_time + .map(|timeout_time| (dst_chain_status.timestamp + *timeout_time).unwrap()); + // Check that at least one of timeout_height and timeout_timestamp has been provided - let Ok(timeout) = UpgradeTimeout::new(self.timeout_height, self.timeout_timestamp) else { + let Ok(timeout) = UpgradeTimeout::new(self.timeout_height, timeout_timestamp) else { Output::error( "At least one of --timeout-height or --timeout-timestamp must be specified.", ) @@ -1045,22 +1057,6 @@ pub struct TxChanUpgradeAckCmd { help = "Identifier of the destination channel (optional)" )] dst_chan_id: Option, - - #[clap( - long = "timeout-height", - required = false, - value_name = "TIMEOUT_HEIGHT", - help = "Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified." - )] - timeout_height: Option, - - #[clap( - long = "timeout-timestamp", - required = false, - value_name = "TIMEOUT_TIMESTAMP", - help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." - )] - timeout_timestamp: Option, } impl Runnable for TxChanUpgradeAckCmd { @@ -1191,22 +1187,6 @@ pub struct TxChanUpgradeOpenCmd { help = "Identifier of the destination channel (optional)" )] dst_chan_id: Option, - - #[clap( - long = "timeout-height", - required = false, - value_name = "TIMEOUT_HEIGHT", - help = "Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified." - )] - timeout_height: Option, - - #[clap( - long = "timeout-timestamp", - required = false, - value_name = "TIMEOUT_TIMESTAMP", - help = "Timestamp that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." - )] - timeout_timestamp: Option, } impl Runnable for TxChanUpgradeOpenCmd { @@ -1268,19 +1248,19 @@ impl Runnable for TxChanUpgradeOpenCmd { #[cfg(test)] mod tests { - use super::{ - TxChanCloseConfirmCmd, TxChanCloseInitCmd, TxChanOpenAckCmd, TxChanOpenConfirmCmd, - TxChanOpenInitCmd, TxChanOpenTryCmd, - }; - + use abscissa_core::clap::Parser; use std::str::FromStr; - use abscissa_core::clap::Parser; use ibc_relayer_types::core::{ ics04_channel::channel::Ordering, ics24_host::identifier::{ChainId, ChannelId, ConnectionId, PortId}, }; + use crate::commands::tx::channel::{ + TxChanCloseConfirmCmd, TxChanCloseInitCmd, TxChanOpenAckCmd, TxChanOpenConfirmCmd, + TxChanOpenInitCmd, TxChanOpenTryCmd, + }; + #[test] fn test_chan_open_init_required_only() { assert_eq!( From 298eaf03862b256d1ea7667e5bb7401b67fa42a6 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 7 Aug 2023 15:18:42 +0200 Subject: [PATCH 07/26] Update guide templates --- .../commands/hermes/tx/chan-upgrade-ack_1.md | 2 +- .../commands/hermes/tx/chan-upgrade-open_1.md | 2 +- .../templates/help_templates/tx/chan-upgrade-ack.md | 13 ++----------- .../help_templates/tx/chan-upgrade-init.md | 7 ++++--- .../help_templates/tx/chan-upgrade-open.md | 13 ++----------- .../templates/help_templates/tx/chan-upgrade-try.md | 7 ++++--- 6 files changed, 14 insertions(+), 30 deletions(-) diff --git a/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md b/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md index c025e411bc..3143b03d70 100644 --- a/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md +++ b/guide/src/templates/commands/hermes/tx/chan-upgrade-ack_1.md @@ -1 +1 @@ -[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-ack[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] --dst-channel [[#DST_CHANNEL_ID]] \ No newline at end of file +[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-ack --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] --dst-channel [[#DST_CHANNEL_ID]] \ No newline at end of file diff --git a/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md b/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md index 2b8294ec28..e7c3a0c000 100644 --- a/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md +++ b/guide/src/templates/commands/hermes/tx/chan-upgrade-open_1.md @@ -1 +1 @@ -[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-open[[#OPTIONS]] --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] --dst-channel [[#DST_CHANNEL_ID]] \ No newline at end of file +[[#BINARY hermes]][[#GLOBALOPTIONS]] tx chan-upgrade-open --dst-chain [[#DST_CHAIN_ID]] --src-chain [[#SRC_CHAIN_ID]] --dst-connection [[#DST_CONNECTION_ID]] --dst-port [[#DST_PORT_ID]] --src-port [[#SRC_PORT_ID]] --src-channel [[#SRC_CHANNEL_ID]] --dst-channel [[#DST_CHANNEL_ID]] \ No newline at end of file diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-ack.md b/guide/src/templates/help_templates/tx/chan-upgrade-ack.md index 1b17e8f128..6c30bfa913 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-ack.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-ack.md @@ -2,19 +2,10 @@ DESCRIPTION: Relay the channel upgrade attempt (ChannelUpgradeAck) USAGE: - hermes tx chan-upgrade-ack [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel --dst-channel + hermes tx chan-upgrade-ack --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel --dst-channel OPTIONS: - -h, --help - Print help information - - --timeout-height - Height that, once it has been surpassed on the originating chain, the upgrade will time - out. Required if no timeout timestamp is specified. - - --timeout-timestamp - Timestamp that, once it has been surpassed on the originating chain, the upgrade will - time out. Required if no timeout height is specified. + -h, --help Print help information REQUIRED: --dst-chain diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-init.md b/guide/src/templates/help_templates/tx/chan-upgrade-init.md index bdeccaeb29..f0d217bb3b 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-init.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-init.md @@ -21,9 +21,10 @@ OPTIONS: Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified. - --timeout-timestamp - Timestamp that, once it has been surpassed on the originating chain, the upgrade will - time out. Required if no timeout height is specified. + --timeout-time + Timeout in human readable format since current that, once it has been surpassed on the + originating chain, the upgrade will time out. Required if no timeout height is + specified. --version Version of the channel that both chains will upgrade to. Defaults to the version of the diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-open.md b/guide/src/templates/help_templates/tx/chan-upgrade-open.md index f7c84c37e1..fb878cd41d 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-open.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-open.md @@ -2,19 +2,10 @@ DESCRIPTION: Relay the channel upgrade attempt (ChannelUpgradeOpen) USAGE: - hermes tx chan-upgrade-open [OPTIONS] --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel --dst-channel + hermes tx chan-upgrade-open --dst-chain --src-chain --dst-connection --dst-port --src-port --src-channel --dst-channel OPTIONS: - -h, --help - Print help information - - --timeout-height - Height that, once it has been surpassed on the originating chain, the upgrade will time - out. Required if no timeout timestamp is specified. - - --timeout-timestamp - Timestamp that, once it has been surpassed on the originating chain, the upgrade will - time out. Required if no timeout height is specified. + -h, --help Print help information REQUIRED: --dst-chain diff --git a/guide/src/templates/help_templates/tx/chan-upgrade-try.md b/guide/src/templates/help_templates/tx/chan-upgrade-try.md index cfcb556872..c711c208de 100644 --- a/guide/src/templates/help_templates/tx/chan-upgrade-try.md +++ b/guide/src/templates/help_templates/tx/chan-upgrade-try.md @@ -12,9 +12,10 @@ OPTIONS: Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified. - --timeout-timestamp - Timestamp that, once it has been surpassed on the originating chain, the upgrade will - time out. Required if no timeout height is specified. + --timeout-time + Timeout in human readable format since current that, once it has been surpassed on the + originating chain, the upgrade will time out. Required if no timeout height is + specified. REQUIRED: --dst-chain From e437381adcb800572ace3d8f40327d1764871465 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Tue, 8 Aug 2023 10:06:38 +0200 Subject: [PATCH 08/26] Update channel upgrade test to match ibc-go changes --- Cargo.lock | 342 ++++++++---------- .../src/core/ics04_channel/channel.rs | 42 ++- .../channel_upgrade/manual_channel_upgrade.rs | 22 +- tools/test-framework/src/relayer/channel.rs | 34 +- 4 files changed, 223 insertions(+), 217 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9d8961bef..073d924b41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,9 +67,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.71" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" [[package]] name = "arc-swap" @@ -96,7 +96,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -107,7 +107,7 @@ checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -145,9 +145,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", "axum-core", @@ -360,9 +360,9 @@ checksum = "e6e9e01327e6c86e92ec72b1c798d4a94810f147209bbe3ffab6a86954937a6f" [[package]] name = "cargo-platform" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" dependencies = [ "serde", ] @@ -382,9 +382,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -659,14 +662,20 @@ dependencies = [ [[package]] name = "der" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ed52955ce76b1554f509074bb357d3fb8ac9b51288a65a3fd480d1dfba946" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" + [[package]] name = "derivation-path" version = "0.2.0" @@ -746,9 +755,9 @@ checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" [[package]] name = "ecdsa" -version = "0.16.7" +version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" +checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4" dependencies = [ "der", "digest 0.10.7", @@ -820,9 +829,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" @@ -888,9 +897,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", @@ -928,12 +937,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" [[package]] name = "ff" @@ -1042,7 +1048,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -1386,7 +1392,7 @@ dependencies = [ "futures-util", "http", "hyper", - "rustls 0.21.5", + "rustls 0.21.6", "tokio", "tokio-rustls 0.24.1", ] @@ -1442,7 +1448,7 @@ dependencies = [ [[package]] name = "ibc-proto" version = "0.32.0" -source = "git+https://github.com/cosmos/ibc-proto-rs.git?branch=romac/channel-upgrade-only#9e0ecb6f3c4b736e3ff95e1518f19deeead1a675" +source = "git+https://github.com/cosmos/ibc-proto-rs.git?branch=romac/channel-upgrade-only#b3d0320ead537ed528bb76b45fe49b8e4ca00c75" dependencies = [ "base64 0.21.2", "bytes", @@ -1518,7 +1524,7 @@ dependencies = [ "tonic", "tracing", "tracing-subscriber", - "uuid 1.4.0", + "uuid 1.4.1", ] [[package]] @@ -1730,26 +1736,6 @@ dependencies = [ "hashbrown 0.14.0", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.2", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipnet" version = "2.8.0" @@ -1763,7 +1749,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.2", - "rustix 0.38.4", + "rustix", "windows-sys 0.48.0", ] @@ -1778,9 +1764,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" @@ -1826,15 +1812,9 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - -[[package]] -name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" @@ -1872,9 +1852,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" +checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" [[package]] name = "maybe-uninit" @@ -1925,9 +1905,9 @@ dependencies = [ [[package]] name = "moka" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206bf83f415b0579fd885fe0804eb828e727636657dc1bf73d80d2f1218e14a1" +checksum = "fa6e72583bf6830c956235bff0d5afec8cf2952f579ebad18ae7821a917d950f" dependencies = [ "crossbeam-channel 0.5.8", "crossbeam-epoch", @@ -1942,7 +1922,7 @@ dependencies = [ "tagptr", "thiserror", "triomphe", - "uuid 1.4.0", + "uuid 1.4.1", ] [[package]] @@ -2003,9 +1983,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] @@ -2156,9 +2136,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4b27ab7be369122c218afc2079489cdcb4b517c0a3fc386ff11e1fedfcc2b35" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pbjson" @@ -2214,29 +2194,29 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "2c516611246607d0c04186886dbb3a754368ef82c79e9827a802c6d836dd111c" [[package]] name = "pin-utils" @@ -2297,9 +2277,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.64" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -2386,9 +2366,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.29" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -2504,13 +2484,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.2", + "regex-automata 0.3.6", "regex-syntax 0.7.4", ] @@ -2525,9 +2505,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.2" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" +checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" dependencies = [ "aho-corasick", "memchr", @@ -2569,7 +2549,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.5", + "rustls 0.21.6", "rustls-pemfile", "serde", "serde_json", @@ -2648,28 +2628,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.38.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - -[[package]] -name = "rustix" -version = "0.38.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" dependencies = [ "bitflags 2.3.3", "errno", "libc", - "linux-raw-sys 0.4.3", + "linux-raw-sys", "windows-sys 0.48.0", ] @@ -2700,9 +2666,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36" +checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" dependencies = [ "log", "ring", @@ -2745,9 +2711,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.101.1" +version = "0.101.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f36a6828982f422756984e47912a7a51dcbc2a197aa791158f8ca61cd8204e" +checksum = "513722fd73ad80a71f72b61009ea1b584bcfa1483ca93949c8f290298837fa59" dependencies = [ "ring", "untrusted", @@ -2755,15 +2721,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc31bd9b61a32c31f9650d18add92aa83a49ba979c143eefd27fe7177b05bd5f" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "safe-proc-macro2" @@ -2841,9 +2807,9 @@ dependencies = [ [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sct" @@ -2867,9 +2833,9 @@ dependencies = [ [[package]] name = "sec1" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0aec48e813d6b90b15f0b8948af3c63483992dee44c03e9930b3eebdabe046e" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ "base16ct", "der", @@ -2912,9 +2878,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -2925,9 +2891,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" dependencies = [ "core-foundation-sys", "libc", @@ -2935,27 +2901,27 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.171" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a16be4fe5320ade08736447e3198294a5ea9a6d44dde6f35f0a5e06859c427a" +checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" dependencies = [ "serde", ] @@ -2972,20 +2938,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.171" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] name = "serde_json" -version = "1.0.102" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5062a995d481b2308b6064e9af76011f2921c35f97b0468811ed9f6cd91dfed" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ "itoa", "ryu", @@ -2994,9 +2960,9 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc4422959dd87a76cb117c191dcbffc20467f06c9100b76721dab370f24d3a" +checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" dependencies = [ "itoa", "serde", @@ -3004,13 +2970,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d89a8107374290037607734c0b73a85db7ed80cae314b3c5791f192a496e731" +checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -3036,9 +3002,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.22" +version = "0.9.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "452e67b9c20c37fa79df53201dc03839651086ed9bbe92b3ca585ca9fdaa7d85" +checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" dependencies = [ "indexmap 2.0.0", "itoa", @@ -3069,7 +3035,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -3252,15 +3218,15 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.25.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6069ca09d878a33f883cc06aaa9718ede171841d3832450354410b718b097232" +checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" dependencies = [ "heck", "proc-macro2", "quote", "rustversion", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -3297,9 +3263,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.25" +version = "2.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" dependencies = [ "proc-macro2", "quote", @@ -3332,23 +3298,22 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" [[package]] name = "tempfile" -version = "3.6.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" dependencies = [ - "autocfg", "cfg-if 1.0.0", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.23", + "rustix", "windows-sys 0.48.0", ] [[package]] name = "tendermint" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a46ec6b25b028097ab682ffae11d09d64fe1e2535833b902f26a278a0f88a705" +checksum = "3f0a7d05cf78524782337f8edd55cbc578d159a16ad4affe2135c92f7dbac7f0" dependencies = [ "bytes", "digest 0.10.7", @@ -3377,9 +3342,9 @@ dependencies = [ [[package]] name = "tendermint-config" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dbb7610ef8422d5886116868e48ab6a9ea72859b3bf9021c6d87318e5600225" +checksum = "71a72dbbea6dde12045d261f2c70c0de039125675e8a026c8d5ad34522756372" dependencies = [ "flex-error", "serde", @@ -3391,9 +3356,9 @@ dependencies = [ [[package]] name = "tendermint-light-client" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9940a1376b5c1e3e5759143bc4308a7114f6293167ca5f05365d3386389de0ff" +checksum = "2e2565f83ec8cc360c9cd1bd9117ab4288d1fdf30f8e0f38dfa6313d2d4daaca" dependencies = [ "contracts", "crossbeam-channel 0.4.4", @@ -3416,9 +3381,9 @@ dependencies = [ [[package]] name = "tendermint-light-client-detector" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "765f272201f8dd04067498421b68a449a48623bf8f4df69b7e50071bec193daf" +checksum = "0f7696348c3ae2b998a8ade48e8c2e5b3a7e18ae3ddbe02ffceb07ce188b91cb" dependencies = [ "contracts", "crossbeam-channel 0.4.4", @@ -3440,9 +3405,9 @@ dependencies = [ [[package]] name = "tendermint-light-client-verifier" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4bc4c47cf36e740645e04128bd14ff5723aef86f5377fbd4d3b0149198dfc7e" +checksum = "9875dce5c1b08201152eb0860f8fb1dce96c53e37532c310ffc4956d20f90def" dependencies = [ "derive_more", "flex-error", @@ -3453,9 +3418,9 @@ dependencies = [ [[package]] name = "tendermint-proto" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23c8ff0e6634eb4c3c4aeed45076dc97dac91aac5501a905a67fa222e165b" +checksum = "c0cec054567d16d85e8c3f6a3139963d1a66d9d3051ed545d31562550e9bcc3d" dependencies = [ "bytes", "flex-error", @@ -3471,9 +3436,9 @@ dependencies = [ [[package]] name = "tendermint-rpc" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2cc789170db5a35d4e0bb2490035c03ef96df08f119bee25fd8dab5a09aa25" +checksum = "d119d83a130537fc4a98c3c9eb6899ebe857fea4860400a61675bfb5f0b35129" dependencies = [ "async-trait", "async-tungstenite", @@ -3507,9 +3472,9 @@ dependencies = [ [[package]] name = "tendermint-testgen" -version = "0.32.0" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023911e751fea64f20cd13bb9e15b5aae283aa3c7aaeb7e9bec1512032b32c99" +checksum = "b376f76ebca915ecb2fb5d608c9dbf8b758e8c4884a6780cb365faa83bc265cd" dependencies = [ "ed25519-consensus", "gumdrop", @@ -3549,22 +3514,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" +checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" +checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -3579,10 +3544,11 @@ dependencies = [ [[package]] name = "time" -version = "0.3.22" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" dependencies = [ + "deranged", "serde", "time-core", "time-macros", @@ -3596,9 +3562,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" dependencies = [ "time-core", ] @@ -3684,7 +3650,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -3715,7 +3681,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.5", + "rustls 0.21.6", "tokio", ] @@ -3776,9 +3742,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.12" +version = "0.19.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78" +checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" dependencies = [ "indexmap 2.0.0", "serde", @@ -3872,7 +3838,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] [[package]] @@ -4005,9 +3971,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "unicode-normalization" @@ -4032,9 +3998,9 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unsafe-libyaml" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1865806a559042e51ab5414598446a5871b561d21b6764f2eabb0dd481d880a6" +checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" [[package]] name = "untrusted" @@ -4055,9 +4021,9 @@ dependencies = [ [[package]] name = "urlencoding" -version = "2.1.2" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" [[package]] name = "utf-8" @@ -4079,9 +4045,9 @@ checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" [[package]] name = "uuid" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ "getrandom 0.2.10", ] @@ -4159,7 +4125,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", "wasm-bindgen-shared", ] @@ -4193,7 +4159,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4417,9 +4383,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.9" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81a2094c43cc94775293eaa0e499fbc30048a6d824ac82c0351a8c0bf9112529" +checksum = "acaaa1190073b2b101e15083c38ee8ec891b5e05cbee516521e94ec008f61e64" dependencies = [ "memchr", ] @@ -4450,5 +4416,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.25", + "syn 2.0.28", ] diff --git a/crates/relayer-types/src/core/ics04_channel/channel.rs b/crates/relayer-types/src/core/ics04_channel/channel.rs index cbf14e9e34..95b6f9d83d 100644 --- a/crates/relayer-types/src/core/ics04_channel/channel.rs +++ b/crates/relayer-types/src/core/ics04_channel/channel.rs @@ -418,19 +418,23 @@ pub enum State { /// A channel has been closed and can no longer be used to send or receive /// packets. Closed = 4, + /// A channel is being upgraded and is flushing in-flight packets. + Flushing = 5, + /// A channel is being upgraded and all in-flight packets have been flushed. + Flushcomplete = 6, /// A channel has just started the upgrade handshake. The chain that is /// proposing the upgrade should set the channel state from OPEN to INITUPGRADE. - InitUpgrade = 5, + InitUpgrade = 7, /// A channel has acknowledged the upgrade handshake step on the counterparty chain. /// The counterparty chain that accepts the upgrade should set the channel state from /// OPEN to TRYUPGRADE. /// The counterparty chain blocks new packets until the channel upgrade is done or cancelled. - TryUpgrade = 6, + TryUpgrade = 8, /// A channel has confirmed the upgrade handshake step on the counterparty chain. /// The chain that confirmed the upgrade should set the channel state from /// INITUPGRADE to ACKUPGRADE. /// The chain blocks new packets until the channel upgrade is done or cancelled. - AckUpgrade = 7, + AckUpgrade = 9, } impl State { @@ -442,6 +446,8 @@ impl State { Self::TryOpen => "TRYOPEN", Self::Open => "OPEN", Self::Closed => "CLOSED", + Self::Flushing => "FLUSHING", + Self::Flushcomplete => "FLUSHCOMPLETE", Self::InitUpgrade => "INITUPGRADE", Self::TryUpgrade => "TRYUPGRADE", Self::AckUpgrade => "ACKUPGRADE", @@ -456,9 +462,11 @@ impl State { 2 => Ok(Self::TryOpen), 3 => Ok(Self::Open), 4 => Ok(Self::Closed), - 5 => Ok(Self::InitUpgrade), - 6 => Ok(Self::TryUpgrade), - 7 => Ok(Self::AckUpgrade), + 5 => Ok(Self::Flushing), + 6 => Ok(Self::Flushcomplete), + 7 => Ok(Self::InitUpgrade), + 8 => Ok(Self::TryUpgrade), + 9 => Ok(Self::AckUpgrade), _ => Err(Error::unknown_state(s)), } } @@ -492,11 +500,27 @@ impl State { TryOpen => !matches!(other, Uninitialized | Init), Open => !matches!(other, Uninitialized | Init | TryOpen), - InitUpgrade => !matches!(other, Uninitialized | Init | TryOpen | Open), - TryUpgrade => !matches!(other, Uninitialized | Init | TryOpen | Open | InitUpgrade), + Flushing => !matches!(other, Uninitialized | Init | TryOpen | Open), + Flushcomplete => !matches!(other, Uninitialized | Init | TryOpen | Open | Flushing), + + InitUpgrade => !matches!( + other, + Uninitialized | Init | TryOpen | Open | Flushing | Flushcomplete + ), + TryUpgrade => !matches!( + other, + Uninitialized | Init | TryOpen | Open | Flushing | Flushcomplete | InitUpgrade + ), AckUpgrade => !matches!( other, - Uninitialized | Init | TryOpen | Open | InitUpgrade | TryUpgrade + Uninitialized + | Init + | TryOpen + | Open + | Flushing + | Flushcomplete + | InitUpgrade + | TryUpgrade ), Closed => false, diff --git a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs index 46855c7620..51d82672ee 100644 --- a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs +++ b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs @@ -80,7 +80,16 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { let new_ordering = None; let new_connection_hops = None; - let old_attrs = ChannelUpgradableAttributes::new( + let initial_attrs = ChannelUpgradableAttributes::new( + old_version.clone(), + old_version.clone(), + old_ordering, + old_connection_hops_a.clone(), + old_connection_hops_b.clone(), + ); + + let intermediary_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), old_version, old_ordering, old_connection_hops_a.clone(), @@ -88,6 +97,7 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { ); let upgraded_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), new_version.clone(), old_ordering, old_connection_hops_a, @@ -117,7 +127,7 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { &chains.handle_b, &channels.channel_id_a.as_ref(), &channels.port_a.as_ref(), - &old_attrs, + &initial_attrs, )?; info!("Will run ChanUpgradeTry step..."); @@ -131,7 +141,7 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { &chains.handle_a, &channels.channel_id_b.as_ref(), &channels.port_b.as_ref(), - &old_attrs.flipped(), + &initial_attrs.flipped(), )?; info!("Will run ChanUpgradeAck step..."); @@ -145,17 +155,13 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { &chains.handle_b, &channels.channel_id_a.as_ref(), &channels.port_a.as_ref(), - &old_attrs, + &intermediary_attrs, )?; info!("Will run first ChanUpgradeOpen step..."); channel.build_chan_upgrade_open_and_send()?; - info!("Will run second ChanUpgradeOpen step..."); - - channel.flipped().build_chan_upgrade_open_and_send()?; - info!("Check that the ChanUpgradeOpen steps were correctly executed..."); assert_eventually_channel_upgrade_open( diff --git a/tools/test-framework/src/relayer/channel.rs b/tools/test-framework/src/relayer/channel.rs index 688cf1c0f0..944931de97 100644 --- a/tools/test-framework/src/relayer/channel.rs +++ b/tools/test-framework/src/relayer/channel.rs @@ -38,7 +38,8 @@ impl TaggedChannelEndExt /// This struct contains the attributes which can be modified with a channel upgrade pub struct ChannelUpgradableAttributes { - version: Version, + version_a: Version, + version_b: Version, ordering: Ordering, connection_hops_a: Vec, connection_hops_b: Vec, @@ -46,13 +47,15 @@ pub struct ChannelUpgradableAttributes { impl ChannelUpgradableAttributes { pub fn new( - version: Version, + version_a: Version, + version_b: Version, ordering: Ordering, connection_hops_a: Vec, connection_hops_b: Vec, ) -> Self { Self { - version, + version_a, + version_b, ordering, connection_hops_a, connection_hops_b, @@ -61,15 +64,20 @@ impl ChannelUpgradableAttributes { pub fn flipped(&self) -> Self { Self { - version: self.version.clone(), + version_a: self.version_b.clone(), + version_b: self.version_a.clone(), ordering: self.ordering, connection_hops_a: self.connection_hops_b.clone(), connection_hops_b: self.connection_hops_a.clone(), } } - pub fn version(&self) -> &Version { - &self.version + pub fn version_a(&self) -> &Version { + &self.version_a + } + + pub fn version_b(&self) -> &Version { + &self.version_b } pub fn ordering(&self) -> &Ordering { @@ -334,9 +342,11 @@ pub fn assert_eventually_channel_upgrade_ack( if !channel_end_a .value() - .version_matches(upgrade_attrs.version()) + .version_matches(upgrade_attrs.version_a()) { return Err(Error::generic(eyre!( "expected channel end A version to be `{}`, but it is instead `{}`", - upgrade_attrs.version(), + upgrade_attrs.version_a(), channel_end_a.value().version() ))); } @@ -471,11 +481,11 @@ fn assert_channel_upgrade_state( if !channel_end_b .value() - .version_matches(upgrade_attrs.version()) + .version_matches(upgrade_attrs.version_b()) { return Err(Error::generic(eyre!( "expected channel end B version to be `{}`, but it is instead `{}`", - upgrade_attrs.version(), + upgrade_attrs.version_b(), channel_end_b.value().version() ))); } From f3ad7611b523ddd57074f5f7d8cc16aa0037528d Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Wed, 9 Aug 2023 12:23:35 +0200 Subject: [PATCH 09/26] WIP: waiting for new channel states during upgrade to be implemented --- crates/relayer-cli/src/commands/tx/channel.rs | 40 +----- crates/relayer-types/Cargo.toml | 1 + .../src/core/ics04_channel/events.rs | 9 +- crates/relayer-types/src/events.rs | 12 +- crates/relayer/src/chain/counterparty.rs | 2 + crates/relayer/src/channel.rs | 119 ++++++++---------- crates/relayer/src/channel/error.rs | 3 +- crates/relayer/src/event/source/rpc.rs | 2 + .../src/event/source/websocket/extract.rs | 9 ++ crates/relayer/src/object.rs | 33 +++++ crates/relayer/src/supervisor.rs | 28 +++++ crates/relayer/src/worker/channel.rs | 49 +++++--- .../channel_upgrade/manual_channel_upgrade.rs | 4 +- 13 files changed, 186 insertions(+), 125 deletions(-) diff --git a/crates/relayer-cli/src/commands/tx/channel.rs b/crates/relayer-cli/src/commands/tx/channel.rs index 3133d03062..3e5cb97e08 100644 --- a/crates/relayer-cli/src/commands/tx/channel.rs +++ b/crates/relayer-cli/src/commands/tx/channel.rs @@ -888,22 +888,6 @@ pub struct TxChanUpgradeTryCmd { help = "Identifier of the destination channel (optional)" )] dst_chan_id: Option, - - #[clap( - long = "timeout-height", - required = false, - value_name = "TIMEOUT_HEIGHT", - help = "Height that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout timestamp is specified." - )] - timeout_height: Option, - - #[clap( - long = "timeout-time", - required = false, - value_name = "TIMEOUT_TIME", - help = "Timeout in human readable format since current that, once it has been surpassed on the originating chain, the upgrade will time out. Required if no timeout height is specified." - )] - timeout_time: Option, } impl Runnable for TxChanUpgradeTryCmd { @@ -915,28 +899,6 @@ impl Runnable for TxChanUpgradeTryCmd { Err(e) => Output::error(format!("{}", e)).exit(), }; - let dst_chain_status = match chains.dst.query_application_status() { - Ok(application_status) => application_status, - Err(e) => Output::error(format!("query_application_status error {}", e)).exit(), - }; - - let timeout_timestamp = self - .timeout_time - .map(|timeout_time| (dst_chain_status.timestamp + *timeout_time).unwrap()); - - // Check that at least one of timeout_height and timeout_timestamp has been provided - let Ok(timeout) = UpgradeTimeout::new(self.timeout_height, timeout_timestamp) else { - Output::error( - "At least one of --timeout-height or --timeout-timestamp must be specified.", - ) - .exit(); - }; - - let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) { - Ok(chains) => chains, - Err(e) => Output::error(format!("{}", e)).exit(), - }; - // Retrieve the connection let dst_connection = match chains.dst.query_connection( QueryConnectionRequest { @@ -975,7 +937,7 @@ impl Runnable for TxChanUpgradeTryCmd { info!("message ChanUpgradeTry: {}", channel); let res: Result = channel - .build_chan_upgrade_try_and_send(timeout) + .build_chan_upgrade_try_and_send() .map_err(Error::channel); match res { diff --git a/crates/relayer-types/Cargo.toml b/crates/relayer-types/Cargo.toml index 4206e6b0bb..3a3dddf78d 100644 --- a/crates/relayer-types/Cargo.toml +++ b/crates/relayer-types/Cargo.toml @@ -42,6 +42,7 @@ itertools = { version = "0.10.3" } primitive-types = { version = "0.12.1", default-features = false, features = ["serde_no_std"] } dyn-clone = "1.0.12" num-rational = "0.4.1" +tracing = "0.1.36" [dependencies.tendermint] version = "0.32.0" diff --git a/crates/relayer-types/src/core/ics04_channel/events.rs b/crates/relayer-types/src/core/ics04_channel/events.rs index 42eca22569..3fdd9eeed8 100644 --- a/crates/relayer-types/src/core/ics04_channel/events.rs +++ b/crates/relayer-types/src/core/ics04_channel/events.rs @@ -149,7 +149,14 @@ pub struct UpgradeAttributes { pub channel_flush_status: FlushStatus, } -impl UpgradeAttributes {} +impl UpgradeAttributes { + pub fn port_id(&self) -> &PortId { + &self.port_id + } + pub fn channel_id(&self) -> &ChannelId { + &self.channel_id + } +} impl Display for UpgradeAttributes { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { diff --git a/crates/relayer-types/src/events.rs b/crates/relayer-types/src/events.rs index a5a30fce81..7d0cfa1576 100644 --- a/crates/relayer-types/src/events.rs +++ b/crates/relayer-types/src/events.rs @@ -19,8 +19,8 @@ use crate::core::ics03_connection::error as connection_error; use crate::core::ics03_connection::events as ConnectionEvents; use crate::core::ics03_connection::events::Attributes as ConnectionAttributes; use crate::core::ics04_channel::error as channel_error; -use crate::core::ics04_channel::events as ChannelEvents; use crate::core::ics04_channel::events::Attributes as ChannelAttributes; +use crate::core::ics04_channel::events::{self as ChannelEvents, UpgradeAttributes}; use crate::core::ics04_channel::packet::Packet; use crate::core::ics24_host::error::ValidationError; use crate::timestamp::ParseTimestampError; @@ -442,6 +442,16 @@ impl IbcEvent { } } + pub fn channel_upgrade_attributes(self) -> Option { + match self { + IbcEvent::UpgradeInitChannel(ev) => Some(ev.into()), + IbcEvent::UpgradeTryChannel(ev) => Some(ev.into()), + IbcEvent::UpgradeAckChannel(ev) => Some(ev.into()), + IbcEvent::UpgradeOpenChannel(ev) => Some(ev.into()), + _ => None, + } + } + pub fn connection_attributes(&self) -> Option<&ConnectionAttributes> { match self { IbcEvent::OpenInitConnection(ev) => Some(ev.attributes()), diff --git a/crates/relayer/src/chain/counterparty.rs b/crates/relayer/src/chain/counterparty.rs index ac34d84f40..323a5477af 100644 --- a/crates/relayer/src/chain/counterparty.rs +++ b/crates/relayer/src/chain/counterparty.rs @@ -304,6 +304,8 @@ pub fn channel_on_destination( }) .map_err(Error::relayer)?; + tracing::info!("counterparty on channel_on_destination: {counterparty:#?}"); + Ok(Some(counterparty)) } else if let Some(remote_connection_id) = connection.end().counterparty().connection_id() { fetch_channel_on_destination( diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index 5057feba24..c1512021bb 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -313,6 +313,8 @@ impl Channel { ) .map_err(ChannelError::relayer)?; + tracing::info!("Channel A from restore_from_state: {a_channel:#?}"); + let a_connection_id = a_channel.connection_hops().first().ok_or_else(|| { ChannelError::supervisor(SupervisorError::missing_connection_hops( channel.src_channel_id.clone(), @@ -761,6 +763,11 @@ impl Channel { &mut self, state: State, ) -> Result<(Option, Next), ChannelError> { + tracing::info!( + "state: {}, counterparty state: {}", + state, + self.counterparty_state()? + ); let event = match (state, self.counterparty_state()?) { // Open handshake steps (State::Init, State::Uninitialized) => Some(self.build_chan_open_try_and_send()?), @@ -778,15 +785,42 @@ impl Channel { (State::Closed, State::Closed) => return Ok((None, Next::Abort)), (State::Closed, _) => Some(self.build_chan_close_confirm_and_send()?), + (State::InitUpgrade, State::Open) => { + tracing::info!("handshake_step from InitUpgrade state"); + Some(self.build_chan_upgrade_try_and_send()?) + } + + (State::InitUpgrade, State::InitUpgrade) => { + tracing::info!("handshake_step from InitUpgrade state 2"); + Some(self.build_chan_upgrade_try_and_send()?) + } + + (State::TryUpgrade, State::InitUpgrade) => { + tracing::info!("handshake_step from TryUpgrade state"); + Some(self.build_chan_upgrade_ack_and_send()?) + } + + (State::Open, State::TryUpgrade) => { + tracing::info!("handshake_step from OpenUpgrade state"); + Some(self.build_chan_upgrade_open_and_send()?) + } + _ => None, }; + tracing::info!( + "Resulting event from build_chan_upgrade_try_and_send: {:#?}", + event + ); + // Abort if the channel is at OpenAck, OpenConfirm or CloseConfirm stage, as there is // nothing more for the worker to do match event { Some(IbcEvent::OpenConfirmChannel(_)) | Some(IbcEvent::OpenAckChannel(_)) - | Some(IbcEvent::CloseConfirmChannel(_)) => Ok((event, Next::Abort)), + | Some(IbcEvent::CloseConfirmChannel(_)) + | Some(IbcEvent::UpgradeAckChannel(_)) + | Some(IbcEvent::UpgradeOpenChannel(_)) => Ok((event, Next::Abort)), _ => Ok((event, Next::Continue)), } } @@ -802,7 +836,7 @@ impl Channel { RetryResult::Err(index) } else { error!("failed Chan{} with error: {}", state, e); - RetryResult::Retry(index) + RetryResult::Err(index) } } Ok((Some(ev), handshake_completed)) => { @@ -820,6 +854,10 @@ impl Channel { IbcEvent::OpenAckChannel(_) => State::Open, IbcEvent::OpenConfirmChannel(_) => State::Open, IbcEvent::CloseInitChannel(_) => State::Closed, + IbcEvent::UpgradeInitChannel(_) => State::InitUpgrade, + IbcEvent::UpgradeTryChannel(_) => State::TryUpgrade, + IbcEvent::UpgradeAckChannel(_) => State::AckUpgrade, + IbcEvent::UpgradeOpenChannel(_) => State::Open, _ => State::Uninitialized, }; @@ -1510,7 +1548,10 @@ impl Channel { .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; if channel_end.state != State::Open { - return Err(ChannelError::invalid_channel_upgrade_state()); + return Err(ChannelError::invalid_channel_upgrade_state( + channel_end.state.to_string(), + State::Open.to_string(), + )); } if let Some(new_ordering) = new_ordering { @@ -1594,10 +1635,7 @@ impl Channel { } } - pub fn build_chan_upgrade_try( - &self, - timeout: UpgradeTimeout, - ) -> Result, ChannelError> { + pub fn build_chan_upgrade_try(&self) -> Result, ChannelError> { let src_channel_id = self .src_channel_id() .ok_or_else(ChannelError::missing_local_channel_id)?; @@ -1691,7 +1729,10 @@ impl Channel { } if channel_end.state != State::InitUpgrade { - return Err(ChannelError::invalid_channel_upgrade_state()); + return Err(ChannelError::invalid_channel_upgrade_state( + channel_end.state.to_string(), + State::InitUpgrade.to_string(), + )); } let signer = self @@ -1704,7 +1745,7 @@ impl Channel { port_id: dst_port_id.clone(), channel_id: dst_channel_id.clone(), proposed_upgrade_connection_hops: dst_channel_end.connection_hops, - upgrade_timeout: timeout, + upgrade_timeout: upgrade.timeout.clone(), counterparty_proposed_upgrade: upgrade, counterparty_upgrade_sequence: channel_end.upgraded_sequence, proof_channel: src_proof.object_proof().clone(), @@ -1720,11 +1761,8 @@ impl Channel { Ok(chain_a_msgs) } - pub fn build_chan_upgrade_try_and_send( - &self, - timeout: UpgradeTimeout, - ) -> Result { - let dst_msgs = self.build_chan_upgrade_try(timeout)?; + pub fn build_chan_upgrade_try_and_send(&self) -> Result { + let dst_msgs = self.build_chan_upgrade_try()?; let tm = TrackedMsgs::new_static(dst_msgs, "ChannelUpgradeTry"); @@ -1977,59 +2015,6 @@ impl Channel { connection_delay: self.connection_delay, } } - - pub fn get_upgrade_fields( - &self, - new_version: Option, - new_ordering: Option, - new_connection_hops: Option>, - ) -> Result { - // Destination channel ID must exist - let channel_id = self - .dst_channel_id() - .ok_or_else(ChannelError::missing_counterparty_channel_id)?; - - let port_id = self.dst_port_id(); - - // Channel must exist on destination - let (mut channel_end, _proof) = self - .dst_chain() - .query_channel( - QueryChannelRequest { - port_id: port_id.clone(), - channel_id: channel_id.clone(), - height: QueryHeight::Latest, - }, - IncludeProof::No, - ) - .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; - - if channel_end.state != State::Open { - return Err(ChannelError::invalid_channel_upgrade_state()); - } - - if let Some(new_ordering) = new_ordering { - if new_ordering == Ordering::Uninitialized || new_ordering > channel_end.ordering { - return Err(ChannelError::invalid_channel_upgrade_ordering()); - } - - channel_end.ordering = new_ordering; - } - - if let Some(new_version) = new_version { - channel_end.version = new_version; - } - - if let Some(new_connection_hops) = new_connection_hops { - channel_end.connection_hops = new_connection_hops; - } - - Ok(UpgradeFields::new( - channel_end.ordering, - channel_end.connection_hops, - channel_end.version, - )) - } } pub fn extract_channel_id(event: &IbcEvent) -> Result<&ChannelId, ChannelError> { diff --git a/crates/relayer/src/channel/error.rs b/crates/relayer/src/channel/error.rs index ff8b0809b8..ebece322b4 100644 --- a/crates/relayer/src/channel/error.rs +++ b/crates/relayer/src/channel/error.rs @@ -39,7 +39,8 @@ define_error! { |_| { "attempted to upgrade a channel to a more strict ordring, which is not allowed" }, InvalidChannelUpgradeState - |_| { "attempted to upgrade a channel that is not in the OPEN state" }, + { state: String, expected: String } + | e | { format_args!("attempted to upgrade a channel that is in the state {} instead of the state {}", e.state, e.expected) }, InvalidChannelUpgradeTimeout |_| { "attempted to upgrade a channel without supplying at least one of timeout height or timeout timestamp" }, diff --git a/crates/relayer/src/event/source/rpc.rs b/crates/relayer/src/event/source/rpc.rs index b684cc6590..4fa475cac4 100644 --- a/crates/relayer/src/event/source/rpc.rs +++ b/crates/relayer/src/event/source/rpc.rs @@ -220,6 +220,8 @@ impl EventSource { } } + debug!("fetched batch: {batches:#?}"); + Ok(batches) } diff --git a/crates/relayer/src/event/source/websocket/extract.rs b/crates/relayer/src/event/source/websocket/extract.rs index 97ff858a98..cb7c08e0ca 100644 --- a/crates/relayer/src/event/source/websocket/extract.rs +++ b/crates/relayer/src/event/source/websocket/extract.rs @@ -127,6 +127,7 @@ pub fn extract_events( query, } = result; let events = events.ok_or("missing events")?; + tracing::debug!("query: {query}"); match data { RpcEventData::NewBlock { block, .. } if query == queries::new_block().to_string() => { @@ -150,6 +151,7 @@ pub fn extract_events( .map_err(|_| String::from("tx_result.height: invalid header height of 0"))?; for abci_event in &tx_result.result.events { + tracing::debug!("abci event: {abci_event:#?}"); if let Ok(ibc_event) = ibc_event_try_from_abci_event(abci_event) { if query == queries::ibc_client().to_string() && event_is_type_client(&ibc_event) @@ -201,6 +203,9 @@ pub fn extract_events( _ => {} } + tracing::debug!("Events:"); + tracing::debug!("{events_with_height:#?}"); + Ok(events_with_height) } @@ -233,6 +238,10 @@ fn event_is_type_channel(ev: &IbcEvent) -> bool { | IbcEvent::OpenConfirmChannel(_) | IbcEvent::CloseInitChannel(_) | IbcEvent::CloseConfirmChannel(_) + | IbcEvent::UpgradeInitChannel(_) + | IbcEvent::UpgradeTryChannel(_) + | IbcEvent::UpgradeAckChannel(_) + | IbcEvent::UpgradeOpenChannel(_) | IbcEvent::SendPacket(_) | IbcEvent::ReceivePacket(_) | IbcEvent::WriteAcknowledgement(_) diff --git a/crates/relayer/src/object.rs b/crates/relayer/src/object.rs index 9f7349734d..eea5e2f60c 100644 --- a/crates/relayer/src/object.rs +++ b/crates/relayer/src/object.rs @@ -1,6 +1,7 @@ use std::fmt::Display; use flex_error::define_error; +use ibc_relayer_types::core::ics04_channel::events::UpgradeAttributes; use serde::{Deserialize, Serialize}; use ibc_relayer_types::applications::ics29_fee::events::IncentivizedPacket; @@ -460,6 +461,38 @@ impl Object { .into()) } + pub fn channel_from_chan_upgrade_events( + attributes: &UpgradeAttributes, + src_chain: &impl ChainHandle, + allow_non_open_connection: bool, + ) -> Result { + let channel_id = attributes.channel_id(); + + let port_id = attributes.port_id(); + + let dst_chain_id = if allow_non_open_connection { + // Get the destination chain allowing for the possibility that the connection is not yet open. + // This is to support the optimistic channel handshake by allowing the channel worker to get + // the channel events while the connection is being established. + // The channel worker will eventually finish the channel handshake via the retry mechanism. + channel_connection_client_no_checks(src_chain, port_id, channel_id) + .map(|c| c.client.client_state.chain_id()) + .map_err(ObjectError::supervisor)? + } else { + channel_connection_client(src_chain, port_id, channel_id) + .map(|c| c.client.client_state.chain_id()) + .map_err(ObjectError::supervisor)? + }; + + Ok(Channel { + dst_chain_id, + src_chain_id: src_chain.id(), + src_channel_id: channel_id.clone(), + src_port_id: port_id.clone(), + } + .into()) + } + /// Build the object associated with the given [`SendPacket`] event. pub fn for_send_packet( e: &SendPacket, diff --git a/crates/relayer/src/supervisor.rs b/crates/relayer/src/supervisor.rs index dac0ef62bc..d0ab46aac2 100644 --- a/crates/relayer/src/supervisor.rs +++ b/crates/relayer/src/supervisor.rs @@ -539,6 +539,30 @@ pub fn collect_events( || Object::client_from_chan_open_events(&attributes, src_chain).ok(), ); } + IbcEvent::UpgradeInitChannel(..) + | IbcEvent::UpgradeTryChannel(..) + | IbcEvent::UpgradeAckChannel(..) + | IbcEvent::UpgradeOpenChannel(..) => { + collect_event( + &mut collected, + event_with_height.clone(), + mode.channels.enabled, + || { + event_with_height + .event + .clone() + .channel_upgrade_attributes() + .and_then(|attr| { + Object::channel_from_chan_upgrade_events( + &attr, + src_chain, + mode.connections.enabled, + ) + .ok() + }) + }, + ); + } IbcEvent::SendPacket(ref packet) => { collect_event( &mut collected, @@ -759,8 +783,12 @@ fn process_batch( telemetry!(received_event_batch, batch.tracking_id); + tracing::debug!("Events to collect: {batch:#?}"); + let collected = collect_events(config, workers, &src_chain, batch); + tracing::debug!("collected events to collect: {collected:#?}"); + // If there is a NewBlock event, forward this event first to any workers affected by it. if let Some(IbcEvent::NewBlock(new_block)) = collected.new_block { workers.notify_new_block(&src_chain.id(), batch.height, new_block); diff --git a/crates/relayer/src/worker/channel.rs b/crates/relayer/src/worker/channel.rs index a6204a3df4..42102efb60 100644 --- a/crates/relayer/src/worker/channel.rs +++ b/crates/relayer/src/worker/channel.rs @@ -1,5 +1,6 @@ use core::time::Duration; use crossbeam_channel::Receiver; +use ibc_relayer_types::events::IbcEventType; use tracing::{debug, error_span}; use crate::channel::{channel_handshake_retry, Channel as RelayChannel}; @@ -44,24 +45,44 @@ pub fn spawn_channel_worker( WorkerCmd::IbcEvents { batch } => { // there can be up to two event for this channel, e.g. init and try. // process the last event, the one with highest "rank". + tracing::info!("batch events: {:#?}", batch.events); let last_event = batch.events.last(); - debug!("starts processing {:?}", last_event); + tracing::info!("starts processing {:?}", last_event); complete_handshake_on_new_block = false; if let Some(event_with_height) = last_event { - retry_with_index( - channel_handshake_retry::default_strategy(max_block_times), - |index| match RelayChannel::restore_from_event( - chains.a.clone(), - chains.b.clone(), - event_with_height.event.clone(), - ) { - Ok(mut handshake_channel) => handshake_channel - .step_event(&event_with_height.event, index), - Err(_) => RetryResult::Retry(index), - }, - ) - .map_err(|e| TaskError::Fatal(RunError::retry(e))) + match event_with_height.event.event_type() { + IbcEventType::UpgradeInitChannel + | IbcEventType::UpgradeTryChannel + | IbcEventType::UpgradeAckChannel + | IbcEventType::UpgradeOpenChannel => retry_with_index( + channel_handshake_retry::default_strategy(max_block_times), + |index| match RelayChannel::restore_from_state( + chains.a.clone(), + chains.b.clone(), + channel.clone(), + event_with_height.height, + ) { + Ok((mut handshake_channel, _)) => handshake_channel + .step_event(&event_with_height.event, index), + Err(_) => RetryResult::Retry(index), + }, + ) + .map_err(|e| TaskError::Fatal(RunError::retry(e))), + _ => retry_with_index( + channel_handshake_retry::default_strategy(max_block_times), + |index| match RelayChannel::restore_from_event( + chains.a.clone(), + chains.b.clone(), + event_with_height.event.clone(), + ) { + Ok(mut handshake_channel) => handshake_channel + .step_event(&event_with_height.event, index), + Err(_) => RetryResult::Retry(index), + }, + ) + .map_err(|e| TaskError::Fatal(RunError::retry(e))), + } } else { Ok(Next::Continue) } diff --git a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs index 51d82672ee..58da0844d0 100644 --- a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs +++ b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs @@ -117,7 +117,7 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { Some(new_version), new_ordering, new_connection_hops, - timeout.clone(), + timeout, )?; info!("Check that the step ChanUpgradeInit was correctly executed..."); @@ -132,7 +132,7 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { info!("Will run ChanUpgradeTry step..."); - channel.build_chan_upgrade_try_and_send(timeout)?; + channel.build_chan_upgrade_try_and_send()?; info!("Check that the step ChanUpgradeTry was correctly executed..."); From f9ee86e0377ca6d73f0127c5cc5413f5735cab87 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 28 Aug 2023 12:49:59 +0200 Subject: [PATCH 10/26] Implement channel upgrade handshake --- .../src/core/ics04_channel/channel.rs | 101 ++++++++++-------- .../msgs/chan_upgrade_confirm.rs | 2 +- .../ics04_channel/msgs/chan_upgrade_open.rs | 2 +- crates/relayer-types/src/events.rs | 1 + crates/relayer/src/chain/counterparty.rs | 2 +- crates/relayer/src/channel.rs | 73 ++++++------- .../src/event/source/websocket/extract.rs | 1 + crates/relayer/src/link.rs | 4 +- crates/relayer/src/worker/channel.rs | 1 + tools/test-framework/src/relayer/channel.rs | 24 +++-- 10 files changed, 111 insertions(+), 100 deletions(-) diff --git a/crates/relayer-types/src/core/ics04_channel/channel.rs b/crates/relayer-types/src/core/ics04_channel/channel.rs index 2cc4705398..18117ebb4f 100644 --- a/crates/relayer-types/src/core/ics04_channel/channel.rs +++ b/crates/relayer-types/src/core/ics04_channel/channel.rs @@ -59,7 +59,7 @@ impl TryFrom for IdentifiedChannelEnd { impl From for RawIdentifiedChannel { fn from(value: IdentifiedChannelEnd) -> Self { RawIdentifiedChannel { - state: value.channel_end.state as i32, + state: value.channel_end.state.into_i32(), ordering: value.channel_end.ordering as i32, counterparty: Some(value.channel_end.counterparty().clone().into()), connection_hops: value @@ -157,7 +157,7 @@ impl TryFrom for ChannelEnd { impl From for RawChannel { fn from(value: ChannelEnd) -> Self { RawChannel { - state: value.state as i32, + state: value.state.into_i32(), ordering: value.ordering as i32, counterparty: Some(value.counterparty().clone().into()), connection_hops: value @@ -207,9 +207,11 @@ impl ChannelEnd { self.remote.channel_id = Some(c); } - /// Returns `true` if this `ChannelEnd` is in state [`State::Open`]. + /// Returns `true` if this `ChannelEnd` is in state [`State::Open`] + /// [`State::Open(UpgradeState::Upgrading)`] is only used in the channel upgrade + /// handshake so this method matches with [`State::Open(UpgradeState::NotUpgrading)`]. pub fn is_open(&self) -> bool { - self.state_matches(&State::Open) + self.state_matches(&State::Open(UpgradeState::NotUpgrading)) } pub fn state(&self) -> &State { @@ -397,6 +399,15 @@ impl FromStr for Ordering { } } +/// This enum is used to differentiate if a channel is being upgraded when +/// a `UpgradeInitChannel` or a `UpgradeOpenChannel` is received. +/// See `handshake_step` method in `crates/relayer/src/channel.rs`. +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum UpgradeState { + Upgrading, + NotUpgrading, +} + /// The possible state variants that a channel can exhibit. /// /// These are encoded with integer discriminants so that there is @@ -407,34 +418,25 @@ impl FromStr for Ordering { #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum State { /// Default state - Uninitialized = 0, + Uninitialized, /// A channel has just started the opening handshake. - Init = 1, + Init, /// A channel has acknowledged the handshake step on the counterparty chain. - TryOpen = 2, + TryOpen, /// A channel has completed the handshake step. Open channels are ready to /// send and receive packets. - Open = 3, + /// During some steps of channel upgrades, the state is still in Open. The + /// `UpgradeState` is used to differentiate these states during the upgrade + /// handshake. + /// https://github.com/cosmos/ibc/blob/main/spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md#upgrade-handshake + Open(UpgradeState), /// A channel has been closed and can no longer be used to send or receive /// packets. - Closed = 4, + Closed, /// A channel has just accepted the upgrade handshake attempt and is flushing in-flight packets. - Flushing = 5, + Flushing, /// A channel has just completed flushing any in-flight packets. - Flushcomplete = 6, - /// A channel has just started the upgrade handshake. The chain that is - /// proposing the upgrade should set the channel state from OPEN to INITUPGRADE. - InitUpgrade = 7, - /// A channel has acknowledged the upgrade handshake step on the counterparty chain. - /// The counterparty chain that accepts the upgrade should set the channel state from - /// OPEN to TRYUPGRADE. - /// The counterparty chain blocks new packets until the channel upgrade is done or cancelled. - TryUpgrade = 8, - /// A channel has confirmed the upgrade handshake step on the counterparty chain. - /// The chain that confirmed the upgrade should set the channel state from - /// INITUPGRADE to ACKUPGRADE. - /// The chain blocks new packets until the channel upgrade is done or cancelled. - AckUpgrade = 9, + Flushcomplete, } impl State { @@ -444,13 +446,10 @@ impl State { Self::Uninitialized => "UNINITIALIZED", Self::Init => "INIT", Self::TryOpen => "TRYOPEN", - Self::Open => "OPEN", + Self::Open(_) => "OPEN", Self::Closed => "CLOSED", Self::Flushing => "FLUSHING", Self::Flushcomplete => "FLUSHCOMPLETE", - Self::InitUpgrade => "INITUPGRADE", - Self::TryUpgrade => "TRYUPGRADE", - Self::AckUpgrade => "ACKUPGRADE", } } @@ -460,20 +459,30 @@ impl State { 0 => Ok(Self::Uninitialized), 1 => Ok(Self::Init), 2 => Ok(Self::TryOpen), - 3 => Ok(Self::Open), + 3 => Ok(Self::Open(UpgradeState::NotUpgrading)), 4 => Ok(Self::Closed), 5 => Ok(Self::Flushing), 6 => Ok(Self::Flushcomplete), - 7 => Ok(Self::InitUpgrade), - 8 => Ok(Self::TryUpgrade), - 9 => Ok(Self::AckUpgrade), _ => Err(Error::unknown_state(s)), } } + // Parses the State out from a i32. + pub fn into_i32(&self) -> i32 { + match self { + State::Uninitialized => 0, + State::Init => 1, + State::TryOpen => 2, + State::Open(_) => 3, + State::Closed => 4, + State::Flushing => 5, + State::Flushcomplete => 6, + } + } + /// Returns whether or not this channel state is `Open`. pub fn is_open(self) -> bool { - self == State::Open + self == State::Open(UpgradeState::NotUpgrading) } /// Returns whether or not this channel state is `Closed`. @@ -498,28 +507,28 @@ impl State { Init => !matches!(other, Uninitialized), TryOpen => !matches!(other, Uninitialized | Init), - Open => !matches!(other, Uninitialized | Init | TryOpen), - - Flushing => !matches!(other, Uninitialized | Init | TryOpen | Open), - Flushcomplete => !matches!(other, Uninitialized | Init | TryOpen | Open | Flushing), - InitUpgrade => !matches!( + Open(UpgradeState::NotUpgrading) => !matches!(other, Uninitialized | Init | TryOpen), + Open(UpgradeState::Upgrading) => !matches!( other, - Uninitialized | Init | TryOpen | Open | Flushing | Flushcomplete + Uninitialized | Init | TryOpen | Open(UpgradeState::NotUpgrading) ), - TryUpgrade => !matches!( + + Flushing => !matches!( other, - Uninitialized | Init | TryOpen | Open | Flushing | Flushcomplete | InitUpgrade + Uninitialized + | Init + | TryOpen + | Open(UpgradeState::NotUpgrading) + | Open(UpgradeState::Upgrading) ), - AckUpgrade => !matches!( + Flushcomplete => !matches!( other, Uninitialized | Init | TryOpen - | Open + | Open(UpgradeState::NotUpgrading) + | Open(UpgradeState::Upgrading) | Flushing - | Flushcomplete - | InitUpgrade - | TryUpgrade ), Closed => false, diff --git a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs index fb3c0ed1eb..338f2f1d98 100644 --- a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs +++ b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs @@ -108,7 +108,7 @@ impl From for RawMsgChannelUpgradeConfirm { RawMsgChannelUpgradeConfirm { port_id: domain_msg.port_id.to_string(), channel_id: domain_msg.channel_id.to_string(), - counterparty_channel_state: domain_msg.counterparty_channel_state as i32, + counterparty_channel_state: domain_msg.counterparty_channel_state.into_i32(), counterparty_upgrade: Some(domain_msg.counterparty_upgrade.into()), proof_upgrade: domain_msg.proof_upgrade.into(), proof_channel: domain_msg.proof_channel.into(), diff --git a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs index 841a97ee45..48b818779b 100644 --- a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs +++ b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs @@ -90,7 +90,7 @@ impl From for RawMsgChannelUpgradeOpen { RawMsgChannelUpgradeOpen { port_id: domain_msg.port_id.to_string(), channel_id: domain_msg.channel_id.to_string(), - counterparty_channel_state: domain_msg.counterparty_channel_state as i32, + counterparty_channel_state: domain_msg.counterparty_channel_state.into_i32(), proof_channel: domain_msg.proof_channel.into(), proof_height: Some(domain_msg.proof_height.into()), signer: domain_msg.signer.to_string(), diff --git a/crates/relayer-types/src/events.rs b/crates/relayer-types/src/events.rs index c3445acd41..caff7a421a 100644 --- a/crates/relayer-types/src/events.rs +++ b/crates/relayer-types/src/events.rs @@ -455,6 +455,7 @@ impl IbcEvent { IbcEvent::UpgradeInitChannel(ev) => Some(ev.into()), IbcEvent::UpgradeTryChannel(ev) => Some(ev.into()), IbcEvent::UpgradeAckChannel(ev) => Some(ev.into()), + IbcEvent::UpgradeConfirmChannel(ev) => Some(ev.into()), IbcEvent::UpgradeOpenChannel(ev) => Some(ev.into()), _ => None, } diff --git a/crates/relayer/src/chain/counterparty.rs b/crates/relayer/src/chain/counterparty.rs index 323a5477af..3448f2fd84 100644 --- a/crates/relayer/src/chain/counterparty.rs +++ b/crates/relayer/src/chain/counterparty.rs @@ -295,7 +295,7 @@ pub fn channel_on_destination( channel_id: remote_channel_id.clone(), height: QueryHeight::Latest, }, - IncludeProof::No, + IncludeProof::Yes, ) .map(|(c, _)| IdentifiedChannelEnd { port_id: channel.channel_end.counterparty().port_id().clone(), diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index d437c421f8..cb2551f904 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -15,7 +15,7 @@ use serde::Serialize; use tracing::{debug, error, info, warn}; use ibc_relayer_types::core::ics04_channel::channel::{ - ChannelEnd, Counterparty, IdentifiedChannelEnd, Ordering, State, + ChannelEnd, Counterparty, IdentifiedChannelEnd, Ordering, State, UpgradeState, }; use ibc_relayer_types::core::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm; use ibc_relayer_types::core::ics04_channel::msgs::chan_close_init::MsgChannelCloseInit; @@ -309,7 +309,7 @@ impl Channel { channel_id: channel.src_channel_id.clone(), height: QueryHeight::Specific(height), }, - IncludeProof::No, + IncludeProof::Yes, ) .map_err(ChannelError::relayer)?; @@ -675,7 +675,7 @@ impl Channel { } // send the Confirm message to chain B (destination) - (State::Open, State::TryOpen) => { + (State::Open(UpgradeState::NotUpgrading), State::TryOpen) => { self.build_chan_open_confirm_and_send().map_err(|e| { error!("failed ChanOpenConfirm {}: {}", self.b_side, e); e @@ -683,7 +683,7 @@ impl Channel { } // send the Confirm message to chain A (source) - (State::TryOpen, State::Open) => { + (State::TryOpen, State::Open(UpgradeState::NotUpgrading)) => { self.flipped() .build_chan_open_confirm_and_send() .map_err(|e| { @@ -692,7 +692,7 @@ impl Channel { })?; } - (State::Open, State::Open) => { + (State::Open(UpgradeState::NotUpgrading), State::Open(UpgradeState::NotUpgrading)) => { info!("channel handshake already finished for {}", self); return Ok(()); } @@ -774,52 +774,43 @@ impl Channel { (State::Init, State::Init) => Some(self.build_chan_open_try_and_send()?), (State::TryOpen, State::Init) => Some(self.build_chan_open_ack_and_send()?), (State::TryOpen, State::TryOpen) => Some(self.build_chan_open_ack_and_send()?), - (State::Open, State::TryOpen) => Some(self.build_chan_open_confirm_and_send()?), - (State::Open, State::Open) => return Ok((None, Next::Abort)), + (State::Open(UpgradeState::NotUpgrading), State::TryOpen) => { + Some(self.build_chan_open_confirm_and_send()?) + } + (State::Open(UpgradeState::NotUpgrading), State::Open(_)) => { + return Ok((None, Next::Abort)) + } // If the counterparty state is already Open but current state is TryOpen, // return anyway as the final step is to be done by the counterparty worker. - (State::TryOpen, State::Open) => return Ok((None, Next::Abort)), + (State::TryOpen, State::Open(_)) => return Ok((None, Next::Abort)), // Close handshake steps (State::Closed, State::Closed) => return Ok((None, Next::Abort)), (State::Closed, _) => Some(self.build_chan_close_confirm_and_send()?), - (State::InitUpgrade, State::Open) => { - tracing::info!("handshake_step from InitUpgrade state"); - Some(self.build_chan_upgrade_try_and_send()?) - } - - (State::InitUpgrade, State::InitUpgrade) => { - tracing::info!("handshake_step from InitUpgrade state 2"); + // Channel Upgrade handshake steps + (State::Open(UpgradeState::Upgrading), State::Open(_)) => { Some(self.build_chan_upgrade_try_and_send()?) } - - (State::TryUpgrade, State::InitUpgrade) => { - tracing::info!("handshake_step from TryUpgrade state"); - Some(self.build_chan_upgrade_ack_and_send()?) + (State::Flushing, State::Open(_)) => Some(self.build_chan_upgrade_ack_and_send()?), + (State::Flushcomplete, State::Flushing) => { + Some(self.build_chan_upgrade_confirm_and_send()?) } - - (State::Open, State::TryUpgrade) => { - tracing::info!("handshake_step from OpenUpgrade state"); + (State::Open(UpgradeState::Upgrading), State::Flushcomplete) => { Some(self.build_chan_upgrade_open_and_send()?) } _ => None, }; - tracing::info!( - "Resulting event from build_chan_upgrade_try_and_send: {:#?}", - event - ); - // Abort if the channel is at OpenAck, OpenConfirm or CloseConfirm stage, as there is // nothing more for the worker to do match event { Some(IbcEvent::OpenConfirmChannel(_)) | Some(IbcEvent::OpenAckChannel(_)) | Some(IbcEvent::CloseConfirmChannel(_)) - | Some(IbcEvent::UpgradeAckChannel(_)) + | Some(IbcEvent::UpgradeConfirmChannel(_)) | Some(IbcEvent::UpgradeOpenChannel(_)) => Ok((event, Next::Abort)), _ => Ok((event, Next::Continue)), } @@ -851,13 +842,14 @@ impl Channel { let state = match event { IbcEvent::OpenInitChannel(_) => State::Init, IbcEvent::OpenTryChannel(_) => State::TryOpen, - IbcEvent::OpenAckChannel(_) => State::Open, - IbcEvent::OpenConfirmChannel(_) => State::Open, + IbcEvent::OpenAckChannel(_) => State::Open(UpgradeState::NotUpgrading), + IbcEvent::OpenConfirmChannel(_) => State::Open(UpgradeState::NotUpgrading), IbcEvent::CloseInitChannel(_) => State::Closed, - IbcEvent::UpgradeInitChannel(_) => State::InitUpgrade, - IbcEvent::UpgradeTryChannel(_) => State::TryUpgrade, - IbcEvent::UpgradeAckChannel(_) => State::AckUpgrade, - IbcEvent::UpgradeOpenChannel(_) => State::Open, + IbcEvent::UpgradeInitChannel(_) => State::Open(UpgradeState::Upgrading), + IbcEvent::UpgradeTryChannel(_) => State::Flushing, + IbcEvent::UpgradeAckChannel(_) => State::Flushcomplete, + IbcEvent::UpgradeConfirmChannel(_) => State::Flushcomplete, + IbcEvent::UpgradeOpenChannel(_) => State::Open(UpgradeState::Upgrading), _ => State::Uninitialized, }; @@ -979,7 +971,7 @@ impl Channel { let highest_state = match msg_type { ChannelMsgType::OpenAck => State::TryOpen, ChannelMsgType::OpenConfirm => State::TryOpen, - ChannelMsgType::CloseConfirm => State::Open, + ChannelMsgType::CloseConfirm => State::Open(UpgradeState::NotUpgrading), _ => State::Uninitialized, }; @@ -1546,9 +1538,9 @@ impl Channel { ) .map_err(|e| ChannelError::query(self.dst_chain().id(), e))?; - if channel_end.state != State::Open { + if channel_end.state != State::Open(UpgradeState::NotUpgrading) { return Err(ChannelError::invalid_channel_upgrade_state( - State::Open.to_string(), + State::Open(UpgradeState::NotUpgrading).to_string(), channel_end.state.to_string(), )); } @@ -1725,9 +1717,9 @@ impl Channel { )); } - if channel_end.state != State::Open { + if channel_end.state != State::Open(UpgradeState::NotUpgrading) { return Err(ChannelError::invalid_channel_upgrade_state( - State::Open.to_string(), + State::Open(UpgradeState::NotUpgrading).to_string(), channel_end.state.to_string(), )); } @@ -2146,7 +2138,8 @@ fn check_destination_channel_state( existing_channel.connection_hops() == expected_channel.connection_hops(); // TODO: Refactor into a method - let good_state = *existing_channel.state() as u32 <= *expected_channel.state() as u32; + let good_state = + existing_channel.state().into_i32() as u32 <= expected_channel.state().into_i32() as u32; let good_channel_port_ids = existing_channel.counterparty().channel_id().is_none() || existing_channel.counterparty().channel_id() == expected_channel.counterparty().channel_id() diff --git a/crates/relayer/src/event/source/websocket/extract.rs b/crates/relayer/src/event/source/websocket/extract.rs index e6ad07e9d9..be371c30c5 100644 --- a/crates/relayer/src/event/source/websocket/extract.rs +++ b/crates/relayer/src/event/source/websocket/extract.rs @@ -243,6 +243,7 @@ fn event_is_type_channel(ev: &IbcEvent) -> bool { | IbcEvent::UpgradeInitChannel(_) | IbcEvent::UpgradeTryChannel(_) | IbcEvent::UpgradeAckChannel(_) + | IbcEvent::UpgradeConfirmChannel(_) | IbcEvent::UpgradeOpenChannel(_) | IbcEvent::SendPacket(_) | IbcEvent::ReceivePacket(_) diff --git a/crates/relayer/src/link.rs b/crates/relayer/src/link.rs index 5e9716aee4..1ed7dc7df3 100644 --- a/crates/relayer/src/link.rs +++ b/crates/relayer/src/link.rs @@ -1,6 +1,6 @@ use ibc_relayer_types::core::{ ics03_connection::connection::State as ConnectionState, - ics04_channel::channel::State as ChannelState, + ics04_channel::channel::{State as ChannelState, UpgradeState}, ics24_host::identifier::{ChannelId, PortChannelId, PortId}, }; use tracing::info; @@ -77,7 +77,7 @@ impl Link { ) })?; - if !a_channel.state_matches(&ChannelState::Open) + if !a_channel.state_matches(&ChannelState::Open(UpgradeState::NotUpgrading)) && !a_channel.state_matches(&ChannelState::Closed) { return Err(LinkError::invalid_channel_state( diff --git a/crates/relayer/src/worker/channel.rs b/crates/relayer/src/worker/channel.rs index 42102efb60..15f485d2f7 100644 --- a/crates/relayer/src/worker/channel.rs +++ b/crates/relayer/src/worker/channel.rs @@ -55,6 +55,7 @@ pub fn spawn_channel_worker( IbcEventType::UpgradeInitChannel | IbcEventType::UpgradeTryChannel | IbcEventType::UpgradeAckChannel + | IbcEventType::UpgradeConfirmChannel | IbcEventType::UpgradeOpenChannel => retry_with_index( channel_handshake_retry::default_strategy(max_block_times), |index| match RelayChannel::restore_from_state( diff --git a/tools/test-framework/src/relayer/channel.rs b/tools/test-framework/src/relayer/channel.rs index 42ed7f9670..dcaa45c70c 100644 --- a/tools/test-framework/src/relayer/channel.rs +++ b/tools/test-framework/src/relayer/channel.rs @@ -4,7 +4,7 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest, QueryHeight}; use ibc_relayer::channel::{extract_channel_id, Channel, ChannelSide}; use ibc_relayer_types::core::ics04_channel::channel::{ - ChannelEnd, IdentifiedChannelEnd, Ordering, State as ChannelState, + ChannelEnd, IdentifiedChannelEnd, Ordering, State as ChannelState, UpgradeState, }; use ibc_relayer_types::core::ics04_channel::flush_status::FlushStatus; use ibc_relayer_types::core::ics04_channel::version::Version; @@ -240,7 +240,10 @@ pub fn assert_eventually_channel_established Date: Mon, 28 Aug 2023 13:23:04 +0200 Subject: [PATCH 11/26] Add channel upgrade handshake test --- .../src/tests/channel_upgrade/mod.rs | 1 + .../channel_upgrade/upgrade_handshake.rs | 108 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs diff --git a/tools/integration-test/src/tests/channel_upgrade/mod.rs b/tools/integration-test/src/tests/channel_upgrade/mod.rs index f5fee49272..d17762f554 100644 --- a/tools/integration-test/src/tests/channel_upgrade/mod.rs +++ b/tools/integration-test/src/tests/channel_upgrade/mod.rs @@ -1 +1,2 @@ pub mod manual_channel_upgrade; +pub mod upgrade_handshake; diff --git a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs new file mode 100644 index 0000000000..279af6c56f --- /dev/null +++ b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs @@ -0,0 +1,108 @@ +//! Tests the successful channel upgrade handshake: +//! +//! - `ChannelUpgradeManualHandshake` tests that after the channel can be upgraded +//! without relaying on the supervisor. This test manually calls the INIT, TRY, +//! ACK and CONFIRM steps. + +use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest, QueryHeight}; +use ibc_relayer_types::core::ics04_channel::version::Version; +use ibc_test_framework::prelude::*; +use ibc_test_framework::relayer::channel::{ + assert_eventually_channel_established, assert_eventually_channel_upgrade_open, + ChannelUpgradableAttributes, +}; + +#[test] +fn test_channel_upgrade_handshake() -> Result<(), Error> { + run_binary_channel_test(&ChannelUpgradeHandshake) +} + +pub struct ChannelUpgradeHandshake; + +impl TestOverrides for ChannelUpgradeHandshake { + fn modify_relayer_config(&self, config: &mut Config) { + config.mode.channels.enabled = true; + } +} + +impl BinaryChannelTest for ChannelUpgradeHandshake { + fn run( + &self, + _config: &TestConfig, + _relayer: RelayerDriver, + chains: ConnectedChains, + channels: ConnectedChannel, + ) -> Result<(), Error> { + info!("Check that channels are both in OPEN State"); + + assert_eventually_channel_established( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + )?; + + let channel_end_a = chains + .handle_a + .query_channel( + QueryChannelRequest { + port_id: channels.port_a.0.clone(), + channel_id: channels.channel_id_a.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd A: {e}"))?; + + let channel_end_b = chains + .handle_b + .query_channel( + QueryChannelRequest { + port_id: channels.port_b.0.clone(), + channel_id: channels.channel_id_b.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd B: {e}"))?; + + let old_ordering = channel_end_a.ordering; + let old_connection_hops_a = channel_end_a.connection_hops; + let old_connection_hops_b = channel_end_b.connection_hops; + + let channel = channels.channel; + let new_version = Version::ics20_with_fee(); + let new_ordering = None; + let new_connection_hops = None; + + let upgraded_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), + new_version.clone(), + old_ordering, + old_connection_hops_a, + old_connection_hops_b, + ); + + info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); + + channel.flipped().build_chan_upgrade_init_and_send( + Some(new_version), + new_ordering, + new_connection_hops, + )?; + + info!("Check that the channel upgrade successfully upgraded the version..."); + + assert_eventually_channel_upgrade_open( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &upgraded_attrs, + )?; + + Ok(()) + } +} From f1251427f4857b611cd40d89f4f9fc0a54a2e9e8 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 28 Aug 2023 13:28:26 +0200 Subject: [PATCH 12/26] Removed unnecessary logs --- crates/relayer/src/chain/counterparty.rs | 2 -- crates/relayer/src/channel.rs | 7 ------- crates/relayer/src/event/source/rpc.rs | 2 -- crates/relayer/src/event/source/websocket/extract.rs | 5 ----- crates/relayer/src/supervisor.rs | 4 ---- crates/relayer/src/worker/channel.rs | 3 +-- 6 files changed, 1 insertion(+), 22 deletions(-) diff --git a/crates/relayer/src/chain/counterparty.rs b/crates/relayer/src/chain/counterparty.rs index 3448f2fd84..977416aeaa 100644 --- a/crates/relayer/src/chain/counterparty.rs +++ b/crates/relayer/src/chain/counterparty.rs @@ -304,8 +304,6 @@ pub fn channel_on_destination( }) .map_err(Error::relayer)?; - tracing::info!("counterparty on channel_on_destination: {counterparty:#?}"); - Ok(Some(counterparty)) } else if let Some(remote_connection_id) = connection.end().counterparty().connection_id() { fetch_channel_on_destination( diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index cb2551f904..c0999ed9e2 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -313,8 +313,6 @@ impl Channel { ) .map_err(ChannelError::relayer)?; - tracing::info!("Channel A from restore_from_state: {a_channel:#?}"); - let a_connection_id = a_channel.connection_hops().first().ok_or_else(|| { ChannelError::supervisor(SupervisorError::missing_connection_hops( channel.src_channel_id.clone(), @@ -763,11 +761,6 @@ impl Channel { &mut self, state: State, ) -> Result<(Option, Next), ChannelError> { - tracing::info!( - "state: {}, counterparty state: {}", - state, - self.counterparty_state()? - ); let event = match (state, self.counterparty_state()?) { // Open handshake steps (State::Init, State::Uninitialized) => Some(self.build_chan_open_try_and_send()?), diff --git a/crates/relayer/src/event/source/rpc.rs b/crates/relayer/src/event/source/rpc.rs index 4fa475cac4..b684cc6590 100644 --- a/crates/relayer/src/event/source/rpc.rs +++ b/crates/relayer/src/event/source/rpc.rs @@ -220,8 +220,6 @@ impl EventSource { } } - debug!("fetched batch: {batches:#?}"); - Ok(batches) } diff --git a/crates/relayer/src/event/source/websocket/extract.rs b/crates/relayer/src/event/source/websocket/extract.rs index be371c30c5..9530cd8122 100644 --- a/crates/relayer/src/event/source/websocket/extract.rs +++ b/crates/relayer/src/event/source/websocket/extract.rs @@ -127,7 +127,6 @@ pub fn extract_events( query, } = result; let events = events.ok_or("missing events")?; - tracing::debug!("query: {query}"); match data { RpcEventData::NewBlock { block, .. } | RpcEventData::LegacyNewBlock { block, .. } @@ -153,7 +152,6 @@ pub fn extract_events( .map_err(|_| String::from("tx_result.height: invalid header height of 0"))?; for abci_event in &tx_result.result.events { - tracing::debug!("abci event: {abci_event:#?}"); if let Ok(ibc_event) = ibc_event_try_from_abci_event(abci_event) { if query == queries::ibc_client().to_string() && event_is_type_client(&ibc_event) @@ -205,9 +203,6 @@ pub fn extract_events( _ => {} } - tracing::debug!("Events:"); - tracing::debug!("{events_with_height:#?}"); - Ok(events_with_height) } diff --git a/crates/relayer/src/supervisor.rs b/crates/relayer/src/supervisor.rs index d0ab46aac2..fea736e4e3 100644 --- a/crates/relayer/src/supervisor.rs +++ b/crates/relayer/src/supervisor.rs @@ -783,12 +783,8 @@ fn process_batch( telemetry!(received_event_batch, batch.tracking_id); - tracing::debug!("Events to collect: {batch:#?}"); - let collected = collect_events(config, workers, &src_chain, batch); - tracing::debug!("collected events to collect: {collected:#?}"); - // If there is a NewBlock event, forward this event first to any workers affected by it. if let Some(IbcEvent::NewBlock(new_block)) = collected.new_block { workers.notify_new_block(&src_chain.id(), batch.height, new_block); diff --git a/crates/relayer/src/worker/channel.rs b/crates/relayer/src/worker/channel.rs index 15f485d2f7..84a84e233b 100644 --- a/crates/relayer/src/worker/channel.rs +++ b/crates/relayer/src/worker/channel.rs @@ -45,9 +45,8 @@ pub fn spawn_channel_worker( WorkerCmd::IbcEvents { batch } => { // there can be up to two event for this channel, e.g. init and try. // process the last event, the one with highest "rank". - tracing::info!("batch events: {:#?}", batch.events); let last_event = batch.events.last(); - tracing::info!("starts processing {:?}", last_event); + debug!("starts processing {:?}", last_event); complete_handshake_on_new_block = false; if let Some(event_with_height) = last_event { From ed0f5d45db9514f96e416904c94e956c1983f544 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 28 Aug 2023 13:30:46 +0200 Subject: [PATCH 13/26] Update channel upgrade test doc --- .../src/tests/channel_upgrade/manual_channel_upgrade.rs | 7 +++---- .../src/tests/channel_upgrade/upgrade_handshake.rs | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs index db7d60c4f0..2090516e4b 100644 --- a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs +++ b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs @@ -1,8 +1,7 @@ -//! Tests the successful channel upgrade handshake: +//! Tests the successful channel upgrade: //! -//! - `ChannelUpgradeManualHandshake` tests that after the channel can be upgraded -//! without relaying on the supervisor. This test manually calls the INIT, TRY, -//! ACK and CONFIRM steps. +//! - `ChannelUpgradeManualHandshake` tests each step of the channel upgrade manually, +//! without relaying on the supervisor. use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest, QueryHeight}; use ibc_relayer_types::core::ics04_channel::version::Version; diff --git a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs index 279af6c56f..2c79e80ba0 100644 --- a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs +++ b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs @@ -1,8 +1,8 @@ -//! Tests the successful channel upgrade handshake: +//! Tests the successful channel upgrade: //! -//! - `ChannelUpgradeManualHandshake` tests that after the channel can be upgraded -//! without relaying on the supervisor. This test manually calls the INIT, TRY, -//! ACK and CONFIRM steps. +//! - `ChannelUpgradeHandshake` tests that after the upgrade handshake is completed +//! after initialising the upgrade with `build_chan_upgrade_init_and_send` without +//! any in-flight packets. use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest, QueryHeight}; use ibc_relayer_types::core::ics04_channel::version::Version; From 29ab35ae27a3c8b6da3e2838a9c47c2c2c49b057 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 28 Aug 2023 14:48:02 +0200 Subject: [PATCH 14/26] Add test to transfer ics29 packet after channel upgrade --- .../src/tests/channel_upgrade/ics29.rs | 218 ++++++++++++++++++ .../channel_upgrade/manual_channel_upgrade.rs | 5 +- .../src/tests/channel_upgrade/mod.rs | 1 + .../channel_upgrade/upgrade_handshake.rs | 5 +- 4 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 tools/integration-test/src/tests/channel_upgrade/ics29.rs diff --git a/tools/integration-test/src/tests/channel_upgrade/ics29.rs b/tools/integration-test/src/tests/channel_upgrade/ics29.rs new file mode 100644 index 0000000000..660d287073 --- /dev/null +++ b/tools/integration-test/src/tests/channel_upgrade/ics29.rs @@ -0,0 +1,218 @@ +//! Tests channel upgrade fetures: +//! +//! - `ChannelUpgradeICS29` tests that only after the upgrade handshake is completed +//! and the channel version has been updated to ICS29 can Incentivized packets be +//! relayed. + +use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest, QueryHeight}; +use ibc_relayer_types::core::ics04_channel::version::Version; +use ibc_test_framework::prelude::*; +use ibc_test_framework::relayer::channel::{ + assert_eventually_channel_established, assert_eventually_channel_upgrade_open, + ChannelUpgradableAttributes, +}; +use ibc_test_framework::util::random::random_u128_range; + +#[test] +fn test_channel_upgrade_ics29() -> Result<(), Error> { + run_binary_channel_test(&ChannelUpgradeICS29) +} + +pub struct ChannelUpgradeICS29; + +impl TestOverrides for ChannelUpgradeICS29 { + fn modify_relayer_config(&self, config: &mut Config) { + config.mode.channels.enabled = true; + config.mode.packets.auto_register_counterparty_payee = true; + config.mode.packets.clear_interval = 0; + config.mode.packets.clear_on_start = false; + + config.mode.clients.misbehaviour = false; + } +} + +impl BinaryChannelTest for ChannelUpgradeICS29 { + fn run( + &self, + _config: &TestConfig, + _relayer: RelayerDriver, + chains: ConnectedChains, + channels: ConnectedChannel, + ) -> Result<(), Error> { + info!("Check that channels are both in OPEN State"); + + assert_eventually_channel_established( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + )?; + + let channel_end_a = chains + .handle_a + .query_channel( + QueryChannelRequest { + port_id: channels.port_a.0.clone(), + channel_id: channels.channel_id_a.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd A: {e}"))?; + + let channel_end_b = chains + .handle_b + .query_channel( + QueryChannelRequest { + port_id: channels.port_b.0.clone(), + channel_id: channels.channel_id_b.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd B: {e}"))?; + + let chain_driver_a = chains.node_a.chain_driver(); + let chain_driver_b = chains.node_b.chain_driver(); + + let denom_a = chains.node_a.denom(); + + let port_a = channels.port_a.as_ref(); + let channel_id_a = channels.channel_id_a.as_ref(); + + let wallets_a = chains.node_a.wallets(); + let wallets_b = chains.node_b.wallets(); + + let relayer_a = wallets_a.relayer(); + + let user_a = wallets_a.user1(); + let user_b = wallets_b.user1(); + + let balance_a1 = chain_driver_a.query_balance(&user_a.address(), &denom_a)?; + + let relayer_balance_a = chain_driver_a.query_balance(&relayer_a.address(), &denom_a)?; + + let send_amount = random_u128_range(1000, 2000); + let receive_fee = random_u128_range(300, 400); + let ack_fee = random_u128_range(200, 300); + let timeout_fee = random_u128_range(100, 200); + + let total_sent = send_amount + receive_fee + ack_fee + timeout_fee; + + let balance_a2 = balance_a1 - total_sent; + + let ics29_transfer = chain_driver_a.ibc_token_transfer_with_fee( + &port_a, + &channel_id_a, + &user_a, + &user_b.address(), + &denom_a.with_amount(send_amount).as_ref(), + &denom_a.with_amount(receive_fee).as_ref(), + &denom_a.with_amount(ack_fee).as_ref(), + &denom_a.with_amount(timeout_fee).as_ref(), + Duration::from_secs(60), + ); + + assert!(ics29_transfer.is_err(), "{ics29_transfer:?}"); + + let old_ordering = channel_end_a.ordering; + let old_connection_hops_a = channel_end_a.connection_hops; + let old_connection_hops_b = channel_end_b.connection_hops; + + let channel = channels.channel; + let new_version = Version::ics20_with_fee(); + let new_ordering = None; + let new_connection_hops = None; + + let upgraded_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), + new_version.clone(), + old_ordering, + old_connection_hops_a, + old_connection_hops_b, + ); + + info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); + + // Note: Initialising a channel upgrade this way will eventually be removed. + // Only authority (gov module or other) will be able to trigger a channel upgrade. + // See: https://github.com/cosmos/ibc-go/issues/4186 + channel.flipped().build_chan_upgrade_init_and_send( + Some(new_version), + new_ordering, + new_connection_hops, + )?; + + info!("Check that the channel upgrade successfully upgraded the version..."); + + assert_eventually_channel_upgrade_open( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &upgraded_attrs, + )?; + + // Since the channel has been updated to ICS29 version after the Hermes instance + // was started, the `auto_register_counterparty_payee` has not registered the + // counterparty payee. It is required to register it manually. + chain_driver_b.register_counterparty_payee( + &wallets_b.relayer(), + &relayer_a.address(), + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + )?; + + { + let counterparty_payee = chain_driver_b.query_counterparty_payee( + &channels.channel_id_b.as_ref(), + &wallets_b.relayer().address(), + )?; + + assert_eq( + "counterparty address should match registered address", + &counterparty_payee, + &Some(relayer_a.address().cloned()), + )?; + } + + chain_driver_a.ibc_token_transfer_with_fee( + &port_a, + &channel_id_a, + &user_a, + &user_b.address(), + &denom_a.with_amount(send_amount).as_ref(), + &denom_a.with_amount(receive_fee).as_ref(), + &denom_a.with_amount(ack_fee).as_ref(), + &denom_a.with_amount(timeout_fee).as_ref(), + Duration::from_secs(60), + )?; + + let denom_b = derive_ibc_denom( + &channels.port_b.as_ref(), + &channels.channel_id_b.as_ref(), + &denom_a, + )?; + + chain_driver_a.assert_eventual_wallet_amount(&user_a.address(), &balance_a2.as_ref())?; + + chain_driver_b.assert_eventual_wallet_amount( + &user_b.address(), + &denom_b.with_amount(send_amount).as_ref(), + )?; + + chain_driver_a.assert_eventual_wallet_amount( + &user_a.address(), + &(balance_a2 + timeout_fee).as_ref(), + )?; + + chain_driver_a.assert_eventual_wallet_amount( + &relayer_a.address(), + &(relayer_balance_a + ack_fee + receive_fee).as_ref(), + )?; + + Ok(()) + } +} diff --git a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs index 2090516e4b..0ee37eb4c3 100644 --- a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs +++ b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs @@ -1,4 +1,4 @@ -//! Tests the successful channel upgrade: +//! Tests channel upgrade: //! //! - `ChannelUpgradeManualHandshake` tests each step of the channel upgrade manually, //! without relaying on the supervisor. @@ -105,6 +105,9 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { info!("Will run ChanUpgradeInit step..."); + // Note: Initialising a channel upgrade this way will eventually be removed. + // Only authority (gov module or other) will be able to trigger a channel upgrade. + // See: https://github.com/cosmos/ibc-go/issues/4186 channel.flipped().build_chan_upgrade_init_and_send( Some(new_version), new_ordering, diff --git a/tools/integration-test/src/tests/channel_upgrade/mod.rs b/tools/integration-test/src/tests/channel_upgrade/mod.rs index d17762f554..f6e864ab78 100644 --- a/tools/integration-test/src/tests/channel_upgrade/mod.rs +++ b/tools/integration-test/src/tests/channel_upgrade/mod.rs @@ -1,2 +1,3 @@ +pub mod ics29; pub mod manual_channel_upgrade; pub mod upgrade_handshake; diff --git a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs index 2c79e80ba0..d16e00183b 100644 --- a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs +++ b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs @@ -1,4 +1,4 @@ -//! Tests the successful channel upgrade: +//! Tests channel upgrade: //! //! - `ChannelUpgradeHandshake` tests that after the upgrade handshake is completed //! after initialising the upgrade with `build_chan_upgrade_init_and_send` without @@ -87,6 +87,9 @@ impl BinaryChannelTest for ChannelUpgradeHandshake { info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); + // Note: Initialising a channel upgrade this way will eventually be removed. + // Only authority (gov module or other) will be able to trigger a channel upgrade. + // See: https://github.com/cosmos/ibc-go/issues/4186 channel.flipped().build_chan_upgrade_init_and_send( Some(new_version), new_ordering, From c5fa9ee6ffaa9a5e6070b58698b0ba2c025b93f0 Mon Sep 17 00:00:00 2001 From: Luca Joss <43531661+ljoss17@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:27:26 +0200 Subject: [PATCH 15/26] Update tools/integration-test/src/tests/channel_upgrade/ics29.rs Co-authored-by: Sean Chen Signed-off-by: Luca Joss <43531661+ljoss17@users.noreply.github.com> --- tools/integration-test/src/tests/channel_upgrade/ics29.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/integration-test/src/tests/channel_upgrade/ics29.rs b/tools/integration-test/src/tests/channel_upgrade/ics29.rs index 660d287073..1104c22dc3 100644 --- a/tools/integration-test/src/tests/channel_upgrade/ics29.rs +++ b/tools/integration-test/src/tests/channel_upgrade/ics29.rs @@ -136,7 +136,9 @@ impl BinaryChannelTest for ChannelUpgradeICS29 { info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); - // Note: Initialising a channel upgrade this way will eventually be removed. + // Note: Initialising a channel upgrade this way, without requiring a + // signature or proof of authority to perform the channel upgrade, will + // eventually be removed. // Only authority (gov module or other) will be able to trigger a channel upgrade. // See: https://github.com/cosmos/ibc-go/issues/4186 channel.flipped().build_chan_upgrade_init_and_send( From f2f6c732e046b8335c07b0071488b46f96ba123b Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Tue, 29 Aug 2023 16:31:32 +0200 Subject: [PATCH 16/26] Add comments --- crates/relayer/src/chain/counterparty.rs | 4 ++++ crates/relayer/src/channel.rs | 4 ++++ tools/integration-test/src/tests/channel_upgrade/ics29.rs | 2 +- .../src/tests/channel_upgrade/manual_channel_upgrade.rs | 4 +++- .../src/tests/channel_upgrade/upgrade_handshake.rs | 4 +++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/relayer/src/chain/counterparty.rs b/crates/relayer/src/chain/counterparty.rs index 977416aeaa..f1fcc7cd14 100644 --- a/crates/relayer/src/chain/counterparty.rs +++ b/crates/relayer/src/chain/counterparty.rs @@ -295,6 +295,10 @@ pub fn channel_on_destination( channel_id: remote_channel_id.clone(), height: QueryHeight::Latest, }, + // IncludeProof::Yes forces a new query when the CachingChainHandle + // is used. + // TODO: Pass the BaseChainHandle instead of the CachingChainHandle + // to the channel worker to avoid querying for a Proof . IncludeProof::Yes, ) .map(|(c, _)| IdentifiedChannelEnd { diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index c0999ed9e2..5f993b84c8 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -309,6 +309,10 @@ impl Channel { channel_id: channel.src_channel_id.clone(), height: QueryHeight::Specific(height), }, + // IncludeProof::Yes forces a new query when the CachingChainHandle + // is used. + // TODO: Pass the BaseChainHandle instead of the CachingChainHandle + // to the channel worker to avoid querying for a Proof . IncludeProof::Yes, ) .map_err(ChannelError::relayer)?; diff --git a/tools/integration-test/src/tests/channel_upgrade/ics29.rs b/tools/integration-test/src/tests/channel_upgrade/ics29.rs index 1104c22dc3..cdcae198fa 100644 --- a/tools/integration-test/src/tests/channel_upgrade/ics29.rs +++ b/tools/integration-test/src/tests/channel_upgrade/ics29.rs @@ -136,7 +136,7 @@ impl BinaryChannelTest for ChannelUpgradeICS29 { info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); - // Note: Initialising a channel upgrade this way, without requiring a + // Note: Initialising a channel upgrade this way, without requiring a // signature or proof of authority to perform the channel upgrade, will // eventually be removed. // Only authority (gov module or other) will be able to trigger a channel upgrade. diff --git a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs index 0ee37eb4c3..31ce58b267 100644 --- a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs +++ b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs @@ -105,7 +105,9 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { info!("Will run ChanUpgradeInit step..."); - // Note: Initialising a channel upgrade this way will eventually be removed. + // Note: Initialising a channel upgrade this way, without requiring a + // signature or proof of authority to perform the channel upgrade, will + // eventually be removed. // Only authority (gov module or other) will be able to trigger a channel upgrade. // See: https://github.com/cosmos/ibc-go/issues/4186 channel.flipped().build_chan_upgrade_init_and_send( diff --git a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs index d16e00183b..8d0f5ec644 100644 --- a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs +++ b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs @@ -87,7 +87,9 @@ impl BinaryChannelTest for ChannelUpgradeHandshake { info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); - // Note: Initialising a channel upgrade this way will eventually be removed. + // Note: Initialising a channel upgrade this way, without requiring a + // signature or proof of authority to perform the channel upgrade, will + // eventually be removed. // Only authority (gov module or other) will be able to trigger a channel upgrade. // See: https://github.com/cosmos/ibc-go/issues/4186 channel.flipped().build_chan_upgrade_init_and_send( From 9ca22615b1aec1562587709cc1ed2cf8bfb93714 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Mon, 9 Oct 2023 11:18:28 +0200 Subject: [PATCH 17/26] Fix 'query bank balances' CLI to handle SDK v0.50 changes --- tools/test-framework/src/chain/cli/query.rs | 70 +++++++++++++++++---- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/tools/test-framework/src/chain/cli/query.rs b/tools/test-framework/src/chain/cli/query.rs index 8029d23929..9bf90f81bf 100644 --- a/tools/test-framework/src/chain/cli/query.rs +++ b/tools/test-framework/src/chain/cli/query.rs @@ -14,7 +14,9 @@ pub fn query_balance( wallet_id: &str, denom: &str, ) -> Result { - let res = simple_exec( + // SDK v0.50 has removed the `--denom` flag from the `query bank balances` CLI. + // It also changed the JSON output. + match simple_exec( chain_id, command_path, &[ @@ -29,20 +31,64 @@ pub fn query_balance( "--output", "json", ], - )? - .stdout; + ) { + Ok(output) => { + let amount_str = json::from_str::(&output.stdout) + .map_err(handle_generic_error)? + .get("amount") + .ok_or_else(|| eyre!("expected amount field"))? + .as_str() + .ok_or_else(|| eyre!("expected string field"))? + .to_string(); - let amount_str = json::from_str::(&res) - .map_err(handle_generic_error)? - .get("amount") - .ok_or_else(|| eyre!("expected amount field"))? - .as_str() - .ok_or_else(|| eyre!("expected string field"))? - .to_string(); + let amount = Amount::from_str(&amount_str).map_err(handle_generic_error)?; + + Ok(amount) + } + Err(_) => { + let res = simple_exec( + chain_id, + command_path, + &[ + "--node", + rpc_listen_address, + "query", + "bank", + "balances", + wallet_id, + "--output", + "json", + ], + )? + .stdout; + let amounts_array = + json::from_str::(&res).map_err(handle_generic_error)?; - let amount = Amount::from_str(&amount_str).map_err(handle_generic_error)?; + let balances = amounts_array + .get("balances") + .ok_or_else(|| eyre!("expected balances field"))? + .as_array() + .ok_or_else(|| eyre!("expected array field"))?; - Ok(amount) + let amount_str = balances + .iter() + .find(|a| { + a.get("denom") + .ok_or_else(|| eyre!("expected denom field")) + .unwrap() + == denom + }) + .ok_or_else(|| eyre!("no entry with denom `{denom}` found"))? + .get("amount") + .ok_or_else(|| eyre!("expected amount field"))? + .as_str() + .ok_or_else(|| eyre!("expected amount to be in string format"))?; + + let amount = Amount::from_str(amount_str).map_err(handle_generic_error)?; + + Ok(amount) + } + } } /** From f018a5f418d14521be168233f2f8f1823985067e Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Tue, 10 Oct 2023 16:49:52 +0200 Subject: [PATCH 18/26] Remove flush status from channel end --- Cargo.lock | 8 +- crates/relayer-cli/src/commands/tx/client.rs | 4 +- .../src/core/ics04_channel/channel.rs | 23 +----- .../src/core/ics04_channel/events.rs | 37 +++------- .../src/core/ics04_channel/flush_status.rs | 73 ------------------- .../src/core/ics04_channel/mod.rs | 1 - crates/relayer/src/channel.rs | 4 - crates/relayer/src/event.rs | 14 +--- tools/test-framework/src/relayer/channel.rs | 35 --------- 9 files changed, 19 insertions(+), 180 deletions(-) delete mode 100644 crates/relayer-types/src/core/ics04_channel/flush_status.rs diff --git a/Cargo.lock b/Cargo.lock index d9378af793..9b6e5ded21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1372,8 +1372,7 @@ dependencies = [ [[package]] name = "ibc-proto" version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725fd83c94e9859fd967cd706996679799171eba940740f071f0046fb6f6e031" +source = "git+https://github.com/cosmos/ibc-proto-rs.git?branch=romac/channel-upgrade-only#f2745837ae445d431e8e48e5fd0bef14b2cf4585" dependencies = [ "base64 0.21.4", "bytes", @@ -4185,8 +4184,3 @@ dependencies = [ "quote", "syn 2.0.38", ] - -[[patch.unused]] -name = "ibc-proto" -version = "0.33.0" -source = "git+https://github.com/cosmos/ibc-proto-rs.git?branch=romac/channel-upgrade-only#a3cad9102eeae2d356054b2a5c55298213f9405d" diff --git a/crates/relayer-cli/src/commands/tx/client.rs b/crates/relayer-cli/src/commands/tx/client.rs index 3cb2f51812..e528e0a4bc 100644 --- a/crates/relayer-cli/src/commands/tx/client.rs +++ b/crates/relayer-cli/src/commands/tx/client.rs @@ -435,9 +435,9 @@ impl Runnable for TxUpgradeClientsCmd { .chains .iter() .filter(|&chain| { - (self.reference_chain_id != chain.id + self.reference_chain_id != chain.id && (self.host_chain_id.is_none() - || self.host_chain_id == Some(chain.id.clone()))) + || self.host_chain_id == Some(chain.id.clone())) }) .map(|chain| { self.upgrade_clients_for_chain( diff --git a/crates/relayer-types/src/core/ics04_channel/channel.rs b/crates/relayer-types/src/core/ics04_channel/channel.rs index 18117ebb4f..982ccb0219 100644 --- a/crates/relayer-types/src/core/ics04_channel/channel.rs +++ b/crates/relayer-types/src/core/ics04_channel/channel.rs @@ -7,12 +7,12 @@ use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; use ibc_proto::ibc::core::channel::v1::{ - Channel as RawChannel, Counterparty as RawCounterparty, FlushStatus as RawFlushStatus, + Channel as RawChannel, Counterparty as RawCounterparty, IdentifiedChannel as RawIdentifiedChannel, }; use crate::core::ics04_channel::packet::Sequence; -use crate::core::ics04_channel::{error::Error, flush_status::FlushStatus, version::Version}; +use crate::core::ics04_channel::{error::Error, version::Version}; use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -45,7 +45,6 @@ impl TryFrom for IdentifiedChannelEnd { connection_hops: value.connection_hops, version: value.version, upgrade_sequence: 0, // FIXME: proto IdentifiedChannel does not have this field, should we default to 0 ? - flush_status: 0, }; Ok(IdentifiedChannelEnd { @@ -83,7 +82,6 @@ pub struct ChannelEnd { pub connection_hops: Vec, pub version: Version, pub upgraded_sequence: Sequence, - pub flush_status: FlushStatus, } impl Display for ChannelEnd { @@ -105,7 +103,6 @@ impl Default for ChannelEnd { connection_hops: Vec::new(), version: Version::default(), upgraded_sequence: Sequence::from(0), // The value of 0 indicates the channel has never been upgraded - flush_status: FlushStatus::NotinflushUnspecified, } } } @@ -140,8 +137,6 @@ impl TryFrom for ChannelEnd { let version = value.version.into(); - let flush_status = FlushStatus::try_from(value.flush_status)?; - Ok(ChannelEnd::new( chan_state, chan_ordering, @@ -149,7 +144,6 @@ impl TryFrom for ChannelEnd { connection_hops, version, Sequence::from(value.upgrade_sequence), - flush_status, )) } } @@ -167,7 +161,6 @@ impl From for RawChannel { .collect(), version: value.version.to_string(), upgrade_sequence: value.upgraded_sequence.into(), - flush_status: RawFlushStatus::from(value.flush_status).into(), } } } @@ -181,7 +174,6 @@ impl ChannelEnd { connection_hops: Vec, version: Version, upgraded_sequence: Sequence, - flush_status: FlushStatus, ) -> Self { Self { state, @@ -190,7 +182,6 @@ impl ChannelEnd { connection_hops, version, upgraded_sequence, - flush_status, } } @@ -218,10 +209,6 @@ impl ChannelEnd { &self.state } - pub fn flush_status(&self) -> &FlushStatus { - &self.flush_status - } - pub fn ordering(&self) -> &Ordering { &self.ordering } @@ -253,11 +240,6 @@ impl ChannelEnd { self.state() == other } - /// Helper function to compare the flush status of this end with another flush status. - pub fn flush_status_matches(&self, other: &FlushStatus) -> bool { - self.flush_status() == other - } - /// Helper function to compare the order of this end with another order. pub fn order_matches(&self, other: &Ordering) -> bool { self.ordering() == other @@ -568,7 +550,6 @@ pub mod test_util { connection_hops: vec![ConnectionId::default().to_string()], version: "ics20".to_string(), // The version is not validated. upgrade_sequence: 0, // The value of 0 indicates the channel has never been upgraded - flush_status: 0, } } } diff --git a/crates/relayer-types/src/core/ics04_channel/events.rs b/crates/relayer-types/src/core/ics04_channel/events.rs index ba69a619eb..0e466e17d2 100644 --- a/crates/relayer-types/src/core/ics04_channel/events.rs +++ b/crates/relayer-types/src/core/ics04_channel/events.rs @@ -7,7 +7,6 @@ use tendermint::abci; use crate::core::ics04_channel::channel::Ordering; use crate::core::ics04_channel::error::Error; -use crate::core::ics04_channel::flush_status::FlushStatus; use crate::core::ics04_channel::packet::Packet; use crate::core::ics04_channel::packet::Sequence; use crate::core::ics04_channel::version::Version; @@ -146,7 +145,6 @@ pub struct UpgradeAttributes { pub upgrade_version: Version, pub upgrade_sequence: Sequence, pub upgrade_ordering: Ordering, - pub channel_flush_status: FlushStatus, } impl UpgradeAttributes { @@ -580,7 +578,6 @@ pub struct UpgradeInit { pub upgrade_version: Version, pub upgrade_sequence: Sequence, pub upgrade_ordering: Ordering, - pub channel_flush_status: FlushStatus, } impl Display for UpgradeInit { @@ -595,8 +592,8 @@ impl Display for UpgradeInit { } write!( f, - "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {}, channel_flush_status: {} }}", - self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering, self.channel_flush_status + "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {} }}", + self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering ) } } @@ -612,7 +609,6 @@ impl From for UpgradeAttributes { upgrade_version: ev.upgrade_version, upgrade_sequence: ev.upgrade_sequence, upgrade_ordering: ev.upgrade_ordering, - channel_flush_status: ev.channel_flush_status, } } } @@ -658,7 +654,6 @@ impl TryFrom for UpgradeInit { upgrade_version: attrs.upgrade_version, upgrade_sequence: attrs.upgrade_sequence, upgrade_ordering: attrs.upgrade_ordering, - channel_flush_status: attrs.channel_flush_status, }) } } @@ -685,7 +680,6 @@ pub struct UpgradeTry { pub upgrade_version: Version, pub upgrade_sequence: Sequence, pub upgrade_ordering: Ordering, - pub channel_flush_status: FlushStatus, } impl Display for UpgradeTry { @@ -700,8 +694,8 @@ impl Display for UpgradeTry { } write!( f, - "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {}, channel_flush_status: {} }}", - self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering, self.channel_flush_status + "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {} }}", + self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering ) } } @@ -717,7 +711,6 @@ impl From for UpgradeAttributes { upgrade_version: ev.upgrade_version, upgrade_sequence: ev.upgrade_sequence, upgrade_ordering: ev.upgrade_ordering, - channel_flush_status: ev.channel_flush_status, } } } @@ -763,7 +756,6 @@ impl TryFrom for UpgradeTry { upgrade_version: attrs.upgrade_version, upgrade_sequence: attrs.upgrade_sequence, upgrade_ordering: attrs.upgrade_ordering, - channel_flush_status: attrs.channel_flush_status, }) } } @@ -790,7 +782,6 @@ pub struct UpgradeAck { pub upgrade_version: Version, pub upgrade_sequence: Sequence, pub upgrade_ordering: Ordering, - pub channel_flush_status: FlushStatus, } impl Display for UpgradeAck { @@ -805,8 +796,8 @@ impl Display for UpgradeAck { } write!( f, - "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {}, channel_flush_status: {} }}", - self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering, self.channel_flush_status + "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {} }}", + self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering ) } } @@ -822,7 +813,6 @@ impl From for UpgradeAttributes { upgrade_version: ev.upgrade_version, upgrade_sequence: ev.upgrade_sequence, upgrade_ordering: ev.upgrade_ordering, - channel_flush_status: ev.channel_flush_status, } } } @@ -868,7 +858,6 @@ impl TryFrom for UpgradeAck { upgrade_version: attrs.upgrade_version, upgrade_sequence: attrs.upgrade_sequence, upgrade_ordering: attrs.upgrade_ordering, - channel_flush_status: attrs.channel_flush_status, }) } } @@ -895,7 +884,6 @@ pub struct UpgradeConfirm { pub upgrade_version: Version, pub upgrade_sequence: Sequence, pub upgrade_ordering: Ordering, - pub channel_flush_status: FlushStatus, } impl Display for UpgradeConfirm { @@ -910,8 +898,8 @@ impl Display for UpgradeConfirm { } write!( f, - "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {}, channel_flush_status: {} }}", - self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering, self.channel_flush_status + "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {} }}", + self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering ) } } @@ -927,7 +915,6 @@ impl From for UpgradeAttributes { upgrade_version: ev.upgrade_version, upgrade_sequence: ev.upgrade_sequence, upgrade_ordering: ev.upgrade_ordering, - channel_flush_status: ev.channel_flush_status, } } } @@ -973,7 +960,6 @@ impl TryFrom for UpgradeConfirm { upgrade_version: attrs.upgrade_version, upgrade_sequence: attrs.upgrade_sequence, upgrade_ordering: attrs.upgrade_ordering, - channel_flush_status: attrs.channel_flush_status, }) } } @@ -1000,7 +986,6 @@ pub struct UpgradeOpen { pub upgrade_version: Version, pub upgrade_sequence: Sequence, pub upgrade_ordering: Ordering, - pub channel_flush_status: FlushStatus, } impl Display for UpgradeOpen { @@ -1015,8 +1000,8 @@ impl Display for UpgradeOpen { } write!( f, - "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {}, channel_flush_status: {} }}", - self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering, self.channel_flush_status + "], upgrade_version: {}, upgrade_sequence: {}, upgrade_ordering: {} }}", + self.upgrade_version, self.upgrade_sequence, self.upgrade_ordering ) } } @@ -1032,7 +1017,6 @@ impl From for UpgradeAttributes { upgrade_version: ev.upgrade_version, upgrade_sequence: ev.upgrade_sequence, upgrade_ordering: ev.upgrade_ordering, - channel_flush_status: ev.channel_flush_status, } } } @@ -1078,7 +1062,6 @@ impl TryFrom for UpgradeOpen { upgrade_version: attrs.upgrade_version, upgrade_sequence: attrs.upgrade_sequence, upgrade_ordering: attrs.upgrade_ordering, - channel_flush_status: attrs.channel_flush_status, }) } } diff --git a/crates/relayer-types/src/core/ics04_channel/flush_status.rs b/crates/relayer-types/src/core/ics04_channel/flush_status.rs deleted file mode 100644 index 80cfb172d3..0000000000 --- a/crates/relayer-types/src/core/ics04_channel/flush_status.rs +++ /dev/null @@ -1,73 +0,0 @@ -use std::fmt::Display; -use std::fmt::Error as FmtError; -use std::fmt::Formatter; -use std::str::FromStr; - -use serde::Deserialize; -use serde::Serialize; - -use ibc_proto::ibc::core::channel::v1::FlushStatus as RawFlushStatus; - -use crate::core::ics04_channel::error::Error; - -#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] -pub enum FlushStatus { - #[default] - NotinflushUnspecified = 0, - Flushing = 1, - Flushcomplete = 2, -} - -impl Display for FlushStatus { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - match self { - FlushStatus::NotinflushUnspecified => write!(f, "FLUSH_STATUS_NOTINFLUSH_UNSPECIFIED"), - FlushStatus::Flushing => write!(f, "FLUSH_STATUS_FLUSHING"), - FlushStatus::Flushcomplete => write!(f, "FLUSH_STATUS_FLUSHCOMPLETE"), - } - } -} - -impl FromStr for FlushStatus { - type Err = Error; - - fn from_str(s: &str) -> Result { - match s.to_lowercase().trim_start_matches("flush_status_") { - "notinflush_unspecified" => Ok(Self::NotinflushUnspecified), - "flushing" => Ok(Self::Flushing), - "flushcomplete" => Ok(Self::Flushcomplete), - _ => Err(Error::unknown_flush_status_type(s.to_string())), - } - } -} - -impl TryFrom for FlushStatus { - type Error = Error; - - fn try_from(value: RawFlushStatus) -> Result { - value.try_into() - } -} - -impl From for RawFlushStatus { - fn from(value: FlushStatus) -> Self { - match value { - FlushStatus::NotinflushUnspecified => RawFlushStatus::NotinflushUnspecified, - FlushStatus::Flushing => RawFlushStatus::Flushing, - FlushStatus::Flushcomplete => RawFlushStatus::Flushcomplete, - } - } -} - -impl TryFrom for FlushStatus { - type Error = Error; - - fn try_from(value: i32) -> Result { - match value { - 0 => Ok(FlushStatus::NotinflushUnspecified), - 1 => Ok(FlushStatus::Flushing), - 2 => Ok(FlushStatus::Flushcomplete), - _ => Err(Error::unknown_flush_status(value)), - } - } -} diff --git a/crates/relayer-types/src/core/ics04_channel/mod.rs b/crates/relayer-types/src/core/ics04_channel/mod.rs index b3abac8a4b..018a0608de 100644 --- a/crates/relayer-types/src/core/ics04_channel/mod.rs +++ b/crates/relayer-types/src/core/ics04_channel/mod.rs @@ -5,7 +5,6 @@ pub mod channel; pub mod commitment; pub mod error; pub mod events; -pub mod flush_status; pub mod msgs; pub mod packet; pub mod packet_id; diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index 5f993b84c8..886cfb61f7 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -1,6 +1,5 @@ pub use error::ChannelError; use ibc_proto::ibc::core::channel::v1::QueryUpgradeRequest; -use ibc_relayer_types::core::ics04_channel::flush_status::FlushStatus; use ibc_relayer_types::core::ics04_channel::msgs::chan_upgrade_ack::MsgChannelUpgradeAck; use ibc_relayer_types::core::ics04_channel::msgs::chan_upgrade_confirm::MsgChannelUpgradeConfirm; use ibc_relayer_types::core::ics04_channel::msgs::chan_upgrade_open::MsgChannelUpgradeOpen; @@ -898,7 +897,6 @@ impl Channel { vec![self.dst_connection_id().clone()], version, Sequence::from(0), - FlushStatus::NotinflushUnspecified, ); // Build the domain type message @@ -979,7 +977,6 @@ impl Channel { vec![self.dst_connection_id().clone()], Version::empty(), Sequence::from(0), - FlushStatus::NotinflushUnspecified, // UPGRADE TODO check ); // Retrieve existing channel @@ -1072,7 +1069,6 @@ impl Channel { vec![self.dst_connection_id().clone()], version, Sequence::from(0), - FlushStatus::NotinflushUnspecified, // UPGRADE TODO check ); // Get signer diff --git a/crates/relayer/src/event.rs b/crates/relayer/src/event.rs index 181c452c7a..a1771e56ff 100644 --- a/crates/relayer/src/event.rs +++ b/crates/relayer/src/event.rs @@ -5,6 +5,10 @@ use tendermint::abci::Event as AbciEvent; use ibc_relayer_types::{ applications::ics29_fee::events::{DistributeFeePacket, IncentivizedPacket}, applications::ics31_icq::events::CrossChainQueryPacket, + core::ics03_connection::{ + error::Error as ConnectionError, + events::{self as connection_events, Attributes as ConnectionAttributes}, + }, core::ics04_channel::{ error::Error as ChannelError, events::{ @@ -24,13 +28,6 @@ use ibc_relayer_types::{ ics04_channel::{channel::Ordering, packet::Sequence, version::Version}, ics24_host::identifier::ConnectionId, }, - core::{ - ics03_connection::{ - error::Error as ConnectionError, - events::{self as connection_events, Attributes as ConnectionAttributes}, - }, - ics04_channel::flush_status::FlushStatus, - }, events::{Error as IbcEventError, IbcEvent, IbcEventType}, Height, }; @@ -516,9 +513,6 @@ fn channel_upgrade_extract_attributes_from_tx( channel_events::UPGRADE_ORDERING => { attr.upgrade_ordering = Ordering::from_str(value)?; } - channel_events::CHANNEL_FLUSH_STATUS => { - attr.channel_flush_status = FlushStatus::from_str(value)?; - } _ => {} } } diff --git a/tools/test-framework/src/relayer/channel.rs b/tools/test-framework/src/relayer/channel.rs index dcaa45c70c..637ec1f195 100644 --- a/tools/test-framework/src/relayer/channel.rs +++ b/tools/test-framework/src/relayer/channel.rs @@ -6,7 +6,6 @@ use ibc_relayer::channel::{extract_channel_id, Channel, ChannelSide}; use ibc_relayer_types::core::ics04_channel::channel::{ ChannelEnd, IdentifiedChannelEnd, Ordering, State as ChannelState, UpgradeState, }; -use ibc_relayer_types::core::ics04_channel::flush_status::FlushStatus; use ibc_relayer_types::core::ics04_channel::version::Version; use ibc_relayer_types::core::ics24_host::identifier::ConnectionId; @@ -294,8 +293,6 @@ pub fn assert_eventually_channel_upgrade_init( a_side_state: ChannelState, b_side_state: ChannelState, - a_side_flush_status: FlushStatus, - b_side_flush_status: FlushStatus, handle_a: &ChainA, handle_b: &ChainB, channel_id_a: &TaggedChannelIdRef, @@ -439,17 +426,6 @@ fn assert_channel_upgrade_state( ))); } - if !channel_end_a - .value() - .flush_status_matches(&a_side_flush_status) - { - return Err(Error::generic(eyre!( - "expected channel end A flush status to be `{}`, but is instead `{}`", - a_side_flush_status, - channel_end_a.value().flush_status() - ))); - } - if !channel_end_a .value() .version_matches(upgrade_attrs.version_a()) @@ -499,17 +475,6 @@ fn assert_channel_upgrade_state( ))); } - if !channel_end_b - .value() - .flush_status_matches(&b_side_flush_status) - { - return Err(Error::generic(eyre!( - "expected channel end B flush status to be `{}`, but is instead `{}`", - b_side_flush_status, - channel_end_b.value().flush_status() - ))); - } - if !channel_end_b .value() .version_matches(upgrade_attrs.version_b()) From bf4b9e22a5d193cb209a5aae3a4a1b7dad2b0798 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Wed, 11 Oct 2023 10:10:37 +0200 Subject: [PATCH 19/26] Update Nix flake and use alpha release of channel upgrade simapp for CI --- .github/workflows/integration.yaml | 2 +- flake.lock | 302 +++++++++++++++++------------ flake.nix | 4 +- 3 files changed, 180 insertions(+), 128 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 2d9b43f44e..c2f3935fc7 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -425,7 +425,7 @@ jobs: fail-fast: false matrix: chain: - - package: ibc-go-v7-channel-upgrade + - package: ibc-go-v8-channel-upgrade-simapp command: simd account_prefix: cosmos steps: diff --git a/flake.lock b/flake.lock index 676b703bd1..fb782902ce 100644 --- a/flake.lock +++ b/flake.lock @@ -34,20 +34,37 @@ "type": "github" } }, + "beaker-src": { + "flake": false, + "locked": { + "lastModified": 1686823358, + "narHash": "sha256-bQiN5Q7RV4Uupc7rk1rGurRvCTy+5EiiB4p3bHct7M0=", + "owner": "osmosis-labs", + "repo": "beaker", + "rev": "f3c7a9fc6886aa2b4e0d259f70058d6c23c225e5", + "type": "github" + }, + "original": { + "owner": "osmosis-labs", + "ref": "v0.1.6", + "repo": "beaker", + "type": "github" + } + }, "centauri-src": { "flake": false, "locked": { - "lastModified": 1689290261, - "narHash": "sha256-S3zu7pSUF+7jnu06Fj4Co/eUe1wYEB+3CyZoN1sYUdA=", + "lastModified": 1692209286, + "narHash": "sha256-fabsZyaSCnWnhvG9nO8y39t85u+MZNyEKzU+0fSueLM=", "owner": "dzmitry-lahoda-forks", "repo": "composable-centauri", - "rev": "6b8d9fa640d7e5e0986b637bfec4a74c87ced280", + "rev": "9fa53d8b47d17219d1270146a146e4e386bc2a29", "type": "github" }, "original": { "owner": "dzmitry-lahoda-forks", "repo": "composable-centauri", - "rev": "6b8d9fa640d7e5e0986b637bfec4a74c87ced280", + "rev": "9fa53d8b47d17219d1270146a146e4e386bc2a29", "type": "github" } }, @@ -55,6 +72,7 @@ "inputs": { "akash-src": "akash-src", "apalache-src": "apalache-src", + "beaker-src": "beaker-src", "centauri-src": "centauri-src", "cosmos-sdk-src": "cosmos-sdk-src", "cosmwasm-src": "cosmwasm-src", @@ -62,6 +80,8 @@ "evmos-src": "evmos-src", "flake-utils": "flake-utils", "gaia-main-src": "gaia-main-src", + "gaia10-src": "gaia10-src", + "gaia11-src": "gaia11-src", "gaia5-src": "gaia5-src", "gaia6-ordered-src": "gaia6-ordered-src", "gaia6-src": "gaia6-src", @@ -75,8 +95,9 @@ "ibc-go-v4-src": "ibc-go-v4-src", "ibc-go-v5-src": "ibc-go-v5-src", "ibc-go-v6-src": "ibc-go-v6-src", - "ibc-go-v7-channel-upgrade-src": "ibc-go-v7-channel-upgrade-src", "ibc-go-v7-src": "ibc-go-v7-src", + "ibc-go-v8-channel-upgrade-src": "ibc-go-v8-channel-upgrade-src", + "ibc-go-v8-src": "ibc-go-v8-src", "ibc-rs-src": "ibc-rs-src", "ica-src": "ica-src", "ignite-cli-src": "ignite-cli-src", @@ -89,9 +110,6 @@ "nix-std": "nix-std", "nixpkgs": "nixpkgs", "osmosis-src": "osmosis-src", - "osmosis6-src": "osmosis6-src", - "osmosis7-src": "osmosis7-src", - "osmosis8-src": "osmosis8-src", "pre-commit-hooks": "pre-commit-hooks", "regen-src": "regen-src", "relayer-src": "relayer-src", @@ -104,7 +122,6 @@ "stoml-src": "stoml-src", "stride-consumer-src": "stride-consumer-src", "stride-src": "stride-src", - "terra-src": "terra-src", "ts-relayer-src": "ts-relayer-src", "umee-src": "umee-src", "wasmd-src": "wasmd-src", @@ -118,16 +135,15 @@ "wasmvm_1_beta7-src": "wasmvm_1_beta7-src" }, "locked": { - "lastModified": 1692879240, - "narHash": "sha256-oVxjLGuWIaWeyI9KufDgQKtGyfKYMxDzvGk5UNuRjnk=", + "lastModified": 1697010618, + "narHash": "sha256-lktcpUUape/qh0kDDrT3sLKUOP5o1rCSWW/o6otWtFY=", "owner": "informalsystems", "repo": "cosmos.nix", - "rev": "8cdc17fbefdafce7ff659838372a6ab740798b6e", + "rev": "7a42d2ad91fcc33a9fd4871a5b7ca82ff1850a0a", "type": "github" }, "original": { "owner": "informalsystems", - "ref": "ibc-go-channel-upgrade", "repo": "cosmos.nix", "type": "github" } @@ -217,12 +233,15 @@ } }, "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1649676176, - "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "lastModified": 1692792214, + "narHash": "sha256-voZDQOvqHsaReipVd3zTKSBwN7LZcUwi3/ThMxRZToU=", "owner": "numtide", "repo": "flake-utils", - "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "rev": "1721b3e7c882f75f2301b00d48a2884af8c448ae", "type": "github" }, "original": { @@ -233,7 +252,7 @@ }, "flake-utils_2": { "inputs": { - "systems": "systems" + "systems": "systems_2" }, "locked": { "lastModified": 1681202837, @@ -250,8 +269,23 @@ } }, "flake-utils_3": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { "inputs": { - "systems": "systems_2" + "systems": "systems_3" }, "locked": { "lastModified": 1694529238, @@ -270,11 +304,11 @@ "gaia-main-src": { "flake": false, "locked": { - "lastModified": 1664958609, - "narHash": "sha256-w9tJJXimf0AhYhgColCjdHGh14sAId0Svtz/hHNYNlI=", + "lastModified": 1692777545, + "narHash": "sha256-Gg6pqITR+aqq4FBE0h/HvXpG+whtli2gJXw+dsyoKEE=", "owner": "cosmos", "repo": "gaia", - "rev": "4d3a104f6ce6f441e6588cdb8fa6e600396ad3ac", + "rev": "97d0a1359716c5c534053a6a15a007b740d34780", "type": "github" }, "original": { @@ -283,6 +317,40 @@ "type": "github" } }, + "gaia10-src": { + "flake": false, + "locked": { + "lastModified": 1688401730, + "narHash": "sha256-F72AxDI1OdleE8If5s4HJbORqMsDVsdEO5q7nrK07E8=", + "owner": "cosmos", + "repo": "gaia", + "rev": "a2b14cdd568273e12b80579b4e22681df95b4cb9", + "type": "github" + }, + "original": { + "owner": "cosmos", + "ref": "v10.0.2", + "repo": "gaia", + "type": "github" + } + }, + "gaia11-src": { + "flake": false, + "locked": { + "lastModified": 1690464504, + "narHash": "sha256-bIegGSPDdDRbznfgsrojsGCwCPSesNknpffTFskc7fE=", + "owner": "cosmos", + "repo": "gaia", + "rev": "541a8d86af28231c767d6db52eb88ba9496ad0c4", + "type": "github" + }, + "original": { + "owner": "cosmos", + "ref": "v11.0.0", + "repo": "gaia", + "type": "github" + } + }, "gaia5-src": { "flake": false, "locked": { @@ -526,36 +594,53 @@ "type": "github" } }, - "ibc-go-v7-channel-upgrade-src": { + "ibc-go-v7-src": { "flake": false, "locked": { - "lastModified": 1692787150, - "narHash": "sha256-2EicMXlcBneBR5NwpAyVZ/uSvLaWrJEKLmb5/H+o/Ls=", + "lastModified": 1693509694, + "narHash": "sha256-umh/ckDALt0ugXwN8glcaCkGfAQvXY7S3Jd95Do2XeA=", "owner": "cosmos", "repo": "ibc-go", - "rev": "f1e8ae805a3633d47928cfc02315a1a19ca80a0e", + "rev": "c75650a1a037a9fecba5a9005df380f707520ff7", "type": "github" }, "original": { "owner": "cosmos", + "ref": "v7.3.0", "repo": "ibc-go", - "rev": "f1e8ae805a3633d47928cfc02315a1a19ca80a0e", "type": "github" } }, - "ibc-go-v7-src": { + "ibc-go-v8-channel-upgrade-src": { "flake": false, "locked": { - "lastModified": 1686298823, - "narHash": "sha256-8ModVWpRWbwWQLj5BCCopn7vpOJjFp4ISESCCp4pqWQ=", + "lastModified": 1695726576, + "narHash": "sha256-mM6h1KAi8lQUrJakxI6f8WI+vpmBhCnAysk3hTZBI7M=", "owner": "cosmos", "repo": "ibc-go", - "rev": "000e9d20b15b3c6939cefc0e26daa4b64c1be8fb", + "rev": "63c30108f0ecf954108cf51f50f3d36ec58c7e51", "type": "github" }, "original": { "owner": "cosmos", - "ref": "v7.1.0", + "ref": "04-channel-upgrades-alpha.0", + "repo": "ibc-go", + "type": "github" + } + }, + "ibc-go-v8-src": { + "flake": false, + "locked": { + "lastModified": 1695930850, + "narHash": "sha256-BHmsnnqB+SoS8UdfGbEk07EXGZJG9ELo4+2gAbP8LdM=", + "owner": "cosmos", + "repo": "ibc-go", + "rev": "9c7212198d0ef82b8219ea66cee9c96b40e7981d", + "type": "github" + }, + "original": { + "owner": "cosmos", + "ref": "v8.0.0-beta.1", "repo": "ibc-go", "type": "github" } @@ -580,11 +665,11 @@ "ica-src": { "flake": false, "locked": { - "lastModified": 1647255020, - "narHash": "sha256-Ah5pivnAmk3W0fLWnrBbi84tqwJYQETSILSvNVH6fI8=", + "lastModified": 1679480012, + "narHash": "sha256-LFyInZT7z/8/d3RYepYf95ryxA7Pbg3TMQhHrHUvlCA=", "owner": "cosmos", "repo": "interchain-accounts-demo", - "rev": "09b6a493a84a135f395d74d5ec82ea983617a714", + "rev": "fe07f304731161055cecec120e0d2de01e84bad4", "type": "github" }, "original": { @@ -714,11 +799,11 @@ }, "nix-std": { "locked": { - "lastModified": 1658944356, - "narHash": "sha256-+nBrRSPsDIjrmLfLdiB/a22Gj4bhEF53ubWN0z33NJo=", + "lastModified": 1685917625, + "narHash": "sha256-2manVKofCZrCToVDnDYNvtYUFBYOM5JhdDoNGVY4fq4=", "owner": "chessai", "repo": "nix-std", - "rev": "9500903a19ef2720469578de0e10ce9e66623bdf", + "rev": "e20af8822b5739434b875643bfc61fe0195ea2fb", "type": "github" }, "original": { @@ -729,11 +814,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1673947312, - "narHash": "sha256-xx/2nRwRy3bXrtry6TtydKpJpqHahjuDB5sFkQ/XNDE=", + "lastModified": 1692684269, + "narHash": "sha256-zJk2pyF4Cuhtor0khtPlf+hfJIh22rzAUC+KU3Ob31Q=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2d38b664b4400335086a713a0036aafaa002c003", + "rev": "9d757ec498666cc1dcc6f2be26db4fd3e1e9ab37", "type": "github" }, "original": { @@ -745,16 +830,16 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1673800717, - "narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-22.11", + "ref": "nixos-23.05", "repo": "nixpkgs", "type": "github" } @@ -777,84 +862,49 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1696757521, - "narHash": "sha256-cfgtLNCBLFx2qOzRLI6DHfqTdfWI+UbvsKYa3b3fvaA=", - "owner": "nixos", + "lastModified": 1674990008, + "narHash": "sha256-4zOyp+hFW2Y7imxIpZqZGT8CEqKmDjwgfD6BzRUE0mQ=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "2646b294a146df2781b1ca49092450e8a32814e1", + "rev": "d2bbcbe6c626d339b25a4995711f07625b508214", "type": "github" }, "original": { - "owner": "nixos", + "owner": "NixOS", "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, - "osmosis-src": { - "flake": false, - "locked": { - "lastModified": 1687920590, - "narHash": "sha256-nzNUf55ZgWUuaEJ25hvGi34zzqTuWOGm3j72BtldGxs=", - "owner": "osmosis-labs", - "repo": "osmosis", - "rev": "4a4a94585872e3196b9c83286979cda11d4889e3", - "type": "github" - }, - "original": { - "owner": "osmosis-labs", - "ref": "v15.2.0", - "repo": "osmosis", - "type": "github" - } - }, - "osmosis6-src": { - "flake": false, - "locked": { - "lastModified": 1646678581, - "narHash": "sha256-fGcz33PPA5dJ4J9vgfbYvBxNydu3/YuKSCf8pZkn5PM=", - "owner": "osmosis-labs", - "repo": "osmosis", - "rev": "2b61fd38505dbcbad08e78c96b7ab17e7ae1c85d", - "type": "github" - }, - "original": { - "owner": "osmosis-labs", - "ref": "v6.4.1", - "repo": "osmosis", - "type": "github" - } - }, - "osmosis7-src": { - "flake": false, + "nixpkgs_4": { "locked": { - "lastModified": 1651600564, - "narHash": "sha256-aY6L+5Iw5tu/QOZ1ZgZq163MCy4ZZDHVl53MhZ8AyS4=", - "owner": "osmosis-labs", - "repo": "osmosis", - "rev": "ab02323b075e2573cd7a54736d705c88797d11c5", + "lastModified": 1696757521, + "narHash": "sha256-cfgtLNCBLFx2qOzRLI6DHfqTdfWI+UbvsKYa3b3fvaA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2646b294a146df2781b1ca49092450e8a32814e1", "type": "github" }, "original": { - "owner": "osmosis-labs", - "ref": "v7.3.0", - "repo": "osmosis", + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", "type": "github" } }, - "osmosis8-src": { + "osmosis-src": { "flake": false, "locked": { - "lastModified": 1652595598, - "narHash": "sha256-upQzIJnzswT+HO6H0welw/X5n4F/K1k/dP4FQMOeC8Q=", + "lastModified": 1692886846, + "narHash": "sha256-VdM6hGqcDyCNx7AR8s7SxE3pEMxHiIhCJ7592sDp3uc=", "owner": "osmosis-labs", "repo": "osmosis", - "rev": "16e3b51f19a58f815a4eabcbcee11886eb33e026", + "rev": "1c5f25d04f19d6302e0bdd585ba1d7a2cc96e397", "type": "github" }, "original": { "owner": "osmosis-labs", - "ref": "v8.0.0", + "ref": "v18.0.0", "repo": "osmosis", "type": "github" } @@ -874,11 +924,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1674122161, - "narHash": "sha256-9QM4rvgUSEwO8DWtJN9sR/afEqrH1s3b6ACsZT5wiAM=", + "lastModified": 1692274144, + "narHash": "sha256-BxTQuRUANQ81u8DJznQyPmRsg63t4Yc+0kcyq6OLz8s=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "53e766957b73298fa68b47478c48cbcc005cc18a", + "rev": "7e3517c03d46159fdbf8c0e5c97f82d5d4b0c8fa", "type": "github" }, "original": { @@ -924,8 +974,8 @@ "root": { "inputs": { "cosmos-nix": "cosmos-nix", - "flake-utils": "flake-utils_3", - "nixpkgs": "nixpkgs_3" + "flake-utils": "flake-utils_4", + "nixpkgs": "nixpkgs_4" } }, "rust-overlay": { @@ -949,12 +999,16 @@ } }, "sbt-derivation": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_3" + }, "locked": { - "lastModified": 1617466857, - "narHash": "sha256-Z7eWMLreLtiSiJ3nWDWBy1w9WNEFexkYCgT/dWZF7yo=", + "lastModified": 1675083208, + "narHash": "sha256-+sSFhSpV2jckr1qYlX/SaxQ6IdpagD6o4rru/3HAl0I=", "owner": "zaninime", "repo": "sbt-derivation", - "rev": "920b6f187937493371e2b1687261017e6e014cf1", + "rev": "92d6d6d825e3f6ae5642d1cce8ff571c3368aaf7", "type": "github" }, "original": { @@ -966,11 +1020,11 @@ "sconfig-src": { "flake": false, "locked": { - "lastModified": 1594094862, - "narHash": "sha256-jR2hkR0YlPyW2nKWJl90kL80R+9psNKGPYxGg7Y/YGw=", + "lastModified": 1679585941, + "narHash": "sha256-ywh9IcqMWbRHqJkGJezcDCvfbBYNJH7ualKvPJQRcHA=", "owner": "freshautomations", "repo": "sconfig", - "rev": "88043754c024aec433b3b059af170b6f555931c3", + "rev": "41450b55f3b37b4b7a0fdf4a69c707619dbeb47c", "type": "github" }, "original": { @@ -1033,11 +1087,11 @@ "stoml-src": { "flake": false, "locked": { - "lastModified": 1622172633, - "narHash": "sha256-PvKkOjjWkmK90PzKcOBq0pUWLjHLjfYs9PRqqzAR7/8=", + "lastModified": 1666796497, + "narHash": "sha256-Adjag1/Hd2wrar2/anD6jQEMDvUc2TOIG7DlEgxpTXc=", "owner": "freshautomations", "repo": "stoml", - "rev": "f5dab84dbf52345a1f36389aec38b02fda086a47", + "rev": "4b2cd09b5795a54fddc215f0d24e24071894b3cf", "type": "github" }, "original": { @@ -1110,20 +1164,18 @@ "type": "github" } }, - "terra-src": { - "flake": false, + "systems_3": { "locked": { - "lastModified": 1645516218, - "narHash": "sha256-7cmVYWFLeOZJtbfw8qaVKLDMVafoeFDXOcrmrMS9buE=", - "owner": "terra-money", - "repo": "core", - "rev": "a6b93b72a7d4fabbbb85fb89e685426f5d07cac1", + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { - "owner": "terra-money", - "ref": "v0.5.17", - "repo": "core", + "owner": "nix-systems", + "repo": "default", "type": "github" } }, @@ -1147,11 +1199,11 @@ "umee-src": { "flake": false, "locked": { - "lastModified": 1648176855, - "narHash": "sha256-s7MnAaM+O84JDO1uBNZm1qGN6ZfYmhXD5rCvns4u/rc=", + "lastModified": 1649261156, + "narHash": "sha256-hydRL/88fHCW/k7z7GoqAwvynZuvLEDLyA6A9Cm+6UY=", "owner": "umee-network", "repo": "umee", - "rev": "3c9b8db04d6ab19d31e89df65232abc35d1a8a59", + "rev": "42f57545251ce5337dcc5fe4309520ead89183b9", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c55745e361..b9d7b35cbb 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { nixpkgs.url = github:nixos/nixpkgs/nixpkgs-unstable; flake-utils.url = github:numtide/flake-utils; - cosmos-nix.url = github:informalsystems/cosmos.nix/ibc-go-channel-upgrade; + cosmos-nix.url = github:informalsystems/cosmos.nix; }; outputs = inputs: let @@ -37,7 +37,7 @@ ibc-go-v5-simapp ibc-go-v6-simapp ibc-go-v7-simapp - ibc-go-v7-channel-upgrade + ibc-go-v8-channel-upgrade-simapp apalache evmos juno From af442c34e842c03cd7bae63602a706089eec6b76 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Wed, 11 Oct 2023 10:27:53 +0200 Subject: [PATCH 20/26] Fix test-stable and change 'into_i32' to 'as_i32' for Channel State --- crates/relayer-types/src/core/ics04_channel/channel.rs | 6 +++--- .../src/core/ics04_channel/msgs/chan_upgrade_confirm.rs | 2 +- .../src/core/ics04_channel/msgs/chan_upgrade_open.rs | 4 ++-- crates/relayer/src/channel.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/relayer-types/src/core/ics04_channel/channel.rs b/crates/relayer-types/src/core/ics04_channel/channel.rs index 982ccb0219..dd748422df 100644 --- a/crates/relayer-types/src/core/ics04_channel/channel.rs +++ b/crates/relayer-types/src/core/ics04_channel/channel.rs @@ -58,7 +58,7 @@ impl TryFrom for IdentifiedChannelEnd { impl From for RawIdentifiedChannel { fn from(value: IdentifiedChannelEnd) -> Self { RawIdentifiedChannel { - state: value.channel_end.state.into_i32(), + state: value.channel_end.state.as_i32(), ordering: value.channel_end.ordering as i32, counterparty: Some(value.channel_end.counterparty().clone().into()), connection_hops: value @@ -151,7 +151,7 @@ impl TryFrom for ChannelEnd { impl From for RawChannel { fn from(value: ChannelEnd) -> Self { RawChannel { - state: value.state.into_i32(), + state: value.state.as_i32(), ordering: value.ordering as i32, counterparty: Some(value.counterparty().clone().into()), connection_hops: value @@ -450,7 +450,7 @@ impl State { } // Parses the State out from a i32. - pub fn into_i32(&self) -> i32 { + pub fn as_i32(&self) -> i32 { match self { State::Uninitialized => 0, State::Init => 1, diff --git a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs index 338f2f1d98..3ae7856a13 100644 --- a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs +++ b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_confirm.rs @@ -108,7 +108,7 @@ impl From for RawMsgChannelUpgradeConfirm { RawMsgChannelUpgradeConfirm { port_id: domain_msg.port_id.to_string(), channel_id: domain_msg.channel_id.to_string(), - counterparty_channel_state: domain_msg.counterparty_channel_state.into_i32(), + counterparty_channel_state: domain_msg.counterparty_channel_state.as_i32(), counterparty_upgrade: Some(domain_msg.counterparty_upgrade.into()), proof_upgrade: domain_msg.proof_upgrade.into(), proof_channel: domain_msg.proof_channel.into(), diff --git a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs index 48b818779b..a33ba54851 100644 --- a/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs +++ b/crates/relayer-types/src/core/ics04_channel/msgs/chan_upgrade_open.rs @@ -90,7 +90,7 @@ impl From for RawMsgChannelUpgradeOpen { RawMsgChannelUpgradeOpen { port_id: domain_msg.port_id.to_string(), channel_id: domain_msg.channel_id.to_string(), - counterparty_channel_state: domain_msg.counterparty_channel_state.into_i32(), + counterparty_channel_state: domain_msg.counterparty_channel_state.as_i32(), proof_channel: domain_msg.proof_channel.into(), proof_height: Some(domain_msg.proof_height.into()), signer: domain_msg.signer.to_string(), @@ -111,7 +111,7 @@ pub mod test_util { RawMsgChannelUpgradeOpen { port_id: PortId::default().to_string(), channel_id: ChannelId::default().to_string(), - counterparty_channel_state: 7, // AckUpgrade + counterparty_channel_state: 6, // Flushcomplete proof_channel: get_dummy_proof(), proof_height: Some(RawHeight { revision_number: 1, diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index 886cfb61f7..607fa75171 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -2132,7 +2132,7 @@ fn check_destination_channel_state( // TODO: Refactor into a method let good_state = - existing_channel.state().into_i32() as u32 <= expected_channel.state().into_i32() as u32; + existing_channel.state().as_i32() as u32 <= expected_channel.state().as_i32() as u32; let good_channel_port_ids = existing_channel.counterparty().channel_id().is_none() || existing_channel.counterparty().channel_id() == expected_channel.counterparty().channel_id() From e113556f1f97b65bfecedce8a2a6801695e5d876 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Thu, 12 Oct 2023 13:16:34 +0200 Subject: [PATCH 21/26] Fix python tests --- e2e/e2e/channel.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/e2e/e2e/channel.py b/e2e/e2e/channel.py index 0036ae7fa3..37f3871aee 100644 --- a/e2e/e2e/channel.py +++ b/e2e/e2e/channel.py @@ -472,15 +472,17 @@ def handshake( split() a_chan_end = query_channel_end(c, side_a, port_id, a_chan_id) - if a_chan_end.state != 'Open': + expected_state = str({'Open': 'NotUpgrading'}) + if str(a_chan_end.state) != str({'Open': 'NotUpgrading'}): l.error( - f'Channel end with id {a_chan_id} on chain {side_a} is not in Open state, got: {a_chan_end.state}') + f"Channel end with id {a_chan_id} on chain {side_a} is not in {expected_state} state, got: {a_chan_end.state}") exit(1) b_chan_end = query_channel_end(c, side_b, port_id, b_chan_id) - if b_chan_end.state != 'Open': + print(b_chan_end.state) + if str(b_chan_end.state) != str({'Open': 'NotUpgrading'}): l.error( - f'Channel end with id {b_chan_id} on chain {side_b} is not in Open state, got: {b_chan_end.state}') + f'Channel end with id {b_chan_id} on chain {side_b} is not in {expected_state} state, got: {b_chan_end.state}') exit(1) a_chan_ends = query_channel_ends(c, side_a, port_id, a_chan_id) From db3d29ecea826cbb4281e0776d94783eb65f2c56 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Thu, 12 Oct 2023 13:26:00 +0200 Subject: [PATCH 22/26] Use state comparison method 'less_or_equal_progress' where applicable --- crates/relayer/src/channel.rs | 5 +++-- crates/relayer/src/connection.rs | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index 607fa75171..bb851ba4ef 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -2131,8 +2131,9 @@ fn check_destination_channel_state( existing_channel.connection_hops() == expected_channel.connection_hops(); // TODO: Refactor into a method - let good_state = - existing_channel.state().as_i32() as u32 <= expected_channel.state().as_i32() as u32; + let good_state = existing_channel + .state() + .less_or_equal_progress(*expected_channel.state()); let good_channel_port_ids = existing_channel.counterparty().channel_id().is_none() || existing_channel.counterparty().channel_id() == expected_channel.counterparty().channel_id() diff --git a/crates/relayer/src/connection.rs b/crates/relayer/src/connection.rs index 341049446b..52326ad937 100644 --- a/crates/relayer/src/connection.rs +++ b/crates/relayer/src/connection.rs @@ -1365,7 +1365,9 @@ fn check_destination_connection_state( && existing_connection.counterparty().client_id() == expected_connection.counterparty().client_id(); - let good_state = *existing_connection.state() as u32 <= *expected_connection.state() as u32; + let good_state = existing_connection + .state() + .less_or_equal_progress(*expected_connection.state()); let good_connection_ids = existing_connection.counterparty().connection_id().is_none() || existing_connection.counterparty().connection_id() From ef4d8a9503bf4e6d290c3ede005a1c73d046df68 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Fri, 13 Oct 2023 13:14:16 +0200 Subject: [PATCH 23/26] Add tests for channel upgrade completion --- .../channel_upgrade/manual_channel_upgrade.rs | 187 ------ .../src/tests/channel_upgrade/mod.rs | 2 +- .../upgrade_handshake_steps.rs | 632 ++++++++++++++++++ 3 files changed, 633 insertions(+), 188 deletions(-) delete mode 100644 tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs create mode 100644 tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs diff --git a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs b/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs deleted file mode 100644 index 31ce58b267..0000000000 --- a/tools/integration-test/src/tests/channel_upgrade/manual_channel_upgrade.rs +++ /dev/null @@ -1,187 +0,0 @@ -//! Tests channel upgrade: -//! -//! - `ChannelUpgradeManualHandshake` tests each step of the channel upgrade manually, -//! without relaying on the supervisor. - -use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest, QueryHeight}; -use ibc_relayer_types::core::ics04_channel::version::Version; -use ibc_test_framework::prelude::*; -use ibc_test_framework::relayer::channel::{ - assert_eventually_channel_established, assert_eventually_channel_upgrade_ack, - assert_eventually_channel_upgrade_confirm, assert_eventually_channel_upgrade_init, - assert_eventually_channel_upgrade_open, assert_eventually_channel_upgrade_try, - ChannelUpgradableAttributes, -}; - -#[test] -fn test_channel_upgrade_manual_handshake() -> Result<(), Error> { - run_binary_channel_test(&ChannelUpgradeManualHandshake) -} - -pub struct ChannelUpgradeManualHandshake; - -impl TestOverrides for ChannelUpgradeManualHandshake { - fn should_spawn_supervisor(&self) -> bool { - false - } -} - -impl BinaryChannelTest for ChannelUpgradeManualHandshake { - fn run( - &self, - _config: &TestConfig, - _relayer: RelayerDriver, - chains: ConnectedChains, - channels: ConnectedChannel, - ) -> Result<(), Error> { - info!("Check that channels are both in OPEN State"); - - assert_eventually_channel_established( - &chains.handle_b, - &chains.handle_a, - &channels.channel_id_b.as_ref(), - &channels.port_b.as_ref(), - )?; - - let channel_end_a = chains - .handle_a - .query_channel( - QueryChannelRequest { - port_id: channels.port_a.0.clone(), - channel_id: channels.channel_id_a.0.clone(), - height: QueryHeight::Latest, - }, - IncludeProof::No, - ) - .map(|(channel_end, _)| channel_end) - .map_err(|e| eyre!("Error querying ChannelEnd A: {e}"))?; - - let channel_end_b = chains - .handle_b - .query_channel( - QueryChannelRequest { - port_id: channels.port_b.0.clone(), - channel_id: channels.channel_id_b.0.clone(), - height: QueryHeight::Latest, - }, - IncludeProof::No, - ) - .map(|(channel_end, _)| channel_end) - .map_err(|e| eyre!("Error querying ChannelEnd B: {e}"))?; - - let old_version = channel_end_a.version; - let old_ordering = channel_end_a.ordering; - let old_connection_hops_a = channel_end_a.connection_hops; - let old_connection_hops_b = channel_end_b.connection_hops; - - let channel = channels.channel; - let new_version = Version::ics20_with_fee(); - let new_ordering = None; - let new_connection_hops = None; - - let old_attrs = ChannelUpgradableAttributes::new( - old_version.clone(), - old_version.clone(), - old_ordering, - old_connection_hops_a.clone(), - old_connection_hops_b.clone(), - ); - - let interm_attrs = ChannelUpgradableAttributes::new( - old_version, - new_version.clone(), - old_ordering, - old_connection_hops_a.clone(), - old_connection_hops_b.clone(), - ); - - let upgraded_attrs = ChannelUpgradableAttributes::new( - new_version.clone(), - new_version.clone(), - old_ordering, - old_connection_hops_a, - old_connection_hops_b, - ); - - info!("Will run ChanUpgradeInit step..."); - - // Note: Initialising a channel upgrade this way, without requiring a - // signature or proof of authority to perform the channel upgrade, will - // eventually be removed. - // Only authority (gov module or other) will be able to trigger a channel upgrade. - // See: https://github.com/cosmos/ibc-go/issues/4186 - channel.flipped().build_chan_upgrade_init_and_send( - Some(new_version), - new_ordering, - new_connection_hops, - )?; - - info!("Check that the step ChanUpgradeInit was correctly executed..."); - - assert_eventually_channel_upgrade_init( - &chains.handle_a, - &chains.handle_b, - &channels.channel_id_a.as_ref(), - &channels.port_a.as_ref(), - &old_attrs, - )?; - - info!("Will run ChanUpgradeTry step..."); - - channel.build_chan_upgrade_try_and_send()?; - - info!("Check that the step ChanUpgradeTry was correctly executed..."); - - assert_eventually_channel_upgrade_try( - &chains.handle_b, - &chains.handle_a, - &channels.channel_id_b.as_ref(), - &channels.port_b.as_ref(), - &old_attrs.flipped(), - )?; - - info!("Will run ChanUpgradeAck step..."); - - channel.flipped().build_chan_upgrade_ack_and_send()?; - - info!("Check that the step ChanUpgradeAck was correctly executed..."); - - assert_eventually_channel_upgrade_ack( - &chains.handle_a, - &chains.handle_b, - &channels.channel_id_a.as_ref(), - &channels.port_a.as_ref(), - &old_attrs, - )?; - - info!("Will run ChanUpgradeConfirm step..."); - - channel.build_chan_upgrade_confirm_and_send()?; - - info!("Check that the step ChanUpgradeConfirm was correctly executed..."); - - assert_eventually_channel_upgrade_confirm( - &chains.handle_b, - &chains.handle_a, - &channels.channel_id_b.as_ref(), - &channels.port_b.as_ref(), - &interm_attrs.flipped(), - )?; - - info!("Will run ChanUpgradeOpen step..."); - - channel.flipped().build_chan_upgrade_open_and_send()?; - - info!("Check that the ChanUpgradeOpen steps were correctly executed..."); - - assert_eventually_channel_upgrade_open( - &chains.handle_a, - &chains.handle_b, - &channels.channel_id_a.as_ref(), - &channels.port_a.as_ref(), - &upgraded_attrs, - )?; - - Ok(()) - } -} diff --git a/tools/integration-test/src/tests/channel_upgrade/mod.rs b/tools/integration-test/src/tests/channel_upgrade/mod.rs index f6e864ab78..158224819b 100644 --- a/tools/integration-test/src/tests/channel_upgrade/mod.rs +++ b/tools/integration-test/src/tests/channel_upgrade/mod.rs @@ -1,3 +1,3 @@ pub mod ics29; -pub mod manual_channel_upgrade; pub mod upgrade_handshake; +pub mod upgrade_handshake_steps; diff --git a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs new file mode 100644 index 0000000000..f775f57f32 --- /dev/null +++ b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs @@ -0,0 +1,632 @@ +//! Tests channel upgrade: +//! +//! - `ChannelUpgradeManualHandshake` tests each step of the channel upgrade manually, +//! without relaying on the supervisor. +//! +//! - `ChannelUpgradeHandshakeFromTry` tests that the channel worker will finish the +//! upgrade handshake if the channel is being upgraded and is at the Try step. +//! +//! - `ChannelUpgradeHandshakeFromAck` tests that the channel worker will finish the +//! upgrade handshake if the channel is being upgraded and is at the Ack step. +//! +//! - `ChannelUpgradeHandshakeFromConfirm` tests that the channel worker will finish the +//! upgrade handshake if the channel is being upgraded and is at the Confirm step. + +use ibc_relayer::chain::requests::{IncludeProof, QueryChannelRequest, QueryHeight}; +use ibc_relayer_types::core::ics04_channel::version::Version; +use ibc_test_framework::prelude::*; +use ibc_test_framework::relayer::channel::{ + assert_eventually_channel_established, assert_eventually_channel_upgrade_ack, + assert_eventually_channel_upgrade_confirm, assert_eventually_channel_upgrade_init, + assert_eventually_channel_upgrade_open, assert_eventually_channel_upgrade_try, + ChannelUpgradableAttributes, +}; + +#[test] +fn test_channel_upgrade_manual_handshake() -> Result<(), Error> { + run_binary_channel_test(&ChannelUpgradeManualHandshake) +} + +#[test] +fn test_channel_upgrade_handshake_from_try() -> Result<(), Error> { + run_binary_channel_test(&ChannelUpgradeHandshakeFromTry) +} + +#[test] +fn test_channel_upgrade_handshake_from_ack() -> Result<(), Error> { + run_binary_channel_test(&ChannelUpgradeHandshakeFromAck) +} + +#[test] +fn test_channel_upgrade_handshake_from_confirm() -> Result<(), Error> { + run_binary_channel_test(&ChannelUpgradeHandshakeFromConfirm) +} + +pub struct ChannelUpgradeManualHandshake; + +impl TestOverrides for ChannelUpgradeManualHandshake { + fn should_spawn_supervisor(&self) -> bool { + false + } +} + +impl BinaryChannelTest for ChannelUpgradeManualHandshake { + fn run( + &self, + _config: &TestConfig, + _relayer: RelayerDriver, + chains: ConnectedChains, + channels: ConnectedChannel, + ) -> Result<(), Error> { + info!("Check that channels are both in OPEN State"); + + assert_eventually_channel_established( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + )?; + + let channel_end_a = chains + .handle_a + .query_channel( + QueryChannelRequest { + port_id: channels.port_a.0.clone(), + channel_id: channels.channel_id_a.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd A: {e}"))?; + + let channel_end_b = chains + .handle_b + .query_channel( + QueryChannelRequest { + port_id: channels.port_b.0.clone(), + channel_id: channels.channel_id_b.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd B: {e}"))?; + + let old_version = channel_end_a.version; + let old_ordering = channel_end_a.ordering; + let old_connection_hops_a = channel_end_a.connection_hops; + let old_connection_hops_b = channel_end_b.connection_hops; + + let channel = channels.channel; + let new_version = Version::ics20_with_fee(); + let new_ordering = None; + let new_connection_hops = None; + + let old_attrs = ChannelUpgradableAttributes::new( + old_version.clone(), + old_version.clone(), + old_ordering, + old_connection_hops_a.clone(), + old_connection_hops_b.clone(), + ); + + let interm_attrs = ChannelUpgradableAttributes::new( + old_version, + new_version.clone(), + old_ordering, + old_connection_hops_a.clone(), + old_connection_hops_b.clone(), + ); + + let upgraded_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), + new_version.clone(), + old_ordering, + old_connection_hops_a, + old_connection_hops_b, + ); + + info!("Will run ChanUpgradeInit step..."); + + // Note: Initialising a channel upgrade this way, without requiring a + // signature or proof of authority to perform the channel upgrade, will + // eventually be removed. + // Only authority (gov module or other) will be able to trigger a channel upgrade. + // See: https://github.com/cosmos/ibc-go/issues/4186 + channel.flipped().build_chan_upgrade_init_and_send( + Some(new_version), + new_ordering, + new_connection_hops, + )?; + + info!("Check that the step ChanUpgradeInit was correctly executed..."); + + assert_eventually_channel_upgrade_init( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &old_attrs, + )?; + + info!("Will run ChanUpgradeTry step..."); + + channel.build_chan_upgrade_try_and_send()?; + + info!("Check that the step ChanUpgradeTry was correctly executed..."); + + assert_eventually_channel_upgrade_try( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + &old_attrs.flipped(), + )?; + + info!("Will run ChanUpgradeAck step..."); + + channel.flipped().build_chan_upgrade_ack_and_send()?; + + info!("Check that the step ChanUpgradeAck was correctly executed..."); + + assert_eventually_channel_upgrade_ack( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &old_attrs, + )?; + + info!("Will run ChanUpgradeConfirm step..."); + + channel.build_chan_upgrade_confirm_and_send()?; + + info!("Check that the step ChanUpgradeConfirm was correctly executed..."); + + assert_eventually_channel_upgrade_confirm( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + &interm_attrs.flipped(), + )?; + + info!("Will run ChanUpgradeOpen step..."); + + channel.flipped().build_chan_upgrade_open_and_send()?; + + info!("Check that the ChanUpgradeOpen steps were correctly executed..."); + + assert_eventually_channel_upgrade_open( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &upgraded_attrs, + )?; + + Ok(()) + } +} + +pub struct ChannelUpgradeHandshakeFromTry; + +impl TestOverrides for ChannelUpgradeHandshakeFromTry { + fn modify_relayer_config(&self, config: &mut Config) { + config.mode.channels.enabled = true; + } + + fn should_spawn_supervisor(&self) -> bool { + false + } +} + +impl BinaryChannelTest for ChannelUpgradeHandshakeFromTry { + fn run( + &self, + _config: &TestConfig, + relayer: RelayerDriver, + chains: ConnectedChains, + channels: ConnectedChannel, + ) -> Result<(), Error> { + info!("Check that channels are both in OPEN State"); + + assert_eventually_channel_established( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + )?; + + let channel_end_a = chains + .handle_a + .query_channel( + QueryChannelRequest { + port_id: channels.port_a.0.clone(), + channel_id: channels.channel_id_a.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd A: {e}"))?; + + let channel_end_b = chains + .handle_b + .query_channel( + QueryChannelRequest { + port_id: channels.port_b.0.clone(), + channel_id: channels.channel_id_b.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd B: {e}"))?; + + let old_version = channel_end_a.version; + let old_ordering = channel_end_a.ordering; + let old_connection_hops_a = channel_end_a.connection_hops; + let old_connection_hops_b = channel_end_b.connection_hops; + + let channel = channels.channel; + let new_version = Version::ics20_with_fee(); + let new_ordering = None; + let new_connection_hops = None; + + let old_attrs = ChannelUpgradableAttributes::new( + old_version.clone(), + old_version.clone(), + old_ordering, + old_connection_hops_a.clone(), + old_connection_hops_b.clone(), + ); + + let upgraded_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), + new_version.clone(), + old_ordering, + old_connection_hops_a, + old_connection_hops_b, + ); + + info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); + + // Note: Initialising a channel upgrade this way, without requiring a + // signature or proof of authority to perform the channel upgrade, will + // eventually be removed. + // Only authority (gov module or other) will be able to trigger a channel upgrade. + // See: https://github.com/cosmos/ibc-go/issues/4186 + channel.flipped().build_chan_upgrade_init_and_send( + Some(new_version), + new_ordering, + new_connection_hops, + )?; + + info!("Will run ChanUpgradeTry step..."); + + channel.build_chan_upgrade_try_and_send()?; + + info!("Check that the step ChanUpgradeTry was correctly executed..."); + + assert_eventually_channel_upgrade_try( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + &old_attrs.flipped(), + )?; + + info!("Check that the channel upgrade successfully upgraded the version..."); + + relayer.with_supervisor(|| { + assert_eventually_channel_upgrade_open( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &upgraded_attrs, + )?; + + Ok(()) + }) + } +} + +pub struct ChannelUpgradeHandshakeFromAck; + +impl TestOverrides for ChannelUpgradeHandshakeFromAck { + fn modify_relayer_config(&self, config: &mut Config) { + config.mode.channels.enabled = true; + } + + fn should_spawn_supervisor(&self) -> bool { + false + } +} + +impl BinaryChannelTest for ChannelUpgradeHandshakeFromAck { + fn run( + &self, + _config: &TestConfig, + relayer: RelayerDriver, + chains: ConnectedChains, + channels: ConnectedChannel, + ) -> Result<(), Error> { + info!("Check that channels are both in OPEN State"); + + assert_eventually_channel_established( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + )?; + + let channel_end_a = chains + .handle_a + .query_channel( + QueryChannelRequest { + port_id: channels.port_a.0.clone(), + channel_id: channels.channel_id_a.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd A: {e}"))?; + + let channel_end_b = chains + .handle_b + .query_channel( + QueryChannelRequest { + port_id: channels.port_b.0.clone(), + channel_id: channels.channel_id_b.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd B: {e}"))?; + + let old_version = channel_end_a.version; + let old_ordering = channel_end_a.ordering; + let old_connection_hops_a = channel_end_a.connection_hops; + let old_connection_hops_b = channel_end_b.connection_hops; + + let channel = channels.channel; + let new_version = Version::ics20_with_fee(); + let new_ordering = None; + let new_connection_hops = None; + + let old_attrs = ChannelUpgradableAttributes::new( + old_version.clone(), + old_version.clone(), + old_ordering, + old_connection_hops_a.clone(), + old_connection_hops_b.clone(), + ); + + let upgraded_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), + new_version.clone(), + old_ordering, + old_connection_hops_a, + old_connection_hops_b, + ); + + info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); + + // Note: Initialising a channel upgrade this way, without requiring a + // signature or proof of authority to perform the channel upgrade, will + // eventually be removed. + // Only authority (gov module or other) will be able to trigger a channel upgrade. + // See: https://github.com/cosmos/ibc-go/issues/4186 + channel.flipped().build_chan_upgrade_init_and_send( + Some(new_version), + new_ordering, + new_connection_hops, + )?; + + info!("Will run ChanUpgradeTry step..."); + + channel.build_chan_upgrade_try_and_send()?; + + info!("Check that the step ChanUpgradeTry was correctly executed..."); + + assert_eventually_channel_upgrade_try( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + &old_attrs.flipped(), + )?; + + info!("Will run ChanUpgradeAck step..."); + + channel.flipped().build_chan_upgrade_ack_and_send()?; + + info!("Check that the step ChanUpgradeAck was correctly executed..."); + + assert_eventually_channel_upgrade_ack( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &old_attrs, + )?; + + info!("Check that the channel upgrade successfully upgraded the version..."); + + relayer.with_supervisor(|| { + assert_eventually_channel_upgrade_open( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &upgraded_attrs, + )?; + + Ok(()) + }) + } +} +pub struct ChannelUpgradeHandshakeFromConfirm; + +impl TestOverrides for ChannelUpgradeHandshakeFromConfirm { + fn modify_relayer_config(&self, config: &mut Config) { + config.mode.channels.enabled = true; + } + + fn should_spawn_supervisor(&self) -> bool { + false + } +} + +impl BinaryChannelTest for ChannelUpgradeHandshakeFromConfirm { + fn run( + &self, + _config: &TestConfig, + relayer: RelayerDriver, + chains: ConnectedChains, + channels: ConnectedChannel, + ) -> Result<(), Error> { + info!("Check that channels are both in OPEN State"); + + assert_eventually_channel_established( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + )?; + + let channel_end_a = chains + .handle_a + .query_channel( + QueryChannelRequest { + port_id: channels.port_a.0.clone(), + channel_id: channels.channel_id_a.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd A: {e}"))?; + + let channel_end_b = chains + .handle_b + .query_channel( + QueryChannelRequest { + port_id: channels.port_b.0.clone(), + channel_id: channels.channel_id_b.0.clone(), + height: QueryHeight::Latest, + }, + IncludeProof::No, + ) + .map(|(channel_end, _)| channel_end) + .map_err(|e| eyre!("Error querying ChannelEnd B: {e}"))?; + + let old_version = channel_end_a.version; + let old_ordering = channel_end_a.ordering; + let old_connection_hops_a = channel_end_a.connection_hops; + let old_connection_hops_b = channel_end_b.connection_hops; + + let channel = channels.channel; + let new_version = Version::ics20_with_fee(); + let new_ordering = None; + let new_connection_hops = None; + + let old_attrs = ChannelUpgradableAttributes::new( + old_version.clone(), + old_version.clone(), + old_ordering, + old_connection_hops_a.clone(), + old_connection_hops_b.clone(), + ); + + let interm_attrs = ChannelUpgradableAttributes::new( + old_version, + new_version.clone(), + old_ordering, + old_connection_hops_a.clone(), + old_connection_hops_b.clone(), + ); + + let upgraded_attrs = ChannelUpgradableAttributes::new( + new_version.clone(), + new_version.clone(), + old_ordering, + old_connection_hops_a, + old_connection_hops_b, + ); + + info!("Will initialise upgrade handshake by sending the ChanUpgradeInit step..."); + + // Note: Initialising a channel upgrade this way, without requiring a + // signature or proof of authority to perform the channel upgrade, will + // eventually be removed. + // Only authority (gov module or other) will be able to trigger a channel upgrade. + // See: https://github.com/cosmos/ibc-go/issues/4186 + channel.flipped().build_chan_upgrade_init_and_send( + Some(new_version), + new_ordering, + new_connection_hops, + )?; + + info!("Will run ChanUpgradeTry step..."); + + channel.build_chan_upgrade_try_and_send()?; + + info!("Check that the step ChanUpgradeTry was correctly executed..."); + + assert_eventually_channel_upgrade_try( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + &old_attrs.flipped(), + )?; + + info!("Will run ChanUpgradeAck step..."); + + channel.flipped().build_chan_upgrade_ack_and_send()?; + + info!("Check that the step ChanUpgradeAck was correctly executed..."); + + assert_eventually_channel_upgrade_ack( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &old_attrs, + )?; + + info!("Will run ChanUpgradeConfirm step..."); + + channel.build_chan_upgrade_confirm_and_send()?; + + info!("Check that the step ChanUpgradeConfirm was correctly executed..."); + + assert_eventually_channel_upgrade_confirm( + &chains.handle_b, + &chains.handle_a, + &channels.channel_id_b.as_ref(), + &channels.port_b.as_ref(), + &interm_attrs.flipped(), + )?; + + info!("Check that the channel upgrade successfully upgraded the version..."); + + relayer.with_supervisor(|| { + assert_eventually_channel_upgrade_open( + &chains.handle_a, + &chains.handle_b, + &channels.channel_id_a.as_ref(), + &channels.port_a.as_ref(), + &upgraded_attrs, + )?; + + Ok(()) + }) + } +} From fa67528518778b88eb7b86bf54a9a2d828ff80c4 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Fri, 13 Oct 2023 13:43:47 +0200 Subject: [PATCH 24/26] Improve less_or_equal method for channel states and add unit tests --- .../src/core/ics04_channel/channel.rs | 150 +++++++++++++++--- crates/relayer/src/channel.rs | 2 +- crates/relayer/src/supervisor/spawn.rs | 4 +- 3 files changed, 133 insertions(+), 23 deletions(-) diff --git a/crates/relayer-types/src/core/ics04_channel/channel.rs b/crates/relayer-types/src/core/ics04_channel/channel.rs index dd748422df..6ae0e8bd58 100644 --- a/crates/relayer-types/src/core/ics04_channel/channel.rs +++ b/crates/relayer-types/src/core/ics04_channel/channel.rs @@ -474,6 +474,7 @@ impl State { /// Returns whether or not the channel with this state /// has progressed less or the same than the argument. + /// This only takes into account the open channel handshake. /// /// # Example /// ```rust,ignore @@ -490,30 +491,22 @@ impl State { Init => !matches!(other, Uninitialized), TryOpen => !matches!(other, Uninitialized | Init), Open(UpgradeState::NotUpgrading) => !matches!(other, Uninitialized | Init | TryOpen), - Open(UpgradeState::Upgrading) => !matches!( - other, - Uninitialized | Init | TryOpen | Open(UpgradeState::NotUpgrading) - ), + _ => false, + } + } - Flushing => !matches!( - other, - Uninitialized - | Init - | TryOpen - | Open(UpgradeState::NotUpgrading) - | Open(UpgradeState::Upgrading) - ), - Flushcomplete => !matches!( + /// Returns whether or not the channel with this state is + /// being upgraded. + pub fn is_upgrading(self, other: Self) -> bool { + use State::*; + + match self { + Open(UpgradeState::NotUpgrading) => matches!( other, - Uninitialized - | Init - | TryOpen - | Open(UpgradeState::NotUpgrading) - | Open(UpgradeState::Upgrading) - | Flushing + Open(UpgradeState::Upgrading) | Flushing | Flushcomplete ), - - Closed => false, + Open(UpgradeState::Upgrading) | Flushing | Flushcomplete => true, + _ => false, } } } @@ -690,4 +683,119 @@ mod tests { } } } + + #[test] + fn less_or_equal_progress_uninitialized() { + use crate::core::ics04_channel::channel::State; + use crate::core::ics04_channel::channel::UpgradeState; + + let higher_or_equal_states = vec![ + State::Uninitialized, + State::Init, + State::TryOpen, + State::Open(UpgradeState::NotUpgrading), + State::Open(UpgradeState::Upgrading), + State::Closed, + State::Flushing, + State::Flushcomplete, + ]; + for state in higher_or_equal_states { + assert!(State::Uninitialized.less_or_equal_progress(state)) + } + } + + #[test] + fn less_or_equal_progress_init() { + use crate::core::ics04_channel::channel::State; + use crate::core::ics04_channel::channel::UpgradeState; + + let lower_states = vec![State::Uninitialized]; + let higher_or_equal_states = vec![ + State::Init, + State::TryOpen, + State::Open(UpgradeState::NotUpgrading), + State::Open(UpgradeState::Upgrading), + State::Closed, + State::Flushing, + State::Flushcomplete, + ]; + for state in lower_states { + assert!(!State::Init.less_or_equal_progress(state)); + } + for state in higher_or_equal_states { + assert!(State::Init.less_or_equal_progress(state)) + } + } + + #[test] + fn less_or_equal_progress_tryopen() { + use crate::core::ics04_channel::channel::State; + use crate::core::ics04_channel::channel::UpgradeState; + + let lower_states = vec![State::Uninitialized, State::Init]; + let higher_or_equal_states = vec![ + State::TryOpen, + State::Open(UpgradeState::NotUpgrading), + State::Open(UpgradeState::Upgrading), + State::Closed, + State::Flushing, + State::Flushcomplete, + ]; + for state in lower_states { + assert!(!State::TryOpen.less_or_equal_progress(state)); + } + for state in higher_or_equal_states { + assert!(State::TryOpen.less_or_equal_progress(state)) + } + } + + #[test] + fn less_or_equal_progress_open_not_upgrading() { + use crate::core::ics04_channel::channel::State; + use crate::core::ics04_channel::channel::UpgradeState; + + let lower_states = vec![State::Uninitialized, State::Init, State::TryOpen]; + let higher_or_equal_states = vec![ + State::Open(UpgradeState::NotUpgrading), + State::Open(UpgradeState::Upgrading), + State::Closed, + State::Flushing, + State::Flushcomplete, + ]; + for state in lower_states { + assert!(!State::Open(UpgradeState::NotUpgrading).less_or_equal_progress(state)); + } + for state in higher_or_equal_states { + assert!(State::Open(UpgradeState::NotUpgrading).less_or_equal_progress(state)) + } + } + + #[test] + fn less_or_equal_progress_upgrading_states() { + use crate::core::ics04_channel::channel::State; + use crate::core::ics04_channel::channel::UpgradeState; + + let states = [ + State::Uninitialized, + State::Init, + State::TryOpen, + State::Open(UpgradeState::NotUpgrading), + State::Open(UpgradeState::Upgrading), + State::Closed, + State::Flushing, + State::Flushcomplete, + ]; + + let upgrading_states = vec![ + State::Open(UpgradeState::Upgrading), + State::Closed, + State::Flushing, + State::Flushcomplete, + ]; + for upgrade_state in upgrading_states { + for state in states.iter() { + assert!(!upgrade_state.less_or_equal_progress(*state)); + } + } + } } diff --git a/crates/relayer/src/channel.rs b/crates/relayer/src/channel.rs index bb851ba4ef..8c46816278 100644 --- a/crates/relayer/src/channel.rs +++ b/crates/relayer/src/channel.rs @@ -793,7 +793,7 @@ impl Channel { (State::Flushcomplete, State::Flushing) => { Some(self.build_chan_upgrade_confirm_and_send()?) } - (State::Open(UpgradeState::Upgrading), State::Flushcomplete) => { + (State::Open(_), State::Flushcomplete) => { Some(self.build_chan_upgrade_open_and_send()?) } diff --git a/crates/relayer/src/supervisor/spawn.rs b/crates/relayer/src/supervisor/spawn.rs index c7ffd2a240..eb5499b272 100644 --- a/crates/relayer/src/supervisor/spawn.rs +++ b/crates/relayer/src/supervisor/spawn.rs @@ -315,6 +315,8 @@ impl<'a, Chain: ChainHandle> SpawnContext<'a, Chain> { let open_handshake = chan_state_dst.less_or_equal_progress(ChannelState::TryOpen) && chan_state_dst.less_or_equal_progress(chan_state_src); + let upgrade_handshake = chan_state_dst.is_upgrading(chan_state_src); + // Determine if close handshake is required, i.e. if channel state on source is `Closed`, // and on destination channel state is not `Closed, and there are no pending packets. // If there are pending packets on destination then we let the packet worker clear the @@ -322,7 +324,7 @@ impl<'a, Chain: ChainHandle> SpawnContext<'a, Chain> { let close_handshake = chan_state_src.is_closed() && !chan_state_dst.is_closed() && !has_packets(); - if open_handshake || close_handshake { + if open_handshake || upgrade_handshake || close_handshake { // create worker for channel handshake that will advance the counterparty state let channel_object = Object::Channel(Channel { dst_chain_id: counterparty_chain.id(), From 7b8ea92a377f8300aeaa35cc4742cfc84d667ff4 Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Fri, 13 Oct 2023 15:56:10 +0200 Subject: [PATCH 25/26] Use automatic link for URL in channel State documentation --- crates/relayer-types/src/core/ics04_channel/channel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/relayer-types/src/core/ics04_channel/channel.rs b/crates/relayer-types/src/core/ics04_channel/channel.rs index 6ae0e8bd58..f30f6714c0 100644 --- a/crates/relayer-types/src/core/ics04_channel/channel.rs +++ b/crates/relayer-types/src/core/ics04_channel/channel.rs @@ -410,7 +410,7 @@ pub enum State { /// During some steps of channel upgrades, the state is still in Open. The /// `UpgradeState` is used to differentiate these states during the upgrade /// handshake. - /// https://github.com/cosmos/ibc/blob/main/spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md#upgrade-handshake + /// Open(UpgradeState), /// A channel has been closed and can no longer be used to send or receive /// packets. From 371a620bacc4abe65d8b3e3712d69cec35cbadbe Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Fri, 13 Oct 2023 16:40:40 +0200 Subject: [PATCH 26/26] Add comment on channel upgrade open assertion --- .../src/tests/channel_upgrade/upgrade_handshake.rs | 3 +++ .../tests/channel_upgrade/upgrade_handshake_steps.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs index 8d0f5ec644..b0e100b422 100644 --- a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs +++ b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake.rs @@ -100,6 +100,9 @@ impl BinaryChannelTest for ChannelUpgradeHandshake { info!("Check that the channel upgrade successfully upgraded the version..."); + // This will assert that both channel ends are eventually + // in Open state, and that the fields targeted by the upgrade + // have been correctly updated. assert_eventually_channel_upgrade_open( &chains.handle_a, &chains.handle_b, diff --git a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs index f775f57f32..6c76d57638 100644 --- a/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs +++ b/tools/integration-test/src/tests/channel_upgrade/upgrade_handshake_steps.rs @@ -198,6 +198,9 @@ impl BinaryChannelTest for ChannelUpgradeManualHandshake { info!("Check that the ChanUpgradeOpen steps were correctly executed..."); + // This will assert that both channel ends are eventually + // in Open state, and that the fields targeted by the upgrade + // have been correctly updated. assert_eventually_channel_upgrade_open( &chains.handle_a, &chains.handle_b, @@ -321,6 +324,9 @@ impl BinaryChannelTest for ChannelUpgradeHandshakeFromTry { info!("Check that the channel upgrade successfully upgraded the version..."); relayer.with_supervisor(|| { + // This will assert that both channel ends are eventually + // in Open state, and that the fields targeted by the upgrade + // have been correctly updated. assert_eventually_channel_upgrade_open( &chains.handle_a, &chains.handle_b, @@ -459,6 +465,9 @@ impl BinaryChannelTest for ChannelUpgradeHandshakeFromAck { info!("Check that the channel upgrade successfully upgraded the version..."); relayer.with_supervisor(|| { + // This will assert that both channel ends are eventually + // in Open state, and that the fields targeted by the upgrade + // have been correctly updated. assert_eventually_channel_upgrade_open( &chains.handle_a, &chains.handle_b, @@ -618,6 +627,9 @@ impl BinaryChannelTest for ChannelUpgradeHandshakeFromConfirm { info!("Check that the channel upgrade successfully upgraded the version..."); relayer.with_supervisor(|| { + // This will assert that both channel ends are eventually + // in Open state, and that the fields targeted by the upgrade + // have been correctly updated. assert_eventually_channel_upgrade_open( &chains.handle_a, &chains.handle_b,