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

Relay on all paths defined in the configuration #742

Merged
merged 22 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Proposed ADR 006 to describe Hermes v0.2.0 use-cases ([#637])
- Added `client-upgrade` CLI ([#357])
- Update gaia to version 4.1.0 for e2e tests on CI ([#702])
- Add `start-multi` command to relay on all paths defined in the configuration ([#748])

### IMPROVEMENTS

Expand Down Expand Up @@ -81,6 +82,7 @@
[#734]: https://github.com/informalsystems/ibc-rs/issues/734
[#736]: https://github.com/informalsystems/ibc-rs/issues/736
[#740]: https://github.com/informalsystems/ibc-rs/issues/740
[#748]: https://github.com/informalsystems/ibc-rs/issues/748
[#752]: https://github.com/informalsystems/ibc-rs/issues/752
[#754]: https://github.com/informalsystems/ibc-rs/issues/754
[#761]: https://github.com/informalsystems/ibc-rs/issues/761
Expand Down
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.

2 changes: 1 addition & 1 deletion modules/src/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct ConnectionEnd {
client_id: ClientId,
counterparty: Counterparty,
versions: Vec<Version>,
pub(crate) delay_period: u64,
delay_period: u64,
}

impl Default for ConnectionEnd {
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) fn process(
ctx.commitment_prefix(), // Local commitment prefix.
),
vec![msg.version().clone()],
new_conn_end.delay_period,
new_conn_end.delay_period(),
);

// 2. Pass the details to the verification function.
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(crate) fn process(
ctx.commitment_prefix(), // Local commitment prefix.
),
new_conn_end.versions(),
new_conn_end.delay_period,
new_conn_end.delay_period(),
);

// 2. Pass the details to the verification function.
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) fn process(
if old_connection_end.state_matches(&State::Init)
&& old_connection_end.counterparty_matches(&msg.counterparty())
&& old_connection_end.client_id_matches(msg.client_id())
&& old_connection_end.delay_period == msg.delay_period
&& old_connection_end.delay_period() == msg.delay_period
{
// A ConnectionEnd already exists and all validation passed.
output.log(format!(
Expand Down
5 changes: 5 additions & 0 deletions modules/src/ics04_channel/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,27 @@ impl CloseInit {
pub fn port_id(&self) -> &PortId {
&self.0.port_id
}

pub fn channel_id(&self) -> &ChannelId {
// FIXME(romac): Rework encoding of IbcEvents which use `Attributes`
self.0
.channel_id
.as_ref()
.expect("CloseInit should always have a channel_id")
}

pub fn counterparty_port_id(&self) -> &PortId {
&self.0.counterparty_port_id
}

pub fn counterparty_channel_id(&self) -> Option<&ChannelId> {
self.0.counterparty_channel_id.as_ref()
}

pub fn height(&self) -> Height {
self.0.height
}

pub fn set_height(&mut self, height: Height) {
self.0.height = height;
}
Expand Down
1 change: 1 addition & 0 deletions relayer-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ crossbeam-channel = "0.5.0"
subtle-encoding = "0.5"
dirs-next = "2.0.0"
itertools = "0.10.0"
crossbeam-utils = "0.8.3"

[dependencies.tendermint-proto]
version = "=0.18.1"
Expand Down
4 changes: 2 additions & 2 deletions relayer-cli/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ impl Application for CliApp {
.transpose()?
.unwrap_or_default();

// For `start` cmd exclusively we disable JSON; otherwise output is JSON-only
// For `start` and `start-multi` commands exclusively we disable JSON; otherwise output is JSON-only
let json_on = if let Some(c) = &command.command {
!matches!(c, CliCmd::Start(..))
!matches!(c, CliCmd::Start(_) | CliCmd::StartMulti(_))
} else {
true
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use abscissa_core::config;
use ibc::ics24_host::identifier::ChainId;
use ibc_relayer::chain::runtime::ChainRuntime;
use ibc_relayer::chain::CosmosSdkChain;
use ibc_relayer::{chain::handle::ChainHandle, config::StoreConfig};
use ibc_relayer::{chain::runtime::ChainRuntime, config::ChainConfig};
use ibc_relayer::config::{ChainConfig, StoreConfig};
use ibc_relayer::{chain::handle::ChainHandle, config::Config};

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

#[derive(Clone, Debug)]
/// Pair of chain handles that are used by most CLIs.
Expand All @@ -22,7 +19,7 @@ impl ChainHandlePair {
/// Spawn the source and destination chain runtime from the configuration and chain identifiers,
/// and return the pair of associated handles.
pub fn spawn(
config: &config::Reader<CliApp>,
config: &Config,
src_chain_id: &ChainId,
dst_chain_id: &ChainId,
) -> Result<Self, Error> {
Expand All @@ -34,7 +31,7 @@ impl ChainHandlePair {
/// is used to override each chain configuration before spawning its runtime.
pub fn spawn_with(
options: SpawnOptions,
config: &config::Reader<CliApp>,
config: &Config,
src_chain_id: &ChainId,
dst_chain_id: &ChainId,
) -> Result<Self, Error> {
Expand All @@ -49,7 +46,7 @@ impl ChainHandlePair {
/// Returns the corresponding handle if successful.
pub fn spawn_chain_runtime(
spawn_options: SpawnOptions,
config: &config::Reader<CliApp>,
config: &Config,
chain_id: &ChainId,
) -> Result<Box<dyn ChainHandle>, Error> {
let mut chain_config = config
Expand Down
4 changes: 2 additions & 2 deletions relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use self::{
version::VersionCmd,
};

mod cli_utils;
mod config;
mod create;
mod keys;
Expand Down Expand Up @@ -70,7 +69,8 @@ pub enum CliCmd {
Start(StartCmd),

/// The `start-multi` subcommand
#[options(help = "Start the relayer in multi-channel mode")]
#[options(help = "Start the relayer in multi-channel mode. \
Omit the options to pick up connections from the configuration.")]
StartMulti(StartMultiCmd),

/// The `query` subcommand
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/create/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ibc_relayer::config::StoreConfig;
use ibc_relayer::connection::Connection;
use ibc_relayer::foreign_client::ForeignClient;

use crate::commands::cli_utils::{spawn_chain_runtime, ChainHandlePair, SpawnOptions};
use crate::cli_utils::{spawn_chain_runtime, ChainHandlePair, SpawnOptions};
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/create/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ibc_relayer::config::StoreConfig;
use ibc_relayer::connection::Connection;
use ibc_relayer::foreign_client::ForeignClient;

use crate::commands::cli_utils::{spawn_chain_runtime, ChainHandlePair, SpawnOptions};
use crate::cli_utils::{spawn_chain_runtime, ChainHandlePair, SpawnOptions};
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::prelude::*;

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 @@ -5,7 +5,7 @@ use ibc::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc_relayer::link::LinkParameters;
use ibc_relayer::relay::{channel_relay, relay_on_new_link};

use crate::commands::cli_utils::ChainHandlePair;
use crate::cli_utils::ChainHandlePair;
use crate::conclude::Output;
use crate::prelude::*;

Expand Down
93 changes: 79 additions & 14 deletions relayer-cli/src/commands/start_multi.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,105 @@
use abscissa_core::{config, Command, Options, Runnable};
use abscissa_core::{Command, Options, Runnable};

use ibc::ics24_host::identifier::ChainId;
use ibc_relayer::supervisor::Supervisor;
use ibc_relayer::{config::Config, supervisor::Supervisor};

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

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

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

enum Opts<'a> {
AllConnections,
Specified(&'a ChainId, &'a ChainId),
}

impl StartMultiCmd {
fn validate_options(&self) -> Result<Opts<'_>, BoxError> {
match (&self.chain_a, &self.chain_b) {
(Some(chain_a), Some(chain_b)) => Ok(Opts::Specified(chain_a, chain_b)),
(None, None) => Ok(Opts::AllConnections),
_ => Err("invalid options: please specify both chain identifiers \
or none at all to use the connections defined in the configuration"
.into()),
}
}

fn cmd(&self) -> Result<Output, BoxError> {
let options = self.validate_options()?;
let config = &*app_config();

match options {
Opts::Specified(chain_a, chain_b) => start_specified(config, chain_a, chain_b),
Opts::AllConnections => start_all_connections(config),
}
}
}

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

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

fn start_multi(
config: &config::Reader<CliApp>,
fn start_specified(
config: &Config,
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)?;
info!("spawning supervisor for chains {} and {}", chain_a, chain_b);

let mut registry = Registry::new(&config);
let chain_a = registry.get_or_spawn(chain_a)?;
let chain_b = registry.get_or_spawn(chain_b)?;

let supervisor = Supervisor::spawn(chain_a, chain_b)?;
supervisor.run()?;

Ok(Output::success("ok"))
}

fn start_all_connections(config: &Config) -> Result<Output, BoxError> {
let connections = config
.connections
.as_ref()
.filter(|conns| !conns.is_empty())
.ok_or("no connections configured")?;

let mut registry = Registry::new(config);

let result = crossbeam_utils::thread::scope(|s| {
for conn in connections {
info!(
"spawning supervisor for chains {} and {}",
conn.a_chain, conn.b_chain
);

let chain_a = registry.get_or_spawn(&conn.a_chain)?;
let chain_b = registry.get_or_spawn(&conn.b_chain)?;

s.spawn(|_| {
let supervisor = Supervisor::spawn(chain_a, chain_b).unwrap();
supervisor.run()
});
}

Ok(())
});

match result {
Ok(Ok(())) => Ok(Output::success("ok")),
Ok(Err(e)) => Err(e),
Err(e) => std::panic::resume_unwind(e),
}
}
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/tx/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ibc::Height;
use ibc_relayer::channel::{Channel, ChannelSide};
use ibc_relayer::config::StoreConfig;

use crate::commands::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::conclude::Output;
use crate::error::{Error, Kind};
use crate::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/tx/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ibc_relayer::config::StoreConfig;
use ibc_relayer::foreign_client::ForeignClient;

use crate::application::app_config;
use crate::commands::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::conclude::{exit_with_unrecoverable_error, Output};
use crate::error::{Error, Kind};

Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/tx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ibc::ics24_host::identifier::{ChainId, ClientId, ConnectionId};
use ibc_relayer::config::StoreConfig;
use ibc_relayer::connection::{Connection, ConnectionSide};

use crate::commands::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::conclude::Output;
use crate::error::{Error, Kind};
use crate::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion relayer-cli/src/commands/tx/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ibc::ics24_host::identifier::{ChainId, ChannelId, PortId};
use ibc_relayer::config::StoreConfig;
use ibc_relayer::link::{Link, LinkParameters};

use crate::commands::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::cli_utils::{ChainHandlePair, SpawnOptions};
use crate::conclude::Output;
use crate::error::{Error, Kind};
use crate::prelude::*;
Expand Down
7 changes: 5 additions & 2 deletions relayer-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

pub mod application;
pub mod commands;
mod components;
pub(crate) mod conclude;
pub mod config;
pub mod error;
pub mod prelude;
pub mod registry;

pub(crate) mod cli_utils;
pub(crate) mod components;
pub(crate) mod conclude;
Loading