Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve error reporting in clear packets #180

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cli/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ humantime = { workspace = true }
tracing = { workspace = true }
serde_json = { workspace = true }
futures = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
57 changes: 36 additions & 21 deletions crates/cli/cli/src/commands/clear/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -99,25 +99,40 @@ impl CommandRunner<CosmosBuilder> 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"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl<Relay> Task for RelayPacketTask<Relay>
where
Relay: CanRelayAckPacket + CanLog,
Relay::Packet: Display,
Relay::Error: Display,
Relay::DstChain: HasWriteAckEvent<Relay::SrcChain>,
{
async fn run(self) {
Expand All @@ -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
));
}
Expand All @@ -62,6 +63,7 @@ where
+ CanQueryUnreceivedAcksSequences<Relay::DstChain>,
Relay::Runtime: CanRunConcurrentTasks,
Relay::Packet: Display,
Relay::Error: Display,
{
async fn clear_packets(
relay: &Relay,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::Display;

use alloc::format;
use alloc::vec;

Expand Down Expand Up @@ -34,6 +36,7 @@ where
impl<Relay> Task for RunPacketClearer<Relay>
where
Relay: HasRelayChains + CanLog,
Relay::Error: Display,
ClearReceivePackets: PacketClearer<Relay>,
ClearAckPackets: PacketClearer<Relay>,
{
Expand Down Expand Up @@ -62,14 +65,15 @@ where
};
if let Err(e) = result {
self.relay
.log_error(&format!("failed during packet clearing: {e:#?}"));
.log_error(&format!("failed during packet clearing: {e}"));
}
}
}

impl<Relay, SrcChain, DstChain> PacketClearer<Relay> for ClearAllPackets
where
Relay: Clone + HasRuntime + HasRelayChains<SrcChain = SrcChain, DstChain = DstChain> + CanLog,
Relay::Error: Display,
SrcChain: HasIbcChainTypes<DstChain>,
DstChain: HasIbcChainTypes<SrcChain>,
Relay::Runtime: CanRunConcurrentTasks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ impl<Relay> Task for RelayPacketTask<Relay>
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
));
}
Expand All @@ -48,6 +49,7 @@ where
CanQueryPacketCommitments<Relay::DstChain> + CanQuerySendPackets<Relay::DstChain>,
Relay::Runtime: CanRunConcurrentTasks,
Relay::Packet: Display,
Relay::Error: Display,
{
async fn clear_packets(
relay: &Relay,
Expand Down
Loading