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

Spike for parallel relaying between multiple channels #692

Merged
merged 16 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl IbcEvent {
serde_json::to_string(self).unwrap()
}

pub fn height(&self) -> &Height {
pub fn height(&self) -> Height {
match self {
IbcEvent::NewBlock(bl) => bl.height(),
IbcEvent::CreateClient(ev) => ev.height(),
Expand Down
16 changes: 8 additions & 8 deletions modules/src/ics02_client/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl NewBlock {
pub fn set_height(&mut self, height: Height) {
self.height = height;
}
pub fn height(&self) -> &Height {
&self.height
pub fn height(&self) -> Height {
self.height
}
}

Expand Down Expand Up @@ -104,8 +104,8 @@ impl CreateClient {
pub fn client_id(&self) -> &ClientId {
&self.0.client_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -146,8 +146,8 @@ impl UpdateClient {
&self.0.client_id
}

pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -188,8 +188,8 @@ impl ClientMisbehavior {
pub fn client_id(&self) -> &ClientId {
&self.0.client_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down
16 changes: 8 additions & 8 deletions modules/src/ics03_connection/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl OpenInit {
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -131,8 +131,8 @@ impl OpenTry {
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -174,8 +174,8 @@ impl OpenAck {
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -217,8 +217,8 @@ impl OpenConfirm {
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down
62 changes: 36 additions & 26 deletions modules/src/ics04_channel/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ impl OpenInit {
pub fn channel_id(&self) -> &Option<ChannelId> {
&self.0.channel_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -225,8 +225,8 @@ impl OpenTry {
pub fn channel_id(&self) -> &Option<ChannelId> {
&self.0.channel_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -269,8 +269,8 @@ impl OpenAck {
pub fn channel_id(&self) -> &Option<ChannelId> {
&self.0.channel_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -313,8 +313,8 @@ impl OpenConfirm {
pub fn channel_id(&self) -> &Option<ChannelId> {
&self.0.channel_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -357,11 +357,21 @@ impl CloseInit {
pub fn port_id(&self) -> &PortId {
&self.0.port_id
}
pub fn channel_id(&self) -> &Option<ChannelId> {
&self.0.channel_id
pub fn channel_id(&self) -> &ChannelId {
// FIXME(romac): Rework encoding of IbcEvents which use `Attributes`
romac marked this conversation as resolved.
Show resolved Hide resolved
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 height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -416,8 +426,8 @@ impl CloseConfirm {
pub fn channel_id(&self) -> &Option<ChannelId> {
&self.0.channel_id
}
pub fn height(&self) -> &Height {
&self.0.height
pub fn height(&self) -> Height {
self.0.height
}
pub fn set_height(&mut self, height: Height) {
self.0.height = height;
Expand Down Expand Up @@ -486,8 +496,8 @@ pub struct SendPacket {
}

impl SendPacket {
pub fn height(&self) -> &Height {
&self.height
pub fn height(&self) -> Height {
self.height
}
pub fn set_height(&mut self, height: Height) {
self.height = height;
Expand Down Expand Up @@ -524,8 +534,8 @@ pub struct ReceivePacket {
}

impl ReceivePacket {
pub fn height(&self) -> &Height {
&self.height
pub fn height(&self) -> Height {
self.height
}
pub fn set_height(&mut self, height: Height) {
self.height = height;
Expand Down Expand Up @@ -564,8 +574,8 @@ pub struct WriteAcknowledgement {
}

impl WriteAcknowledgement {
pub fn height(&self) -> &Height {
&self.height
pub fn height(&self) -> Height {
self.height
}
pub fn set_height(&mut self, height: Height) {
self.height = height;
Expand Down Expand Up @@ -607,8 +617,8 @@ pub struct AcknowledgePacket {
}

impl AcknowledgePacket {
pub fn height(&self) -> &Height {
&self.height
pub fn height(&self) -> Height {
self.height
}
pub fn set_height(&mut self, height: Height) {
self.height = height;
Expand Down Expand Up @@ -643,8 +653,8 @@ pub struct TimeoutPacket {
}

impl TimeoutPacket {
pub fn height(&self) -> &Height {
&self.height
pub fn height(&self) -> Height {
self.height
}
pub fn set_height(&mut self, height: Height) {
self.height = height
Expand Down Expand Up @@ -686,8 +696,8 @@ pub struct TimeoutOnClosePacket {
}

impl TimeoutOnClosePacket {
pub fn height(&self) -> &Height {
&self.height
pub fn height(&self) -> Height {
self.height
}
pub fn set_height(&mut self, height: Height) {
self.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 @@ -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