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

@@ -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"));