2019-03-01 01:45:01 +00:00
|
|
|
extern crate slog;
|
|
|
|
|
|
|
|
mod client_config;
|
|
|
|
|
|
|
|
pub mod client_types;
|
|
|
|
pub mod error;
|
|
|
|
pub mod notifier;
|
|
|
|
|
|
|
|
pub use client_config::ClientConfig;
|
|
|
|
pub use client_types::ClientTypes;
|
|
|
|
|
|
|
|
//use beacon_chain::BeaconChain;
|
|
|
|
use exit_future::{Exit, Signal};
|
2019-03-04 07:31:01 +00:00
|
|
|
use network::Service as NetworkService;
|
|
|
|
use slog::o;
|
2019-03-01 01:45:01 +00:00
|
|
|
use std::marker::PhantomData;
|
2019-03-04 07:31:01 +00:00
|
|
|
use std::sync::Arc;
|
2019-03-01 01:45:01 +00:00
|
|
|
use tokio::runtime::TaskExecutor;
|
|
|
|
|
2019-03-04 05:39:37 +00:00
|
|
|
/// Main beacon node client service. This provides the connection and initialisation of the clients
|
|
|
|
/// sub-services in multiple threads.
|
2019-03-01 01:45:01 +00:00
|
|
|
pub struct Client<T: ClientTypes> {
|
|
|
|
config: ClientConfig,
|
2019-03-18 05:16:54 +00:00
|
|
|
beacon_chain: Arc<BeaconChain<T::DB, T::SlotClock, T::ForkChoice>>,
|
2019-03-12 06:28:11 +00:00
|
|
|
pub network: Arc<NetworkService>,
|
|
|
|
pub exit: exit_future::Exit,
|
|
|
|
pub exit_signal: Signal,
|
2019-03-01 01:45:01 +00:00
|
|
|
log: slog::Logger,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: ClientTypes> Client<T> {
|
2019-03-04 05:39:37 +00:00
|
|
|
/// Generate an instance of the client. Spawn and link all internal subprocesses.
|
2019-03-01 01:45:01 +00:00
|
|
|
pub fn new(
|
|
|
|
config: ClientConfig,
|
2019-03-18 05:16:54 +00:00
|
|
|
client_type: T,
|
2019-03-01 01:45:01 +00:00
|
|
|
log: slog::Logger,
|
2019-03-17 10:49:56 +00:00
|
|
|
executor: &TaskExecutor,
|
2019-03-01 01:45:01 +00:00
|
|
|
) -> error::Result<Self> {
|
|
|
|
let (exit_signal, exit) = exit_future::signal();
|
|
|
|
|
2019-03-18 05:16:54 +00:00
|
|
|
// generate a beacon chain
|
|
|
|
let beacon_chain = client_type.initialise_beacon_chain(&config);
|
2019-03-04 05:39:37 +00:00
|
|
|
|
2019-03-04 07:31:01 +00:00
|
|
|
// Start the network service, libp2p and syncing threads
|
2019-03-04 05:39:37 +00:00
|
|
|
// TODO: Add beacon_chain reference to network parameters
|
2019-03-18 05:16:54 +00:00
|
|
|
let network_config = &config.net_conf;
|
2019-03-04 07:31:01 +00:00
|
|
|
let network_logger = log.new(o!("Service" => "Network"));
|
2019-03-18 05:16:54 +00:00
|
|
|
let (network, network_send) = NetworkService::new(
|
|
|
|
beacon_chain.clone(),
|
|
|
|
network_config,
|
|
|
|
executor,
|
|
|
|
network_logger,
|
|
|
|
)?;
|
2019-03-04 05:39:37 +00:00
|
|
|
|
2019-03-01 01:45:01 +00:00
|
|
|
Ok(Client {
|
|
|
|
config,
|
|
|
|
exit,
|
2019-03-12 06:28:11 +00:00
|
|
|
exit_signal: exit_signal,
|
2019-03-01 01:45:01 +00:00
|
|
|
log,
|
2019-03-12 06:28:11 +00:00
|
|
|
network: network,
|
2019-03-01 01:45:01 +00:00
|
|
|
phantom: PhantomData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|