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

Remove light client commands and configuration #793

Merged
merged 12 commits into from
Apr 7, 2021
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@
- `MsgConnectionOpenAck.counterparty_connection_id` is now a `ConnectionId` instead of an `Option<ConnectionId>`([#700])

- [ibc-relayer]
- [nothing yet]
- Remove the light client configuration from the global configuration ([#793])

- [ibc-relayer-cli]
- [nothing yet]
- Remove the light add and light rm commands ([#793])


[#352]: https://github.com/informalsystems/ibc-rs/issues/352
[#357]: https://github.com/informalsystems/ibc-rs/issues/357
Expand All @@ -89,6 +90,7 @@
[#761]: https://github.com/informalsystems/ibc-rs/issues/761
[#772]: https://github.com/informalsystems/ibc-rs/issues/772
[#770]: https://github.com/informalsystems/ibc-rs/issues/770
[#793]: https://github.com/informalsystems/ibc-rs/pull/793


## v0.1.1
Expand Down
24 changes: 0 additions & 24 deletions ci/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,6 @@ echo "Add keys for chains"
echo "-----------------------------------------------------------------------------------------------------------------"
hermes -c "$CONFIG_PATH" keys add "$CHAIN_A" key_seed_"$CHAIN_A".json
hermes -c "$CONFIG_PATH" keys add "$CHAIN_B" key_seed_"$CHAIN_B".json
echo "-----------------------------------------------------------------------------------------------------------------"
echo "Set the primary peers for clients on each chain "
echo "-----------------------------------------------------------------------------------------------------------------"
LIGHT_ADD_CHAIN_A="hermes -c $CONFIG_PATH light add http://$CHAIN_A:$CHAIN_A_PORT -c $CHAIN_A -s $CHAIN_A_HOME -p -y -f"
echo "Executing: $LIGHT_ADD_CHAIN_A"
bash -c "$LIGHT_ADD_CHAIN_A"
sleep 2
echo "-----------------------------------------------------------------------------------------------------------------"
LIGHT_ADD_CHAIN_B="hermes -c $CONFIG_PATH light add http://$CHAIN_B:$CHAIN_B_PORT -c $CHAIN_B -s $CHAIN_B_HOME -p -y -f"
echo "Executing: $LIGHT_ADD_CHAIN_B"
bash -c "$LIGHT_ADD_CHAIN_B"
sleep 2
echo "-----------------------------------------------------------------------------------------------------------------"
echo "Set the secondary peers for clients on each chain "
echo "-----------------------------------------------------------------------------------------------------------------"
LIGHT_ADD_CHAIN_A_PEER="hermes -c $CONFIG_PATH light add http://$CHAIN_A:$CHAIN_A_PORT -c $CHAIN_A -s $CHAIN_A_HOME --peer-id 17D46D8C1576A79203A6733F63B2C9B7235DD559 -y"
echo "Executing: $LIGHT_ADD_CHAIN_A_PEER"
bash -c "$LIGHT_ADD_CHAIN_A_PEER"
sleep 2
echo "-----------------------------------------------------------------------------------------------------------------"
LIGHT_ADD_CHAIN_B_PEER="hermes -c $CONFIG_PATH light add http://$CHAIN_B:$CHAIN_B_PORT -c $CHAIN_B -s $CHAIN_B_HOME --peer-id A885BB3D3DFF6101188B462466AE926E7A6CD51E -y"
echo "Executing: $LIGHT_ADD_CHAIN_B_PEER"
bash -c "$LIGHT_ADD_CHAIN_B_PEER"
sleep 2

echo "================================================================================================================="
echo " END-TO-END TESTS "
Expand Down
3 changes: 2 additions & 1 deletion ci/simple_config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[global]
timeout = '10s'
strategy = 'naive'
log_level = 'info'

Expand All @@ -8,6 +7,7 @@ id = 'ibc-0'
rpc_addr = 'http://ibc-0:26657'
grpc_addr = 'http://ibc-0:9090'
websocket_addr = 'ws://ibc-0:26657/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
Expand All @@ -22,6 +22,7 @@ id = 'ibc-1'
rpc_addr = 'http://ibc-1:26657'
grpc_addr = 'http://ibc-1:9090'
websocket_addr = 'ws://ibc-1:26657/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
Expand Down
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[global]
timeout = '10s'
strategy = 'naive'
log_level = 'error'

Expand All @@ -8,6 +7,7 @@ id = 'ibc-0'
rpc_addr = 'http://127.0.0.1:26657'
grpc_addr = 'http://127.0.0.1:9090'
websocket_addr = 'ws://127.0.0.1:26657/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
Expand All @@ -26,6 +26,7 @@ id = 'ibc-1'
rpc_addr = 'http://127.0.0.1:26557'
grpc_addr = 'http://127.0.0.1:9091'
websocket_addr = 'ws://127.0.0.1:26557/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
Expand Down
3 changes: 2 additions & 1 deletion config_example.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[global]
timeout = '10s'
strategy = 'naive'
log_level = 'error'

Expand All @@ -8,6 +7,7 @@ id = 'ibc-0'
rpc_addr = 'tcp://localhost:26657'
grpc_addr = 'tcp://localhost:9090'
websocket_addr = 'ws://localhost:26657/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
Expand All @@ -26,6 +26,7 @@ id = 'ibc-1'
rpc_addr = 'tcp://localhost:26557'
grpc_addr = 'tcp://localhost:9091'
romac marked this conversation as resolved.
Show resolved Hide resolved
websocket_addr = 'ws://localhost:26557/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
Expand Down
34 changes: 20 additions & 14 deletions docs/architecture/adr-002-ibc-relayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Changelog
* 2020-05-19: First draft. Accepted
* 2020-04-06: Configuration updates

## Definitions
These definitions are specific for this document and they may not be consistent with the IBC Specification.
Expand Down Expand Up @@ -110,20 +111,23 @@ The relayer MAY:
The initial implementation will heavily borrow from the Go relayer implementation that uses a "naive" algorithm for relaying messages. The structure of the configuration file is similar with the one in Go (see [Go-Relayer](https://github.com/cosmos/relayer))

### Configuration
(WIP)

> WIP

Upon start the relayer reads a configuration file that includes global and per chain parameters. The file format is .toml
Below is an example of a configuration file.

```toml
title = "IBC Relayer Config Example"

[global]
timeout = "10s"
strategy = "naive"
log_level = "error"

[[chains]]
id = "chain_A"
rpc_addr = "localhost:26657"
rpc_addr = "http://localhost:26657"
grpc_addr = "http://localhost:9090"
websocket_addr = "ws://localhost:26657/websocket"
rpc_timeout = "10s"
account_prefix = "cosmos"
key_name = "testkey"
store_prefix = "ibc"
Expand All @@ -135,7 +139,10 @@ strategy = "naive"

[[chains]]
id = "chain_B"
rpc_addr = "localhost:26557"
rpc_addr = "http://localhost:26557"
grpc_addr = "http://localhost:9091"
websocket_addr = "ws://localhost:26557/websocket"
rpc_timeout = "10s"
account_prefix = "cosmos"
key_name = "testkey"
store_prefix = "ibc"
Expand Down Expand Up @@ -197,13 +204,19 @@ pub enum Strategy {
}

pub struct GlobalConfig {
pub timeout: Duration,
pub strategy: Strategy,

/// All valid log levels, as defined in tracing:
/// https://docs.rs/tracing-core/0.1.17/tracing_core/struct.Level.html
pub log_level: String,
}

pub struct ChainConfig {
pub id: ChainId,
pub rpc_addr: tendermint_rpc::Url,
pub websocket_addr: tendermint_rpc::Url,
pub grpc_addr: tendermint_rpc::Url,
pub rpc_timeout: Duration,
pub account_prefix: String,
pub key_name: String,
pub client_ids: Vec<String>,
Expand Down Expand Up @@ -248,13 +261,6 @@ To validate a configuration file:

The command verifies that the specified configuration file parses and it is semantically correct.

#### Light Client Initialization
To initialize a light client:

`relayer -c <config_file> light init -x <hash> -h <height> <chain>`

The command initializes the light client for `<chain>` with a trusted height and hash. This should be done for all chains for which relaying is performed.

#### Start
To start the relayer:

Expand Down
1 change: 0 additions & 1 deletion docs/architecture/adr-006-hermes-v0.2-usecases.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ of the config file will look as follows:

```toml
[global]
timeout = '10s'
strategy = 'naive'
log_level = 'error'
log_json = 'false'
Expand Down
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
Loading