Organize beacon_chain typing

- Implements ClientTypes
- New network BeaconChain type for the networking service
This commit is contained in:
Age Manning
2019-03-18 17:38:23 +11:00
parent bbad4bfa19
commit 6b5debe654
8 changed files with 93 additions and 45 deletions

View File

@@ -10,6 +10,7 @@ pub use client_config::ClientConfig;
pub use client_types::ClientTypes;
//use beacon_chain::BeaconChain;
use beacon_chain::BeaconChain;
use exit_future::{Exit, Signal};
use network::Service as NetworkService;
use slog::o;
@@ -20,26 +21,35 @@ use tokio::runtime::TaskExecutor;
/// Main beacon node client service. This provides the connection and initialisation of the clients
/// sub-services in multiple threads.
pub struct Client<T: ClientTypes> {
/// Configuration for the lighthouse client.
config: ClientConfig,
/// The beacon chain for the running client.
beacon_chain: Arc<BeaconChain<T::DB, T::SlotClock, T::ForkChoice>>,
/// Reference to the network service.
pub network: Arc<NetworkService>,
/// Future to stop and begin shutdown of the Client.
//TODO: Decide best way to handle shutdown
pub exit: exit_future::Exit,
/// The sending future to call to terminate the Client.
//TODO: Decide best way to handle shutdown
pub exit_signal: Signal,
/// The clients logger.
log: slog::Logger,
/// Marker to pin the beacon chain generics.
phantom: PhantomData<T>,
}
impl<T: ClientTypes> Client<T> {
/// Generate an instance of the client. Spawn and link all internal subprocesses.
impl<TClientType: ClientTypes> Client<TClientType> {
/// Generate an instance of the client. Spawn and link all internal sub-processes.
pub fn new(
config: ClientConfig,
client_type: T,
log: slog::Logger,
executor: &TaskExecutor,
) -> error::Result<Self> {
let (exit_signal, exit) = exit_future::signal();
// generate a beacon chain
let beacon_chain = client_type.initialise_beacon_chain(&config);
let beacon_chain = TClientType::initialise_beacon_chain(&config);
// Start the network service, libp2p and syncing threads
// TODO: Add beacon_chain reference to network parameters
@@ -54,6 +64,7 @@ impl<T: ClientTypes> Client<T> {
Ok(Client {
config,
beacon_chain,
exit,
exit_signal: exit_signal,
log,