Skip to content

Commit

Permalink
Spike for parallel relaying between multiple channels (informalsystem…
Browse files Browse the repository at this point in the history
…s#692)

* Spike for parallel relaying between multiple channels

* Adjust event heights

* Re-use existing Link infra for relaying packets

* Formatting

* Use only source chain, channel and port to identify packets

* Force use of in-memory store

* Fix computation of UnidrectionalChannelPath for WriteAck

* Run two supervisors in parallel

* Relay in both directions with a single supervisor

* Revert "Force use of in-memory store"

This reverts commit b197537.

* Move supervisor into ibc-relayer crate

* Formatting

* Remove println statements

* Formatting
  • Loading branch information
romac authored Mar 3, 2021
1 parent 31a59e8 commit d2d16fa
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 73 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions relayer-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ hex = "0.4"
crossbeam-channel = "0.5.0"
subtle-encoding = "0.5"
dirs-next = "2.0.0"
itertools = "0.10.0"

[dependencies.tendermint-proto]
version = "=0.18.1"
Expand Down
7 changes: 6 additions & 1 deletion relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::config::Config;

use self::{
create::CreateCmds, keys::KeysCmd, light::LightCmd, listen::ListenCmd, query::QueryCmd,
start::StartCmd, tx::TxCmd, version::VersionCmd,
start::StartCmd, start_multi::StartMultiCmd, tx::TxCmd, version::VersionCmd,
};

mod channel;
Expand All @@ -26,6 +26,7 @@ mod light;
mod listen;
mod query;
mod start;
mod start_multi;
mod tx;
mod version;

Expand Down Expand Up @@ -62,6 +63,10 @@ pub enum CliCmd {
#[options(help = "Start the relayer")]
Start(StartCmd),

/// The `start-multi` subcommand
#[options(help = "Start the relayer in multi-channel mode")]
StartMulti(StartMultiCmd),

/// The `channel` subcommand
#[options(help = "Channel functionality for managing channels")]
Channel(ChannelCmds),
Expand Down
8 changes: 5 additions & 3 deletions relayer-cli/src/commands/cli_utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use abscissa_core::config;

use ibc::ics24_host::identifier::ChainId;
use ibc_relayer::chain::CosmosSdkChain;
use ibc_relayer::{chain::handle::ChainHandle, config::StoreConfig};
use ibc_relayer::{chain::runtime::ChainRuntime, config::ChainConfig};

use crate::application::CliApp;
use crate::error::{Error, Kind};
use crate::{
application::CliApp,
error::{Error, Kind},
};

#[derive(Clone, Debug)]
/// Pair of chain handles that are used by most CLIs.
pub struct ChainHandlePair {
/// Source chain handle
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Runnable for StartCmd {
match channel_relay(
chains.src,
chains.dst,
&LinkParameters {
LinkParameters {
src_port_id: src_port_id.clone(),
src_channel_id: src_channel_id.clone(),
},
Expand Down
40 changes: 40 additions & 0 deletions relayer-cli/src/commands/start_multi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use abscissa_core::{config, Command, Options, Runnable};

use ibc::ics24_host::identifier::ChainId;
use ibc_relayer::supervisor::Supervisor;

use crate::conclude::Output;
use crate::prelude::*;
use crate::{application::CliApp, commands::cli_utils::ChainHandlePair};

#[derive(Clone, Command, Debug, Options)]
pub struct StartMultiCmd {
#[options(free, required, help = "identifier of the source chain")]
src_chain_id: ChainId,

#[options(free, required, help = "identifier of the destination chain")]
dst_chain_id: ChainId,
}

impl Runnable for StartMultiCmd {
fn run(&self) {
let config = app_config();

match start_multi(&config, &self.src_chain_id, &self.dst_chain_id) {
Ok(output) => output.exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}

fn start_multi(
config: &config::Reader<CliApp>,
chain_a: &ChainId,
chain_b: &ChainId,
) -> Result<Output, BoxError> {
let chains = ChainHandlePair::spawn(config, chain_a, chain_b)?;
let supervisor = Supervisor::spawn(chains.src, chains.dst)?;
supervisor.run()?;

Ok(Output::success("ok"))
}
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 @@ -44,7 +44,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) {
let mut link = match Link::new_from_opts(chains.src, chains.dst, opts) {
Ok(link) => link,
Err(e) => return Output::error(format!("{}", e)).exit(),
};
Expand Down Expand Up @@ -94,7 +94,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) {
let mut link = match Link::new_from_opts(chains.src, chains.dst, opts) {
Ok(link) => link,
Err(e) => return Output::error(format!("{}", e)).exit(),
};
Expand Down
1 change: 1 addition & 0 deletions relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ pub mod light_client;
pub mod link;
pub mod macros;
pub mod relay;
pub mod supervisor;
pub mod transfer;
pub mod util;
Loading

0 comments on commit d2d16fa

Please sign in to comment.