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

Implement clear packets command #1834

Merged
merged 17 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! See the `impl Configurable` below for how to specify the path to the
//! application's configuration file.

mod clear;
mod completions;
mod config;
mod create;
Expand All @@ -20,9 +21,10 @@ mod upgrade;
mod version;

use self::{
completions::CompletionsCmd, config::ConfigCmd, create::CreateCmds, health::HealthCheckCmd,
keys::KeysCmd, listen::ListenCmd, misbehaviour::MisbehaviourCmd, query::QueryCmd,
start::StartCmd, tx::TxCmd, update::UpdateCmds, upgrade::UpgradeCmds, version::VersionCmd,
clear::ClearCmds, completions::CompletionsCmd, config::ConfigCmd, create::CreateCmds,
health::HealthCheckCmd, keys::KeysCmd, listen::ListenCmd, misbehaviour::MisbehaviourCmd,
query::QueryCmd, start::StartCmd, tx::TxCmd, update::UpdateCmds, upgrade::UpgradeCmds,
version::VersionCmd,
};

use core::time::Duration;
Expand Down Expand Up @@ -63,6 +65,10 @@ pub enum CliCmd {
#[clap(subcommand)]
Upgrade(UpgradeCmds),

/// Clear entities (e.g. packets) on chains
romac marked this conversation as resolved.
Show resolved Hide resolved
#[clap(subcommand)]
Clear(ClearCmds),

/// Start the relayer in multi-chain mode.
///
/// Relays packets and open handshake messages between all chains in the config.
Expand Down
70 changes: 70 additions & 0 deletions relayer-cli/src/commands/clear.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use abscissa_core::clap::Parser;
use abscissa_core::{Command, Runnable};

use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc_relayer::link::{Link, LinkParameters};

use crate::application::app_config;
use crate::cli_utils::ChainHandlePair;
use crate::conclude::Output;
use crate::error::Error;

/// `clear` subcommands
#[derive(Command, Debug, Parser, Runnable)]
pub enum ClearCmds {
/// Clears all packets on the identified path
Packets(ClearPacketsCmd),
}

#[derive(Debug, Parser)]
pub struct ClearPacketsCmd {
#[clap(required = true, help = "identifier of the destination chain")]
dst_chain_id: ChainId,

#[clap(required = true, help = "identifier of the source chain")]
src_chain_id: ChainId,

#[clap(required = true, help = "identifier of the source port")]
src_port_id: PortId,

#[clap(required = true, help = "identifier of the source channel")]
src_channel_id: ChannelId,
}
ancazamfir marked this conversation as resolved.
Show resolved Hide resolved

impl Runnable for ClearPacketsCmd {
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) => return Output::error(format!("{}", e)).exit(),
mzabaluev marked this conversation as resolved.
Show resolved Hide resolved
};

let opts = LinkParameters {
src_port_id: self.src_port_id.clone(),
src_channel_id: self.src_channel_id.clone(),
};
let link = match Link::new_from_opts(chains.src, chains.dst, opts, false) {
Ok(link) => link,
Err(e) => return Output::error(format!("{}", e)).exit(),
};

let mut ev = match link
.build_and_send_recv_packet_messages()
.map_err(Error::link)
{
Ok(ev) => ev,
Err(e) => return Output::error(format!("{}", e)).exit(),
};

match link
.build_and_send_ack_packet_messages()
.map_err(Error::link)
{
Ok(mut ev1) => ev.append(&mut ev1),
adizere marked this conversation as resolved.
Show resolved Hide resolved
Err(e) => return Output::error(format!("{}", e)).exit(),
};

Output::success(ev).exit()
}
}
4 changes: 2 additions & 2 deletions relayer-cli/src/commands/tx/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Runnable for TxRawPacketRecvCmd {
src_port_id: self.src_port_id.clone(),
src_channel_id: self.src_channel_id.clone(),
};
let mut link = match Link::new_from_opts(chains.src, chains.dst, opts, false) {
let link = match Link::new_from_opts(chains.src, chains.dst, opts, false) {
Ok(link) => link,
Err(e) => return Output::error(format!("{}", e)).exit(),
};
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Runnable for TxRawPacketAckCmd {
src_port_id: self.src_port_id.clone(),
src_channel_id: self.src_channel_id.clone(),
};
let mut link = match Link::new_from_opts(chains.src, chains.dst, opts, false) {
let link = match Link::new_from_opts(chains.src, chains.dst, opts, false) {
Ok(link) => link,
Err(e) => return Output::error(format!("{}", e)).exit(),
};
Expand Down
4 changes: 2 additions & 2 deletions relayer/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Link<ChainA, ChainB> {
}

/// Implements the `packet-recv` CLI
pub fn build_and_send_recv_packet_messages(&mut self) -> Result<Vec<IbcEvent>, LinkError> {
adizere marked this conversation as resolved.
Show resolved Hide resolved
pub fn build_and_send_recv_packet_messages(&self) -> Result<Vec<IbcEvent>, LinkError> {
let _span = error_span!(
"PacketRecvCmd",
src_chain = %self.a_to_b.src_chain().id(),
Expand All @@ -189,7 +189,7 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Link<ChainA, ChainB> {
}

/// Implements the `packet-ack` CLI
pub fn build_and_send_ack_packet_messages(&mut self) -> Result<Vec<IbcEvent>, LinkError> {
pub fn build_and_send_ack_packet_messages(&self) -> Result<Vec<IbcEvent>, LinkError> {
let _span = error_span!(
"PacketAckCmd",
src_chain = %self.a_to_b.src_chain().id(),
Expand Down