mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Organize beacon_chain typing
- Implements ClientTypes - New network BeaconChain type for the networking service
This commit is contained in:
@@ -1,39 +1,49 @@
|
||||
use db::{ClientDB, DiskDB, MemoryDB};
|
||||
use fork_choice::{BitwiseLMDGhost, ForkChoice};
|
||||
use slot_clock::{SlotClock, SystemTimeSlotClock, TestingSlotClock};
|
||||
use beacon_chain::initialise;
|
||||
use crate::ClientConfig;
|
||||
use beacon_chain::{
|
||||
db::{ClientDB, DiskDB, MemoryDB},
|
||||
fork_choice::BitwiseLMDGhost,
|
||||
initialise,
|
||||
slot_clock::{SlotClock, SystemTimeSlotClock, TestingSlotClock},
|
||||
BeaconChain,
|
||||
};
|
||||
use fork_choice::ForkChoice;
|
||||
|
||||
use std::sync::Arc;
|
||||
use crate::ClientConfig
|
||||
|
||||
pub trait ClientTypes {
|
||||
type ForkChoice: ForkChoice;
|
||||
type DB: ClientDB;
|
||||
type SlotClock: SlotClock;
|
||||
type DB: ClientDB + 'static;
|
||||
type SlotClock: SlotClock + 'static;
|
||||
type ForkChoice: ForkChoice + 'static;
|
||||
|
||||
pub fn initialise_beacon_chain(cchain_spec: &ClientConfig) -> Arc<BeaconChain<DB,SlotClock,ForkChoice>>);
|
||||
fn initialise_beacon_chain(
|
||||
config: &ClientConfig,
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice>>;
|
||||
}
|
||||
|
||||
pub struct StandardClientType
|
||||
pub struct StandardClientType;
|
||||
|
||||
impl ClientTypes for StandardClientType {
|
||||
type DB = DiskDB;
|
||||
type ForkChoice = BitwiseLMDGhost<DiskDB>;
|
||||
type SlotClock = SystemTimeSlotClock;
|
||||
type ForkChoice = BitwiseLMDGhost<DiskDB>;
|
||||
|
||||
pub fn initialise_beacon_chain(config: &ClientConfig) -> Arc<BeaconChain<DB,SlotClock,ForkChoice>>) {
|
||||
initialise::initialise_beacon_chain(config.chain_spec, config.db_name)
|
||||
fn initialise_beacon_chain(
|
||||
config: &ClientConfig,
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice>> {
|
||||
initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct TestingClientType
|
||||
pub struct TestingClientType;
|
||||
|
||||
impl ClientTypes for TestingClientType {
|
||||
type DB = MemoryDB;
|
||||
type SlotClock = TestingSlotClock;
|
||||
type SlotClock = SystemTimeSlotClock;
|
||||
type ForkChoice = BitwiseLMDGhost<MemoryDB>;
|
||||
|
||||
pub fn initialise_beacon_chain(config: &ClientConfig) -> Arc<BeaconChain<DB,SlotClock,ForkChoice>>) {
|
||||
initialise::initialise_test_beacon_chain(config.chain_spec, None)
|
||||
fn initialise_beacon_chain(
|
||||
config: &ClientConfig,
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice>> {
|
||||
initialise::initialise_test_beacon_chain(&config.spec, None)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user