-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
query packet pending
command (#2096)
* relayer: typo in packet_acknowledgements * cli: Remove an unused struct un unreceived_packets * First crack at `packet pending` cmd * relayer: Optimize pending_packet_summary Don't query the set of commitments on the counterparty chain twice. To achieve this, simplify the low-level functions in chain::counterparty by accepting previously obtained commitment sets rather than querying everything inside each function. * Skip the unreceived acks query on empty ack set Do the same optimization to unreceived_acknowledgements_sequences as the one done in unreceived_packets_sequences. * Swap the directions in pending_packet_summary * Initial test of pending_packet_summary Only tests the unreceived packets. * test framework: impl Copy for Tagged * test-framework: Add query_identified_channel_end * testf-framework: conversion from LinkError * Minimal test of pending_packet_summary * test-framework: query_identified_connection_end * query the reverse channel in pending packet test * Changelog entry for #2096 * Renamed local vars for ChannelConnectionClient * Rename fields in output of `query packet pending` * tests: No override of channel order in query_packet * Renamed PacketSummary members * Fix clippy warnings Co-authored-by: Romain Ruetschi <[email protected]>
- Loading branch information
Showing
16 changed files
with
436 additions
and
132 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.changelog/unreleased/improvements/2096-query-packet-pending.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- Added `query packet pending` command to list outstanding packet | ||
commitments that are either unreceived or pending acknowledgement | ||
at both ends of a channel. | ||
([#1862](https://github.com/informalsystems/ibc-rs/issues/1862)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use abscissa_core::clap::Parser; | ||
use abscissa_core::{Command, Runnable}; | ||
use serde::Serialize; | ||
|
||
use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; | ||
use ibc_relayer::chain::counterparty::{ | ||
channel_on_destination, pending_packet_summary, PendingPackets, | ||
}; | ||
use ibc_relayer::chain::handle::BaseChainHandle; | ||
|
||
use crate::cli_utils::spawn_chain_counterparty; | ||
use crate::conclude::Output; | ||
use crate::error::Error; | ||
use crate::prelude::*; | ||
|
||
/// A structure to display pending packet commitment sequence IDs | ||
/// at both ends of a channel. | ||
#[derive(Debug, Serialize)] | ||
struct Summary { | ||
/// The packets sent on the source chain as identified by the command. | ||
src: PendingPackets, | ||
/// The packets sent on the counterparty chain. | ||
dst: PendingPackets, | ||
} | ||
|
||
/// This command does the following: | ||
/// | ||
/// 1. queries the chain to get its counterparty chain, channel and port identifiers (needed in 2) | ||
/// 2. queries both chains for all packet commitments/ sequences for the given port and channel | ||
/// and its counterparty. | ||
/// 3. queries both chains for the unreceived sequences and acks out of the lists obtained in 2. | ||
#[derive(Clone, Command, Debug, Parser)] | ||
pub struct QueryPendingPacketsCmd { | ||
#[clap( | ||
required = true, | ||
help = "identifier of the chain at one end of the channel" | ||
)] | ||
chain_id: ChainId, | ||
|
||
#[clap( | ||
required = true, | ||
help = "port identifier on the chain given by <CHAIN_ID>" | ||
)] | ||
port_id: PortId, | ||
|
||
#[clap( | ||
required = true, | ||
help = "channel identifier on the chain given by <CHAIN_ID>" | ||
)] | ||
channel_id: ChannelId, | ||
} | ||
|
||
impl QueryPendingPacketsCmd { | ||
fn execute(&self) -> Result<Summary, Error> { | ||
let config = app_config(); | ||
|
||
let (chains, chan_conn_cli) = spawn_chain_counterparty::<BaseChainHandle>( | ||
&config, | ||
&self.chain_id, | ||
&self.port_id, | ||
&self.channel_id, | ||
)?; | ||
|
||
debug!( | ||
chain=%self.chain_id, | ||
"fetched channel from source chain: {:?}", | ||
chan_conn_cli.channel | ||
); | ||
|
||
let src_summary = pending_packet_summary(&chains.src, &chains.dst, &chan_conn_cli.channel) | ||
.map_err(Error::supervisor)?; | ||
let counterparty_channel = channel_on_destination( | ||
&chan_conn_cli.channel, | ||
&chan_conn_cli.connection, | ||
&chains.dst, | ||
) | ||
.map_err(Error::supervisor)? | ||
.ok_or_else(|| Error::missing_counterparty_channel_id(chan_conn_cli.channel))?; | ||
let dst_summary = pending_packet_summary(&chains.dst, &chains.src, &counterparty_channel) | ||
.map_err(Error::supervisor)?; | ||
Ok(Summary { | ||
src: src_summary, | ||
dst: dst_summary, | ||
}) | ||
} | ||
} | ||
|
||
impl Runnable for QueryPendingPacketsCmd { | ||
fn run(&self) { | ||
match self.execute() { | ||
Ok(pending) => Output::success(pending).exit(), | ||
Err(e) => Output::error(format!("{}", e)).exit(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.