2019-03-01 01:45:01 +00:00
|
|
|
extern crate slog;
|
|
|
|
|
|
|
|
mod client_config;
|
|
|
|
|
|
|
|
pub mod client_types;
|
|
|
|
pub mod error;
|
|
|
|
pub mod notifier;
|
|
|
|
|
2019-03-19 12:47:58 +00:00
|
|
|
use beacon_chain::BeaconChain;
|
2019-03-01 01:45:01 +00:00
|
|
|
pub use client_config::ClientConfig;
|
|
|
|
pub use client_types::ClientTypes;
|
2019-03-19 11:53:51 +00:00
|
|
|
use exit_future::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> {
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Configuration for the lighthouse client.
|
2019-03-01 01:45:01 +00:00
|
|
|
config: ClientConfig,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// The beacon chain for the running client.
|
2019-03-18 05:16:54 +00:00
|
|
|
beacon_chain: Arc<BeaconChain<T::DB, T::SlotClock, T::ForkChoice>>,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Reference to the network service.
|
2019-03-12 06:28:11 +00:00
|
|
|
pub network: Arc<NetworkService>,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Future to stop and begin shutdown of the Client.
|
|
|
|
//TODO: Decide best way to handle shutdown
|
2019-03-12 06:28:11 +00:00
|
|
|
pub exit: exit_future::Exit,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// The sending future to call to terminate the Client.
|
|
|
|
//TODO: Decide best way to handle shutdown
|
2019-03-12 06:28:11 +00:00
|
|
|
pub exit_signal: Signal,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// The clients logger.
|
2019-03-01 01:45:01 +00:00
|
|
|
log: slog::Logger,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Marker to pin the beacon chain generics.
|
|
|
|
phantom: PhantomData<T>,
|
2019-03-01 01:45:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 06:38:23 +00:00
|
|
|
impl<TClientType: ClientTypes> Client<TClientType> {
|
|
|
|
/// Generate an instance of the client. Spawn and link all internal sub-processes.
|
2019-03-01 01:45:01 +00:00
|
|
|
pub fn new(
|
|
|
|
config: ClientConfig,
|
|
|
|
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
|
2019-03-18 06:38:23 +00:00
|
|
|
let beacon_chain = TClientType::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-19 11:53:51 +00:00
|
|
|
let (network, _network_send) = NetworkService::new(
|
2019-03-18 05:16:54 +00:00
|
|
|
beacon_chain.clone(),
|
|
|
|
network_config,
|
|
|
|
executor,
|
|
|
|
network_logger,
|
|
|
|
)?;
|
2019-03-04 05:39:37 +00:00
|
|
|
|
2019-03-19 12:47:58 +00:00
|
|
|
// spawn the RPC server
|
|
|
|
rpc::start_server(&config.rpc_conf, &log);
|
|
|
|
|
2019-03-01 01:45:01 +00:00
|
|
|
Ok(Client {
|
|
|
|
config,
|
2019-03-18 06:38:23 +00:00
|
|
|
beacon_chain,
|
2019-03-01 01:45:01 +00:00
|
|
|
exit,
|
2019-03-19 12:20:39 +00:00
|
|
|
exit_signal,
|
2019-03-01 01:45:01 +00:00
|
|
|
log,
|
2019-03-19 12:20:39 +00:00
|
|
|
network,
|
2019-03-01 01:45:01 +00:00
|
|
|
phantom: PhantomData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|