Skip to content

Commit

Permalink
Launch light clients
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 11, 2020
1 parent 189bde0 commit 62b9498
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 381 deletions.
2 changes: 2 additions & 0 deletions relayer-cli/src/commands/light/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use abscissa_core::{application::fatal_error, error::BoxError, Command, Options,

use ibc::ics24_host::identifier::ChainId;
use relayer::{
config,
config::{Config, LightClientConfig, PeersConfig},
util::block_on,
};
Expand Down Expand Up @@ -183,6 +184,7 @@ fn update_config(
let light_client_config = LightClientConfig {
peer_id: status.peer_id,
address: status.address.clone(),
timeout: config::default::timeout(),
trusted_header_hash: status.latest_hash,
trusted_height: status.latest_height,
};
Expand Down
34 changes: 4 additions & 30 deletions relayer-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::ops::Deref;

use abscissa_core::{
application::fatal_error, error::BoxError, tracing::info, Command, Options, Runnable,
};
use abscissa_core::{application::fatal_error, error::BoxError, Command, Options, Runnable};

use relayer::{chain::CosmosSDKChain, config::Config};
use relayer::config::Config;

use crate::{application::APPLICATION, prelude::*, tasks};
use crate::{application::APPLICATION, prelude::*};

#[derive(Command, Debug, Options)]
pub struct StartCmd {
Expand All @@ -33,29 +31,5 @@ impl Runnable for StartCmd {
}

async fn start(config: Config, reset: bool) -> Result<(), BoxError> {
let mut chains: Vec<CosmosSDKChain> = vec![];

for chain_config in &config.chains {
let light_config = chain_config.primary().ok_or_else(|| {
format!(
"could not find light client configuration for chain {}",
chain_config.id
)
})?;

info!(chain.id = %chain_config.id, "spawning light client");

let mut chain = CosmosSDKChain::from_config(chain_config.clone())?;

let client_task =
tasks::light_client::create(&mut chain, light_config.clone(), reset).await?;

chains.push(chain);

let _handle = tokio::task::spawn(client_task);
}

tasks::relayer::start(&config, chains).await?;

Ok(())
todo!() // TODO: Move v0 command here
}
18 changes: 12 additions & 6 deletions relayer-cli/src/commands/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use relayer::{
channel::{Channel, ChannelConfig},
connection::{Connection, ConnectionConfig},
foreign_client::{ForeignClient, ForeignClientConfig},
light_client::tendermint::TendermintLightClient,
link::{Link, LinkConfig},
};

Expand Down Expand Up @@ -60,16 +61,23 @@ pub fn v0_task(config: Config) -> Result<(), BoxError> {
dst_chain_config
.client_ids
.get(0)
.ok_or_else(|| "Config for client for dest. chain not found")?,
.ok_or_else(|| "Config for client for destination chain not found")?,
)
.map_err(|e| format!("Error validating client identifier for dst chain ({:?})", e))?;

let (src_light_client, src_supervisor) =
TendermintLightClient::from_config(&src_chain_config, true)?;
let (dst_light_client, dst_supervisor) =
TendermintLightClient::from_config(&dst_chain_config, true)?;

thread::spawn(move || src_supervisor.run().unwrap());
thread::spawn(move || dst_supervisor.run().unwrap());

let src_chain = ChainRuntime::cosmos_sdk(src_chain_config)?;
let dst_chain = ChainRuntime::cosmos_sdk(dst_chain_config)?;

let src_chain_handle = src_chain.handle();
thread::spawn(move || {
// TODO: What should we do on return here? Probably unrecoverable error.
src_chain.run().unwrap();
});

Expand Down Expand Up @@ -97,16 +105,14 @@ pub fn v0_task(config: Config) -> Result<(), BoxError> {
&dst_chain_handle,
&client_on_src, // Semantic dependency.
ConnectionConfig::new(todo!(), todo!()),
)
.unwrap();
)?;

let channel = Channel::new(
&src_chain_handle,
&dst_chain_handle,
connection, // Semantic dependecy
ChannelConfig::new(todo!(), todo!()),
)
.unwrap();
)?;

let link = Link::new(
src_chain_handle,
Expand Down
2 changes: 0 additions & 2 deletions relayer-cli/src/tasks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! Tasks which make up the relayer application
pub mod event_listener;
pub mod light_client;
pub mod relayer;
178 changes: 0 additions & 178 deletions relayer-cli/src/tasks/light_client.rs

This file was deleted.

46 changes: 0 additions & 46 deletions relayer-cli/src/tasks/relayer.rs

This file was deleted.

15 changes: 2 additions & 13 deletions relayer/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@ use ibc::{

use crate::config::ChainConfig;
use crate::error::Error;
use crate::error::Kind;
use crate::keyring::store::{KeyEntry, KeyRing};
use crate::light_client::LightClient;
use crate::util::block_on;
use crate::{client::LightClient, error::Kind};

/// Defines a blockchain as understood by the relayer
pub trait Chain {
/// Type of headers for this chain
type Header: Send + Sync + Serialize + DeserializeOwned;

/// Type of light blocks for this chain
type LightBlock: Send + Sync + Serialize + DeserializeOwned;

/// Type of light client for this chain
type LightClient: LightClient<Self::LightBlock> + Send + Sync;

/// Type of consensus state for this chain
type ConsensusState: ConsensusState + Send + Sync + Serialize + DeserializeOwned;

Expand All @@ -61,12 +56,6 @@ pub trait Chain {
/// Get a low-level RPC client for this chain
fn rpc_client(&self) -> &Self::RpcClient;

/// Get a light client for this chain
fn light_client(&self) -> Option<&Self::LightClient>;

/// Set a light client for this chain
fn set_light_client(&mut self, light_client: Self::LightClient);

/// The unbonding period of this chain
/// TODO - this is a GRPC query, needs to be implemented
fn unbonding_period(&self) -> Duration;
Expand Down
Loading

0 comments on commit 62b9498

Please sign in to comment.