From 5036f68e1a763dea1e39767a8480ee4e8b404b61 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Fri, 16 Feb 2024 14:12:22 +0100 Subject: [PATCH 1/2] Avoid using debug impl in error messages --- .../src/relay/impls/packet_clearers/ack.rs | 4 +++- .../src/relay/impls/packet_clearers/packets.rs | 6 +++++- .../src/relay/impls/packet_clearers/receive_packet.rs | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/relayer/relayer-components/src/relay/impls/packet_clearers/ack.rs b/crates/relayer/relayer-components/src/relay/impls/packet_clearers/ack.rs index 0ee8a19c6..00d2b72f3 100644 --- a/crates/relayer/relayer-components/src/relay/impls/packet_clearers/ack.rs +++ b/crates/relayer/relayer-components/src/relay/impls/packet_clearers/ack.rs @@ -35,6 +35,7 @@ impl Task for RelayPacketTask where Relay: CanRelayAckPacket + CanLog, Relay::Packet: Display, + Relay::Error: Display, Relay::DstChain: HasWriteAckEvent, { async fn run(self) { @@ -44,7 +45,7 @@ where .await { self.relay.log_error(&format!( - "failed to relay packet the packet {} during ack packet clearing: {e:#?}", + "failed to relay packet the packet {} during ack packet clearing: {e}", self.packet )); } @@ -62,6 +63,7 @@ where + CanQueryUnreceivedAcksSequences, Relay::Runtime: CanRunConcurrentTasks, Relay::Packet: Display, + Relay::Error: Display, { async fn clear_packets( relay: &Relay, diff --git a/crates/relayer/relayer-components/src/relay/impls/packet_clearers/packets.rs b/crates/relayer/relayer-components/src/relay/impls/packet_clearers/packets.rs index 01ddcd147..1c7b46201 100644 --- a/crates/relayer/relayer-components/src/relay/impls/packet_clearers/packets.rs +++ b/crates/relayer/relayer-components/src/relay/impls/packet_clearers/packets.rs @@ -1,3 +1,5 @@ +use core::fmt::Display; + use alloc::format; use alloc::vec; @@ -34,6 +36,7 @@ where impl Task for RunPacketClearer where Relay: HasRelayChains + CanLog, + Relay::Error: Display, ClearReceivePackets: PacketClearer, ClearAckPackets: PacketClearer, { @@ -62,7 +65,7 @@ where }; if let Err(e) = result { self.relay - .log_error(&format!("failed during packet clearing: {e:#?}")); + .log_error(&format!("failed during packet clearing: {e}")); } } } @@ -70,6 +73,7 @@ where impl PacketClearer for ClearAllPackets where Relay: Clone + HasRuntime + HasRelayChains + CanLog, + Relay::Error: Display, SrcChain: HasIbcChainTypes, DstChain: HasIbcChainTypes, Relay::Runtime: CanRunConcurrentTasks, diff --git a/crates/relayer/relayer-components/src/relay/impls/packet_clearers/receive_packet.rs b/crates/relayer/relayer-components/src/relay/impls/packet_clearers/receive_packet.rs index e642969f0..c22591fb6 100644 --- a/crates/relayer/relayer-components/src/relay/impls/packet_clearers/receive_packet.rs +++ b/crates/relayer/relayer-components/src/relay/impls/packet_clearers/receive_packet.rs @@ -28,11 +28,12 @@ impl Task for RelayPacketTask where Relay: CanRelayPacket + CanLog, Relay::Packet: Display, + Relay::Error: Display, { async fn run(self) { if let Err(e) = self.relay.relay_packet(&self.packet).await { self.relay.log_error(&format!( - "failed to relay packet the packet {} during recv packet clearing: {e:#?}", + "failed to relay packet the packet {} during recv packet clearing: {e}", self.packet )); } @@ -48,6 +49,7 @@ where CanQueryPacketCommitments + CanQuerySendPackets, Relay::Runtime: CanRunConcurrentTasks, Relay::Packet: Display, + Relay::Error: Display, { async fn clear_packets( relay: &Relay, From d77999dbc6033b4771a69f40dab5b326561a124a Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Fri, 16 Feb 2024 14:18:39 +0100 Subject: [PATCH 2/2] Report error yielded by packet clearing tasks --- crates/cli/cli/Cargo.toml | 2 +- crates/cli/cli/src/commands/clear/packets.rs | 57 ++++++++++++-------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/crates/cli/cli/Cargo.toml b/crates/cli/cli/Cargo.toml index 0fde20184..760f4abbc 100644 --- a/crates/cli/cli/Cargo.toml +++ b/crates/cli/cli/Cargo.toml @@ -34,4 +34,4 @@ humantime = { workspace = true } tracing = { workspace = true } serde_json = { workspace = true } futures = { workspace = true } -serde = { workspace = true, features = ["derive"] } \ No newline at end of file +serde = { workspace = true, features = ["derive"] } diff --git a/crates/cli/cli/src/commands/clear/packets.rs b/crates/cli/cli/src/commands/clear/packets.rs index 0c190d6b8..84a9433c5 100644 --- a/crates/cli/cli/src/commands/clear/packets.rs +++ b/crates/cli/cli/src/commands/clear/packets.rs @@ -2,13 +2,13 @@ use hermes_cli_framework::command::CommandRunner; use hermes_cli_framework::output::Output; use hermes_cosmos_relayer::contexts::builder::CosmosBuilder; -use futures::stream::{self, StreamExt}; use hermes_relayer_components::build::traits::components::birelay_builder::CanBuildBiRelay; use hermes_relayer_components::relay::traits::packet_clearer::CanClearPackets; use ibc_relayer_types::core::ics24_host::identifier::ChainId; use ibc_relayer_types::core::ics24_host::identifier::ChannelId; use ibc_relayer_types::core::ics24_host::identifier::ClientId; use ibc_relayer_types::core::ics24_host::identifier::PortId; +use tracing::error; use crate::Result; @@ -99,25 +99,40 @@ impl CommandRunner for PacketsClear { ) .await?; - stream::iter(vec![ - relayer.relay_a_to_b.clear_packets( - &self.channel_id, - &self.port_id, - &self.counterparty_channel_id, - &self.counterparty_port_id, - ), - relayer.relay_b_to_a.clear_packets( - &self.counterparty_channel_id, - &self.counterparty_port_id, - &self.channel_id, - &self.port_id, - ), - ]) - .for_each_concurrent(None, |x| async { - let _ = x.await; - }) - .await; - - Ok(Output::success("Packet clear")) + let task_a_to_b = relayer.relay_a_to_b.clear_packets( + &self.channel_id, + &self.port_id, + &self.counterparty_channel_id, + &self.counterparty_port_id, + ); + + let task_b_to_a = relayer.relay_b_to_a.clear_packets( + &self.counterparty_channel_id, + &self.counterparty_port_id, + &self.channel_id, + &self.port_id, + ); + + let (result_a_to_b, result_b_to_a) = futures::join!(task_a_to_b, task_b_to_a); + + if let Err(e) = &result_a_to_b { + error!( + "failed to clear packets from `{}` to `{}`: {e}", + self.chain_id, self.counterparty_port_id + ); + } + + if let Err(e) = &result_b_to_a { + error!( + "failed to clear packets from `{}` to `{}`: {e}", + self.counterparty_port_id, self.chain_id + ); + } + + if result_a_to_b.is_err() || result_b_to_a.is_err() { + Ok(Output::error("failed to clear packets")) + } else { + Ok(Output::success_msg("successfully cleared packets")) + } } }