Skip to content

Commit

Permalink
Shy start on the local chain feature #158
Browse files Browse the repository at this point in the history
  • Loading branch information
adizere committed Sep 18, 2020
1 parent 2abf34a commit 1aefab8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/src/mock_client/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl From<MockClientState> for AnyClientState {
}

impl TryFromRaw for MockClientState {
type Error = Error;
type RawType = ibc_proto::ibc::mock::ClientState;
type Error = Error;

fn try_from(raw: Self::RawType) -> Result<Self, Self::Error> {
let raw_header = raw
Expand Down
25 changes: 24 additions & 1 deletion relayer-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use tendermint::lite::types::Header;
use crate::commands::utils::block_on;
use relayer::chain::{Chain, CosmosSDKChain};
use relayer::client::Client;
use relayer::config::ChainConfig;
use relayer::config::{ChainConfig, LocalChainConfig};

use relayer::store::Store;

use crate::commands::listen::relayer_task;
use relayer::local_chain::LocalChain;

#[derive(Command, Debug, Options)]
pub struct StartCmd {
Expand All @@ -31,13 +32,22 @@ impl Runnable for StartCmd {
// abscissa_tokio::run(&APPLICATION, ...).unwrap();

debug!("launching 'start' command");
if ! config.local_chains.is_empty() {
debug!("found the following local chains: {:?}", config.local_chains);
}

// Spawn all tasks on the same thread that calls `block_on`, ie. the main thread.
// This allows us to spawn tasks which do not implement `Send`,
// like the light client task.
let local = tokio::task::LocalSet::new();

block_on(local.run_until(async move {
// Start the local chains
for lc_config in &config.local_chains {
info!(local_chain.id = %lc_config.id, "spawning local chain");
tokio::task::spawn_local(create_local_chain(lc_config.clone()));
}
// Start the clients
for chain_config in &config.chains {
info!(chain.id = %chain_config.id, "spawning light client");
tokio::task::spawn_local(spawn_client(chain_config.clone(), self.reset));
Expand Down Expand Up @@ -127,3 +137,16 @@ async fn create_client(
client
}
}

async fn create_local_chain(
local_chain_config: LocalChainConfig,
) -> LocalChain {
let chain = LocalChain::from_config(local_chain_config.clone()).unwrap();

// Create clients, if any are specified.
for client_id in &local_chain_config.client_ids {
chain.create_client(client_id);
}

chain
}
7 changes: 7 additions & 0 deletions relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod default {
pub struct Config {
pub global: GlobalConfig,
pub chains: Vec<ChainConfig>,
pub local_chains: Vec<LocalChainConfig>,
pub connections: Option<Vec<Connection>>, // use all for default
}

Expand Down Expand Up @@ -67,6 +68,12 @@ impl Default for GlobalConfig {
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LocalChainConfig {
pub id: ChainId,
pub client_ids: Vec<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ChainConfig {
pub id: ChainId,
Expand Down
1 change: 1 addition & 0 deletions relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pub mod event_handler;
pub mod event_monitor;
pub mod store;
pub mod util;
pub mod local_chain;
21 changes: 21 additions & 0 deletions relayer/src/local_chain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::config::LocalChainConfig;
use crate::error::Error;

pub struct LocalChain {
pub config: LocalChainConfig,
}

impl LocalChain {
pub fn from_config(config: LocalChainConfig) -> Result<Self, Error> {
Ok(Self {
config,
})
}

// TODO -- add a generic interface to submit any type of IBC messages.
/// Submits an IBC message for creating an IBC client on the chain. It is assumed that this is
/// a client for a mock chain.
pub fn create_client(&self, _client_id: &String) {
unimplemented!()
}
}
4 changes: 4 additions & 0 deletions relayer/tests/config/fixtures/relayer_conf_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ title = "IBC Relayer Config Example"
timeout = "10s"
strategy = "naive"

[[local_chains]]
id = "localchain_A"
client_ids = ["lc_clientA"]

[[chains]]
id = "chain_A"
rpc_addr = "localhost:26657"
Expand Down

0 comments on commit 1aefab8

Please sign in to comment.