Skip to content

Commit

Permalink
Remove light client commands and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Apr 1, 2021
1 parent cfbb766 commit b0ec88e
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 718 deletions.
57 changes: 3 additions & 54 deletions relayer-cli/src/cli_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use ibc::ics24_host::identifier::ChainId;
use ibc_relayer::chain::runtime::ChainRuntime;
use ibc_relayer::chain::CosmosSdkChain;
use ibc_relayer::config::{ChainConfig, StoreConfig};
use ibc_relayer::{chain::handle::ChainHandle, config::Config};

use crate::error::{Error, Kind};
Expand All @@ -23,20 +22,8 @@ impl ChainHandlePair {
src_chain_id: &ChainId,
dst_chain_id: &ChainId,
) -> Result<Self, Error> {
Self::spawn_with(Default::default(), config, src_chain_id, dst_chain_id)
}

/// Spawn the source and destination chain runtime from the configuration and chain identifiers,
/// and return the pair of associated handles. Accepts a `SpawnOptions` argument, which
/// is used to override each chain configuration before spawning its runtime.
pub fn spawn_with(
options: SpawnOptions,
config: &Config,
src_chain_id: &ChainId,
dst_chain_id: &ChainId,
) -> Result<Self, Error> {
let src = spawn_chain_runtime(options.clone(), config, src_chain_id)?;
let dst = spawn_chain_runtime(options, config, dst_chain_id)?;
let src = spawn_chain_runtime(config, src_chain_id)?;
let dst = spawn_chain_runtime(config, dst_chain_id)?;

Ok(ChainHandlePair { src, dst })
}
Expand All @@ -45,57 +32,19 @@ impl ChainHandlePair {
/// Spawns a chain runtime from the configuration and given a chain identifier.
/// Returns the corresponding handle if successful.
pub fn spawn_chain_runtime(
spawn_options: SpawnOptions,
config: &Config,
chain_id: &ChainId,
) -> Result<Box<dyn ChainHandle>, Error> {
let mut chain_config = config
let chain_config = config
.find_chain(chain_id)
.cloned()
.ok_or_else(|| format!("missing chain for id ({}) in configuration file", chain_id))
.map_err(|e| Kind::Config.context(e))?;

spawn_options.apply(&mut chain_config);

let chain_res =
ChainRuntime::<CosmosSdkChain>::spawn(chain_config).map_err(|e| Kind::Runtime.context(e));

let handle = chain_res.map(|(handle, _)| handle)?;

Ok(handle)
}

/// Allows override the chain configuration just before
/// spawning a new runtime instance.
///
/// This is currently only used to override the configured
/// light client store for one-off commands which do not
/// need the disk-based store.
#[derive(Clone, Debug, Default)]
pub struct SpawnOptions {
override_store_config: Option<StoreConfig>,
}

impl SpawnOptions {
/// Override the light client store config with the provided config.
pub fn override_store_config(store_config: StoreConfig) -> Self {
Self {
override_store_config: Some(store_config),
}
}

/// Apply these options to the provided chain configuration.
pub fn apply(&self, chain_config: &mut ChainConfig) {
if let Some(store_config) = &self.override_store_config {
Self::apply_store_config(chain_config, &store_config)
}
}

fn apply_store_config(chain_config: &mut ChainConfig, store_config: &StoreConfig) {
if let Some(peer_config) = chain_config.peers.as_mut() {
for light_client in &mut peer_config.light_clients {
light_client.store = store_config.clone();
}
}
}
}
10 changes: 2 additions & 8 deletions relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ use abscissa_core::{Command, Configurable, FrameworkError, Help, Options, Runnab
use crate::config::Config;

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

mod config;
mod create;
mod keys;
mod light;
mod listen;
mod query;
mod start;
Expand Down Expand Up @@ -50,10 +48,6 @@ pub enum CliCmd {
#[options(help = "Manage keys in the relayer for each chain")]
Keys(KeysCmd),

/// The `light` subcommand
#[options(help = "Basic functionality for managing the light clients")]
Light(LightCmd),

/// The `create` subcommand
#[options(help = "Create objects (client, connection, or channel) on chains")]
Create(CreateCmds),
Expand Down
17 changes: 6 additions & 11 deletions relayer-cli/src/commands/create/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use ibc::ics04_channel::channel::Order;
use ibc::ics24_host::identifier::{ChainId, ConnectionId, PortId};
use ibc::Height;
use ibc_relayer::channel::Channel;
use ibc_relayer::config::StoreConfig;
use ibc_relayer::connection::Connection;
use ibc_relayer::foreign_client::ForeignClient;

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

Expand Down Expand Up @@ -69,11 +68,9 @@ impl CreateChannelCommand {
fn run_using_new_connection(&self, chain_b_id: &ChainId) {
let config = app_config();

let spawn_options = SpawnOptions::override_store_config(StoreConfig::memory());
let chains = ChainHandlePair::spawn(&config, &self.chain_a_id, chain_b_id)
.unwrap_or_else(exit_with_unrecoverable_error);

let chains =
ChainHandlePair::spawn_with(spawn_options, &config, &self.chain_a_id, chain_b_id)
.unwrap_or_else(exit_with_unrecoverable_error);
info!(
"Creating new clients, new connection, and a new channel with order {:?} and version {}",
self.order, self.version
Expand All @@ -100,10 +97,8 @@ impl CreateChannelCommand {
fn run_reusing_connection(&self) {
let config = app_config();

let spawn_options = SpawnOptions::override_store_config(StoreConfig::memory());

// Validate & spawn runtime for side a.
let chain_a = spawn_chain_runtime(spawn_options.clone(), &config, &self.chain_a_id)
let chain_a = spawn_chain_runtime(&config, &self.chain_a_id)
.unwrap_or_else(exit_with_unrecoverable_error);

// Unwrap the identifier of the connection on side a.
Expand All @@ -130,8 +125,8 @@ impl CreateChannelCommand {
.unwrap_or_else(exit_with_unrecoverable_error);

// Spawn the runtime for side b.
let chain_b = spawn_chain_runtime(spawn_options, &config, &chain_b_id)
.unwrap_or_else(exit_with_unrecoverable_error);
let chain_b =
spawn_chain_runtime(&config, &chain_b_id).unwrap_or_else(exit_with_unrecoverable_error);

// Create the foreign client handles.
let client_a = ForeignClient::find(chain_b.clone(), chain_a.clone(), conn_end.client_id())
Expand Down
15 changes: 5 additions & 10 deletions relayer-cli/src/commands/create/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use abscissa_core::{Command, Options, Runnable};
use ibc::ics02_client::client_state::ClientState;
use ibc::ics24_host::identifier::{ChainId, ClientId};
use ibc::Height;
use ibc_relayer::config::StoreConfig;
use ibc_relayer::connection::Connection;
use ibc_relayer::foreign_client::ForeignClient;

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

Expand Down Expand Up @@ -60,11 +59,8 @@ impl CreateConnectionCommand {
fn run_using_new_clients(&self, chain_b_id: &ChainId) {
let config = app_config();

let spawn_options = SpawnOptions::override_store_config(StoreConfig::memory());

let chains =
ChainHandlePair::spawn_with(spawn_options, &config, &self.chain_a_id, chain_b_id)
.unwrap_or_else(exit_with_unrecoverable_error);
let chains = ChainHandlePair::spawn(&config, &self.chain_a_id, chain_b_id)
.unwrap_or_else(exit_with_unrecoverable_error);

// Validate the other options. Bail if the CLI was invoked with incompatible options.
if self.client_a.is_some() {
Expand Down Expand Up @@ -99,9 +95,8 @@ impl CreateConnectionCommand {
fn run_reusing_clients(&self) {
let config = app_config();

let spawn_options = SpawnOptions::override_store_config(StoreConfig::memory());
// Validate & spawn runtime for chain_a.
let chain_a = match spawn_chain_runtime(spawn_options.clone(), &config, &self.chain_a_id) {
let chain_a = match spawn_chain_runtime(&config, &self.chain_a_id) {
Ok(handle) => handle,
Err(e) => return Output::error(format!("{}", e)).exit(),
};
Expand Down Expand Up @@ -131,7 +126,7 @@ impl CreateConnectionCommand {
};

// Validate & spawn runtime for chain_b.
let chain_b = match spawn_chain_runtime(spawn_options, &config, &chain_b_id) {
let chain_b = match spawn_chain_runtime(&config, &chain_b_id) {
Ok(handle) => handle,
Err(e) => return Output::error(format!("{}", e)).exit(),
};
Expand Down
18 changes: 0 additions & 18 deletions relayer-cli/src/commands/light.rs

This file was deleted.

Loading

0 comments on commit b0ec88e

Please sign in to comment.