Skip to content

Commit

Permalink
Implement ability to select specific wallet for packet clearing CLI (#…
Browse files Browse the repository at this point in the history
…2252)

* Pull in upstream changes

* Add `-k` key flag to clear packets command

* Implement Override<Config> for ClearPacketsCmd

* Add changelog entry

* Update guide

* Remove unnecessary import

* Remove short flag option

* Add clap option for `counterparty_key_name` flag

* Attempting to fetch counterparty chain config

* Overwrite dst chain's `key_name` in clear packet flow

* Change a word in a comment

* Make language in guide consistent with CLI output

* Update ADR 010 to reflect changes to `clear packet` command

Co-authored-by: Romain Ruetschi <romain@informal.systems>
  • Loading branch information
seanchen1991 and romac authored Jun 29, 2022
1 parent b382eb3 commit 3cb297e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add support for selecting a specific wallet in the `clear packets` CLI flow ([#2111](https://github.com/informalsystems/ibc-rs/issues/2111))
5 changes: 3 additions & 2 deletions docs/architecture/adr-010-unified-cli-arguments-hermes.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ The following commands are implemented, with the binary name `hermes` often omit

### Clear packets

* `clear packets --chain <CHAIN_ID> --port <PORT_ID> --channel <CHANNEL_ID>`
* `clear packets --chain <CHAIN_ID> --port <PORT_ID> --channel <CHANNEL_ID>
--key-name <KEY> --counterparty-key-name <KEY>`

### Queries

Expand Down Expand Up @@ -195,4 +196,4 @@ The PR which updates the flags for all the commands as described in this ADR: [#

## References

* Proposal in issue: [#2239](https://github.com/informalsystems/ibc-rs/issues/2239)
* Proposal in issue: [#2239](https://github.com/informalsystems/ibc-rs/issues/2239)
12 changes: 8 additions & 4 deletions guide/src/commands/relaying/clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ DESCRIPTION:
The channel is identified by the chain, port, and channel IDs at one of its ends
OPTIONS:
-h, --help Print help information
FLAGS:
--chain <CHAIN_ID> Identifier of the chain
--channel <CHANNEL_ID> Identifier of the channel
--port <PORT_ID> Identifier of the port
--chain <CHAIN_ID> Identifier of the chain
--channel <CHANNEL_ID> Identifier of the channel
--port <PORT_ID> Identifier of the port
--key-name <KEY> Use the given signing key for the specified chain (default: `key_name` config)
--counterparty-key-name <KEY> Use the given signing key for the counterparty chain (default: `key_name` config)
```

### Example
Expand Down Expand Up @@ -437,4 +442,3 @@ Success: [
2022-02-24T14:21:28.874190Z INFO ThreadId(01) using default configuration from '/Users/coromac/.hermes/config.toml'
Success: []
```

48 changes: 45 additions & 3 deletions relayer-cli/src/commands/clear.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use abscissa_core::clap::Parser;
use abscissa_core::{Command, Runnable};
use abscissa_core::config::Override;
use abscissa_core::{Command, FrameworkErrorKind, Runnable};

use ibc::core::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc::events::IbcEvent;
use ibc_relayer::chain::handle::BaseChainHandle;
use ibc_relayer::chain::handle::{BaseChainHandle, ChainHandle};
use ibc_relayer::config::Config;
use ibc_relayer::link::error::LinkError;
use ibc_relayer::link::{Link, LinkParameters};

Expand All @@ -21,7 +23,7 @@ pub enum ClearCmds {
Packets(ClearPacketsCmd),
}

#[derive(Debug, Parser)]
#[derive(Debug, Parser, Command)]
pub struct ClearPacketsCmd {
#[clap(
long = "chain",
Expand All @@ -47,6 +49,35 @@ pub struct ClearPacketsCmd {
help = "Identifier of the channel"
)]
channel_id: ChannelId,

#[clap(
long,
help = "use the given signing key for the specified chain (default: `key_name` config)"
)]
key_name: Option<String>,

#[clap(
long,
help = "use the given signing key for the counterparty chain (default: `counterparty_key_name` config)"
)]
counterparty_key_name: Option<String>,
}

impl Override<Config> for ClearPacketsCmd {
fn override_config(&self, mut config: Config) -> Result<Config, abscissa_core::FrameworkError> {
let chain_config = config.find_chain_mut(&self.chain_id).ok_or_else(|| {
FrameworkErrorKind::ComponentError.context(format!(
"missing configuration for chain '{}'",
self.chain_id
))
})?;

if let Some(ref key_name) = self.key_name {
chain_config.key_name = key_name.to_string();
}

Ok(config)
}
}

impl Runnable for ClearPacketsCmd {
Expand All @@ -63,6 +94,17 @@ impl Runnable for ClearPacketsCmd {
Err(e) => Output::error(format!("{}", e)).exit(),
};

// If `counterparty_key_name` is provided, fetch the counterparty chain's
// config and overwrite its `key_name` parameter
if let Some(ref counterparty_key_name) = self.counterparty_key_name {
match chains.dst.config() {
Ok(mut dst_chain_cfg) => {
dst_chain_cfg.key_name = counterparty_key_name.to_string();
}
Err(e) => Output::error(format!("{}", e)).exit(),
}
}

let mut ev_list = vec![];

// Construct links in both directions.
Expand Down

0 comments on commit 3cb297e

Please sign in to comment.