Update beacon_node
to work w/ BeaconStateTypes
This commit is contained in:
parent
42b7aa89d4
commit
4c0c93f0c9
@ -9,8 +9,8 @@ use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::path::PathBuf;
|
||||
use types::multiaddr::Protocol;
|
||||
use types::multiaddr::ToMultiaddr;
|
||||
use types::ChainSpec;
|
||||
use types::Multiaddr;
|
||||
use types::{BeaconStateTypes, ChainSpec, LighthouseTestnetStateTypes};
|
||||
|
||||
/// Stores the client configuration for this Lighthouse instance.
|
||||
#[derive(Debug, Clone)]
|
||||
@ -35,7 +35,7 @@ impl Default for ClientConfig {
|
||||
fs::create_dir_all(&data_dir)
|
||||
.unwrap_or_else(|_| panic!("Unable to create {:?}", &data_dir));
|
||||
|
||||
let default_spec = ChainSpec::lighthouse_testnet();
|
||||
let default_spec = LighthouseTestnetStateTypes::spec();
|
||||
let default_net_conf = NetworkConfig::new(default_spec.boot_nodes.clone());
|
||||
|
||||
Self {
|
||||
|
@ -7,6 +7,7 @@ use beacon_chain::{
|
||||
BeaconChain,
|
||||
};
|
||||
use fork_choice::ForkChoice;
|
||||
use types::{BeaconStateTypes, FewValidatorsStateTypes, FoundationStateTypes};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -14,10 +15,11 @@ pub trait ClientTypes {
|
||||
type DB: ClientDB + 'static;
|
||||
type SlotClock: SlotClock + 'static;
|
||||
type ForkChoice: ForkChoice + 'static;
|
||||
type BeaconStateTypes: BeaconStateTypes + 'static;
|
||||
|
||||
fn initialise_beacon_chain(
|
||||
config: &ClientConfig,
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice>>;
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>>;
|
||||
}
|
||||
|
||||
pub struct StandardClientType;
|
||||
@ -25,11 +27,12 @@ pub struct StandardClientType;
|
||||
impl ClientTypes for StandardClientType {
|
||||
type DB = DiskDB;
|
||||
type SlotClock = SystemTimeSlotClock;
|
||||
type ForkChoice = BitwiseLMDGhost<DiskDB>;
|
||||
type ForkChoice = BitwiseLMDGhost<DiskDB, Self::BeaconStateTypes>;
|
||||
type BeaconStateTypes = FoundationStateTypes;
|
||||
|
||||
fn initialise_beacon_chain(
|
||||
config: &ClientConfig,
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice>> {
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>> {
|
||||
initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name))
|
||||
}
|
||||
}
|
||||
@ -39,11 +42,12 @@ pub struct TestingClientType;
|
||||
impl ClientTypes for TestingClientType {
|
||||
type DB = MemoryDB;
|
||||
type SlotClock = SystemTimeSlotClock;
|
||||
type ForkChoice = BitwiseLMDGhost<MemoryDB>;
|
||||
type ForkChoice = BitwiseLMDGhost<MemoryDB, Self::BeaconStateTypes>;
|
||||
type BeaconStateTypes = FewValidatorsStateTypes;
|
||||
|
||||
fn initialise_beacon_chain(
|
||||
config: &ClientConfig,
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice>> {
|
||||
) -> Arc<BeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>> {
|
||||
initialise::initialise_test_beacon_chain(&config.spec, None)
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use tokio::timer::Interval;
|
||||
use types::BeaconStateTypes;
|
||||
|
||||
/// Main beacon node client service. This provides the connection and initialisation of the clients
|
||||
/// sub-services in multiple threads.
|
||||
@ -27,9 +28,9 @@ 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>>,
|
||||
_beacon_chain: Arc<BeaconChain<T::DB, T::SlotClock, T::ForkChoice, T::BeaconStateTypes>>,
|
||||
/// Reference to the network service.
|
||||
pub network: Arc<NetworkService>,
|
||||
pub network: Arc<NetworkService<T::BeaconStateTypes>>,
|
||||
/// Signal to terminate the RPC server.
|
||||
pub rpc_exit_signal: Option<Signal>,
|
||||
/// Signal to terminate the slot timer.
|
||||
@ -141,11 +142,12 @@ impl<TClientType: ClientTypes> Client<TClientType> {
|
||||
}
|
||||
}
|
||||
|
||||
fn do_state_catchup<T, U, F>(chain: &Arc<BeaconChain<T, U, F>>, log: &slog::Logger)
|
||||
fn do_state_catchup<T, U, F, B>(chain: &Arc<BeaconChain<T, U, F, B>>, log: &slog::Logger)
|
||||
where
|
||||
T: ClientDB,
|
||||
U: SlotClock,
|
||||
F: ForkChoice,
|
||||
B: BeaconStateTypes,
|
||||
{
|
||||
if let Some(genesis_height) = chain.slots_since_genesis() {
|
||||
let result = chain.catchup_state();
|
||||
|
@ -12,6 +12,7 @@ pub trait BeaconStateTypes: 'static + Default + Sync + Send + Clone + Debug + Pa
|
||||
fn spec() -> ChainSpec;
|
||||
}
|
||||
|
||||
/// Ethereum Foundation specifications.
|
||||
#[derive(Clone, PartialEq, Debug, Default)]
|
||||
pub struct FoundationStateTypes;
|
||||
|
||||
@ -45,3 +46,20 @@ impl BeaconStateTypes for FewValidatorsStateTypes {
|
||||
}
|
||||
|
||||
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsStateTypes>;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Default)]
|
||||
pub struct LighthouseTestnetStateTypes;
|
||||
|
||||
impl BeaconStateTypes for LighthouseTestnetStateTypes {
|
||||
type ShardCount = U8;
|
||||
type SlotsPerHistoricalRoot = U8192;
|
||||
type LatestRandaoMixesLength = U8192;
|
||||
type LatestActiveIndexRootsLength = U8192;
|
||||
type LatestSlashedExitLength = U8192;
|
||||
|
||||
fn spec() -> ChainSpec {
|
||||
ChainSpec::lighthouse_testnet()
|
||||
}
|
||||
}
|
||||
|
||||
pub type LighthouseTestnetBeaconState = BeaconState<LighthouseTestnetStateTypes>;
|
||||
|
@ -29,7 +29,6 @@ impl<T, N: Unsigned> FixedLenVec<T, N> {
|
||||
|
||||
impl<T: Default, N: Unsigned> From<Vec<T>> for FixedLenVec<T, N> {
|
||||
fn from(mut vec: Vec<T>) -> Self {
|
||||
dbg!(Self::capacity());
|
||||
vec.resize_with(Self::capacity(), Default::default);
|
||||
|
||||
Self {
|
||||
|
Loading…
Reference in New Issue
Block a user