Rename BeaconStateTypes to EthSpec

This commit is contained in:
Paul Hauner
2019-05-10 14:47:09 +10:00
parent 75b310a078
commit ce8ebeccbc
60 changed files with 223 additions and 235 deletions

View File

@@ -83,7 +83,7 @@ impl BlockProcessingOutcome {
}
}
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, B: BeaconStateTypes> {
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, B: EthSpec> {
pub block_store: Arc<BeaconBlockStore<T>>,
pub state_store: Arc<BeaconStateStore<T>>,
pub slot_clock: U,
@@ -100,7 +100,7 @@ where
T: ClientDB,
U: SlotClock,
F: ForkChoice,
B: BeaconStateTypes,
B: EthSpec,
{
/// Instantiate a new Beacon Chain, from genesis.
pub fn from_genesis(

View File

@@ -1,17 +1,17 @@
use serde_derive::Serialize;
use types::{BeaconBlock, BeaconState, BeaconStateTypes, Hash256};
use types::{BeaconBlock, BeaconState, EthSpec, Hash256};
/// Represents some block and it's associated state. Generally, this will be used for tracking the
/// head, justified head and finalized head.
#[derive(Clone, Serialize, PartialEq, Debug)]
pub struct CheckPoint<B: BeaconStateTypes> {
pub struct CheckPoint<B: EthSpec> {
pub beacon_block: BeaconBlock,
pub beacon_block_root: Hash256,
pub beacon_state: BeaconState<B>,
pub beacon_state_root: Hash256,
}
impl<B: BeaconStateTypes> CheckPoint<B> {
impl<B: EthSpec> CheckPoint<B> {
/// Create a new checkpoint.
pub fn new(
beacon_block: BeaconBlock,

View File

@@ -11,7 +11,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use tree_hash::TreeHash;
use types::test_utils::TestingBeaconStateBuilder;
use types::{BeaconBlock, ChainSpec, FewValidatorsStateTypes, FoundationStateTypes, Hash256};
use types::{BeaconBlock, ChainSpec, FewValidatorsEthSpec, FoundationEthSpec, Hash256};
//TODO: Correct this for prod
//TODO: Account for historical db
@@ -22,8 +22,8 @@ pub fn initialise_beacon_chain(
BeaconChain<
DiskDB,
SystemTimeSlotClock,
BitwiseLMDGhost<DiskDB, FoundationStateTypes>,
FoundationStateTypes,
BitwiseLMDGhost<DiskDB, FoundationEthSpec>,
FoundationEthSpec,
>,
> {
// set up the db
@@ -75,8 +75,8 @@ pub fn initialise_test_beacon_chain(
BeaconChain<
MemoryDB,
SystemTimeSlotClock,
BitwiseLMDGhost<MemoryDB, FewValidatorsStateTypes>,
FewValidatorsStateTypes,
BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>,
FewValidatorsEthSpec,
>,
> {
let db = Arc::new(MemoryDB::open());

View File

@@ -8,16 +8,16 @@ use slot_clock::TestingSlotClock;
use std::sync::Arc;
use tree_hash::TreeHash;
use types::*;
use types::{test_utils::TestingBeaconStateBuilder, BeaconStateTypes, FewValidatorsStateTypes};
use types::{test_utils::TestingBeaconStateBuilder, EthSpec, FewValidatorsEthSpec};
type TestingBeaconChain<B> =
BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB, FewValidatorsStateTypes>, B>;
BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>, B>;
pub struct TestingBeaconChainBuilder<B: BeaconStateTypes> {
pub struct TestingBeaconChainBuilder<B: EthSpec> {
state_builder: TestingBeaconStateBuilder<B>,
}
impl<B: BeaconStateTypes> TestingBeaconChainBuilder<B> {
impl<B: EthSpec> TestingBeaconChainBuilder<B> {
pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain<B> {
let db = Arc::new(MemoryDB::open());
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
@@ -44,7 +44,7 @@ impl<B: BeaconStateTypes> TestingBeaconChainBuilder<B> {
}
}
impl<B: BeaconStateTypes> From<TestingBeaconStateBuilder<B>> for TestingBeaconChainBuilder<B> {
impl<B: EthSpec> From<TestingBeaconStateBuilder<B>> for TestingBeaconChainBuilder<B> {
fn from(state_builder: TestingBeaconStateBuilder<B>) -> TestingBeaconChainBuilder<B> {
TestingBeaconChainBuilder { state_builder }
}

View File

@@ -10,7 +10,7 @@ use std::path::PathBuf;
use types::multiaddr::Protocol;
use types::multiaddr::ToMultiaddr;
use types::Multiaddr;
use types::{BeaconStateTypes, ChainSpec, LighthouseTestnetStateTypes};
use types::{ChainSpec, EthSpec, LighthouseTestnetEthSpec};
/// 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 = LighthouseTestnetStateTypes::spec();
let default_spec = LighthouseTestnetEthSpec::spec();
let default_net_conf = NetworkConfig::new(default_spec.boot_nodes.clone());
Self {

View File

@@ -6,17 +6,17 @@ use beacon_chain::{
slot_clock::{SlotClock, SystemTimeSlotClock},
};
use fork_choice::ForkChoice;
use types::{BeaconStateTypes, FewValidatorsStateTypes, FoundationStateTypes};
use types::{EthSpec, FewValidatorsEthSpec, FoundationEthSpec};
pub trait ClientTypes {
type DB: ClientDB + 'static;
type SlotClock: SlotClock + 'static;
type ForkChoice: ForkChoice + 'static;
type BeaconStateTypes: BeaconStateTypes + 'static;
type EthSpec: EthSpec + 'static;
fn initialise_beacon_chain(
config: &ClientConfig,
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes>;
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec>;
}
pub struct StandardClientType;
@@ -24,12 +24,12 @@ pub struct StandardClientType;
impl ClientTypes for StandardClientType {
type DB = DiskDB;
type SlotClock = SystemTimeSlotClock;
type ForkChoice = BitwiseLMDGhost<DiskDB, Self::BeaconStateTypes>;
type BeaconStateTypes = FoundationStateTypes;
type ForkChoice = BitwiseLMDGhost<DiskDB, Self::EthSpec>;
type EthSpec = FoundationEthSpec;
fn initialise_beacon_chain(
config: &ClientConfig,
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes> {
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec> {
initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name))
}
}
@@ -39,12 +39,12 @@ pub struct TestingClientType;
impl ClientTypes for TestingClientType {
type DB = MemoryDB;
type SlotClock = SystemTimeSlotClock;
type ForkChoice = BitwiseLMDGhost<MemoryDB, Self::BeaconStateTypes>;
type BeaconStateTypes = FewValidatorsStateTypes;
type ForkChoice = BitwiseLMDGhost<MemoryDB, Self::EthSpec>;
type EthSpec = FewValidatorsEthSpec;
fn initialise_beacon_chain(
config: &ClientConfig,
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::BeaconStateTypes> {
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec> {
initialise::initialise_test_beacon_chain(&config.spec, None)
}
}

View File

@@ -20,7 +20,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::runtime::TaskExecutor;
use tokio::timer::Interval;
use types::BeaconStateTypes;
use types::EthSpec;
type ArcBeaconChain<D, S, F, B> = Arc<BeaconChain<D, S, F, B>>;
@@ -30,9 +30,9 @@ pub struct Client<T: ClientTypes> {
/// Configuration for the lighthouse client.
_config: ClientConfig,
/// The beacon chain for the running client.
_beacon_chain: ArcBeaconChain<T::DB, T::SlotClock, T::ForkChoice, T::BeaconStateTypes>,
_beacon_chain: ArcBeaconChain<T::DB, T::SlotClock, T::ForkChoice, T::EthSpec>,
/// Reference to the network service.
pub network: Arc<NetworkService<T::BeaconStateTypes>>,
pub network: Arc<NetworkService<T::EthSpec>>,
/// Signal to terminate the RPC server.
pub rpc_exit_signal: Option<Signal>,
/// Signal to terminate the slot timer.
@@ -149,7 +149,7 @@ where
T: ClientDB,
U: SlotClock,
F: ForkChoice,
B: BeaconStateTypes,
B: EthSpec,
{
if let Some(genesis_height) = chain.slots_since_genesis() {
let result = chain.catchup_state();

View File

@@ -2,7 +2,7 @@ use super::STATES_DB_COLUMN as DB_COLUMN;
use super::{ClientDB, DBError};
use ssz::decode;
use std::sync::Arc;
use types::{BeaconState, BeaconStateTypes, Hash256};
use types::{BeaconState, EthSpec, Hash256};
pub struct BeaconStateStore<T>
where
@@ -19,7 +19,7 @@ impl<T: ClientDB> BeaconStateStore<T> {
Self { db }
}
pub fn get_deserialized<B: BeaconStateTypes>(
pub fn get_deserialized<B: EthSpec>(
&self,
hash: &Hash256,
) -> Result<Option<BeaconState<B>>, DBError> {

View File

@@ -236,7 +236,7 @@ mod test {
#[test]
fn ssz_encoding() {
let original = PubsubMessage::Block(BeaconBlock::empty(&FoundationStateTypes::spec()));
let original = PubsubMessage::Block(BeaconBlock::empty(&FoundationEthSpec::spec()));
let encoded = ssz_encode(&original);

View File

@@ -9,14 +9,13 @@ use beacon_chain::{
};
use eth2_libp2p::rpc::HelloMessage;
use types::{
Attestation, BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, Epoch, Hash256,
Slot,
Attestation, BeaconBlock, BeaconBlockBody, BeaconBlockHeader, Epoch, EthSpec, Hash256, Slot,
};
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome, InvalidBlock};
/// The network's API to the beacon chain.
pub trait BeaconChain<B: BeaconStateTypes>: Send + Sync {
pub trait BeaconChain<B: EthSpec>: Send + Sync {
fn get_spec(&self) -> &ChainSpec;
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>>;
@@ -70,7 +69,7 @@ where
T: ClientDB + Sized,
U: SlotClock,
F: ForkChoice,
B: BeaconStateTypes,
B: EthSpec,
{
fn get_spec(&self) -> &ChainSpec {
&self.spec

View File

@@ -13,7 +13,7 @@ use slog::{debug, warn};
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Instant;
use types::BeaconStateTypes;
use types::EthSpec;
/// Timeout for RPC requests.
// const REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
@@ -21,7 +21,7 @@ use types::BeaconStateTypes;
// const HELLO_TIMEOUT: Duration = Duration::from_secs(30);
/// Handles messages received from the network and client and organises syncing.
pub struct MessageHandler<B: BeaconStateTypes> {
pub struct MessageHandler<B: EthSpec> {
/// Currently loaded and initialised beacon chain.
_chain: Arc<BeaconChain<B>>,
/// The syncing framework.
@@ -45,7 +45,7 @@ pub enum HandlerMessage {
PubsubMessage(PeerId, Box<PubsubMessage>),
}
impl<B: BeaconStateTypes> MessageHandler<B> {
impl<B: EthSpec> MessageHandler<B> {
/// Initializes and runs the MessageHandler.
pub fn spawn(
beacon_chain: Arc<BeaconChain<B>>,

View File

@@ -13,10 +13,10 @@ use slog::{debug, info, o, trace};
use std::marker::PhantomData;
use std::sync::Arc;
use tokio::runtime::TaskExecutor;
use types::{BeaconStateTypes, Topic};
use types::{EthSpec, Topic};
/// Service that handles communication between internal services and the eth2_libp2p network service.
pub struct Service<B: BeaconStateTypes> {
pub struct Service<B: EthSpec> {
//libp2p_service: Arc<Mutex<LibP2PService>>,
_libp2p_exit: oneshot::Sender<()>,
network_send: crossbeam_channel::Sender<NetworkMessage>,
@@ -24,7 +24,7 @@ pub struct Service<B: BeaconStateTypes> {
//message_handler_send: Sender<HandlerMessage>
}
impl<B: BeaconStateTypes> Service<B> {
impl<B: EthSpec> Service<B> {
pub fn new(
beacon_chain: Arc<BeaconChain<B>>,
config: &NetworkConfig,

View File

@@ -5,7 +5,7 @@ use slog::{debug, error};
use std::sync::Arc;
use std::time::{Duration, Instant};
use tree_hash::TreeHash;
use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, Hash256, Slot};
use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, EthSpec, Hash256, Slot};
/// Provides a queue for fully and partially built `BeaconBlock`s.
///
@@ -19,7 +19,7 @@ use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, BeaconStateTypes, H
/// `BeaconBlockBody` as the key.
/// - It is possible for multiple distinct blocks to have identical `BeaconBlockBodies`. Therefore
/// we cannot use a `HashMap` keyed by the root of `BeaconBlockBody`.
pub struct ImportQueue<B: BeaconStateTypes> {
pub struct ImportQueue<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
/// Partially imported blocks, keyed by the root of `BeaconBlockBody`.
pub partials: Vec<PartialBeaconBlock>,
@@ -29,7 +29,7 @@ pub struct ImportQueue<B: BeaconStateTypes> {
log: slog::Logger,
}
impl<B: BeaconStateTypes> ImportQueue<B> {
impl<B: EthSpec> ImportQueue<B> {
/// Return a new, empty queue.
pub fn new(chain: Arc<BeaconChain<B>>, stale_time: Duration, log: slog::Logger) -> Self {
Self {

View File

@@ -9,7 +9,7 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use tree_hash::TreeHash;
use types::{Attestation, BeaconBlock, BeaconStateTypes, Epoch, Hash256, Slot};
use types::{Attestation, BeaconBlock, Epoch, EthSpec, Hash256, Slot};
/// The number of slots that we can import blocks ahead of us, before going into full Sync mode.
const SLOT_IMPORT_TOLERANCE: u64 = 100;
@@ -88,7 +88,7 @@ impl From<HelloMessage> for PeerSyncInfo {
}
}
impl<B: BeaconStateTypes> From<&Arc<BeaconChain<B>>> for PeerSyncInfo {
impl<B: EthSpec> From<&Arc<BeaconChain<B>>> for PeerSyncInfo {
fn from(chain: &Arc<BeaconChain<B>>) -> PeerSyncInfo {
Self::from(chain.hello_message())
}
@@ -103,7 +103,7 @@ pub enum SyncState {
}
/// Simple Syncing protocol.
pub struct SimpleSync<B: BeaconStateTypes> {
pub struct SimpleSync<B: EthSpec> {
/// A reference to the underlying beacon chain.
chain: Arc<BeaconChain<B>>,
/// A mapping of Peers to their respective PeerSyncInfo.
@@ -116,7 +116,7 @@ pub struct SimpleSync<B: BeaconStateTypes> {
log: slog::Logger,
}
impl<B: BeaconStateTypes> SimpleSync<B> {
impl<B: EthSpec> SimpleSync<B> {
/// Instantiate a `SimpleSync` instance, with no peers and an empty queue.
pub fn new(beacon_chain: Arc<BeaconChain<B>>, log: &slog::Logger) -> Self {
let sync_logger = log.new(o!("Service"=> "Sync"));

View File

@@ -9,15 +9,15 @@ use protos::services_grpc::AttestationService;
use slog::{error, info, trace, warn};
use ssz::{ssz_encode, Decodable};
use std::sync::Arc;
use types::{Attestation, BeaconStateTypes};
use types::{Attestation, EthSpec};
#[derive(Clone)]
pub struct AttestationServiceInstance<B: BeaconStateTypes> {
pub struct AttestationServiceInstance<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
pub log: slog::Logger,
}
impl<B: BeaconStateTypes> AttestationService for AttestationServiceInstance<B> {
impl<B: EthSpec> AttestationService for AttestationServiceInstance<B> {
/// Produce the `AttestationData` for signing by a validator.
fn produce_attestation_data(
&mut self,

View File

@@ -13,16 +13,16 @@ use slog::Logger;
use slog::{error, info, trace, warn};
use ssz::{ssz_encode, Decodable};
use std::sync::Arc;
use types::{BeaconBlock, BeaconStateTypes, Signature, Slot};
use types::{BeaconBlock, EthSpec, Signature, Slot};
#[derive(Clone)]
pub struct BeaconBlockServiceInstance<B: BeaconStateTypes> {
pub struct BeaconBlockServiceInstance<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
pub network_chan: crossbeam_channel::Sender<NetworkMessage>,
pub log: Logger,
}
impl<B: BeaconStateTypes> BeaconBlockService for BeaconBlockServiceInstance<B> {
impl<B: EthSpec> BeaconBlockService for BeaconBlockServiceInstance<B> {
/// Produce a `BeaconBlock` for signing by a validator.
fn produce_beacon_block(
&mut self,

View File

@@ -8,10 +8,10 @@ use beacon_chain::{
AttestationValidationError, BlockProductionError,
};
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome};
use types::{Attestation, AttestationData, BeaconBlock, BeaconStateTypes};
use types::{Attestation, AttestationData, BeaconBlock, EthSpec};
/// The RPC's API to the beacon chain.
pub trait BeaconChain<B: BeaconStateTypes>: Send + Sync {
pub trait BeaconChain<B: EthSpec>: Send + Sync {
fn get_spec(&self) -> &ChainSpec;
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>>;
@@ -39,7 +39,7 @@ where
T: ClientDB + Sized,
U: SlotClock,
F: ForkChoice,
B: BeaconStateTypes,
B: EthSpec,
{
fn get_spec(&self) -> &ChainSpec {
&self.spec

View File

@@ -5,15 +5,15 @@ use protos::services::{Empty, Fork, NodeInfoResponse};
use protos::services_grpc::BeaconNodeService;
use slog::{trace, warn};
use std::sync::Arc;
use types::BeaconStateTypes;
use types::EthSpec;
#[derive(Clone)]
pub struct BeaconNodeServiceInstance<B: BeaconStateTypes> {
pub struct BeaconNodeServiceInstance<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
pub log: slog::Logger,
}
impl<B: BeaconStateTypes> BeaconNodeService for BeaconNodeServiceInstance<B> {
impl<B: EthSpec> BeaconNodeService for BeaconNodeServiceInstance<B> {
/// Provides basic node information.
fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink<NodeInfoResponse>) {
trace!(self.log, "Node info requested via RPC");

View File

@@ -21,9 +21,9 @@ use protos::services_grpc::{
use slog::{info, o, warn};
use std::sync::Arc;
use tokio::runtime::TaskExecutor;
use types::BeaconStateTypes;
use types::EthSpec;
pub fn start_server<B: BeaconStateTypes>(
pub fn start_server<B: EthSpec>(
config: &RPCConfig,
executor: &TaskExecutor,
network_chan: crossbeam_channel::Sender<NetworkMessage>,

View File

@@ -7,16 +7,16 @@ use protos::services_grpc::ValidatorService;
use slog::{trace, warn};
use ssz::decode;
use std::sync::Arc;
use types::{BeaconStateTypes, Epoch, RelativeEpoch};
use types::{Epoch, EthSpec, RelativeEpoch};
#[derive(Clone)]
pub struct ValidatorServiceInstance<B: BeaconStateTypes> {
pub struct ValidatorServiceInstance<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
pub log: slog::Logger,
}
//TODO: Refactor Errors
impl<B: BeaconStateTypes> ValidatorService for ValidatorServiceInstance<B> {
impl<B: EthSpec> ValidatorService for ValidatorServiceInstance<B> {
/// For a list of validator public keys, this function returns the slot at which each
/// validator must propose a block, attest to a shard, their shard committee and the shard they
/// need to attest to.