mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Use E for EthSpec trait, instead of B
This commit is contained in:
@@ -15,14 +15,14 @@ use types::{
|
||||
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome, InvalidBlock};
|
||||
|
||||
/// The network's API to the beacon chain.
|
||||
pub trait BeaconChain<B: EthSpec>: Send + Sync {
|
||||
pub trait BeaconChain<E: EthSpec>: Send + Sync {
|
||||
fn get_spec(&self) -> &ChainSpec;
|
||||
|
||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>>;
|
||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<E>>;
|
||||
|
||||
fn slot(&self) -> Slot;
|
||||
|
||||
fn head(&self) -> RwLockReadGuard<CheckPoint<B>>;
|
||||
fn head(&self) -> RwLockReadGuard<CheckPoint<E>>;
|
||||
|
||||
fn get_block(&self, block_root: &Hash256) -> Result<Option<BeaconBlock>, BeaconChainError>;
|
||||
|
||||
@@ -30,7 +30,7 @@ pub trait BeaconChain<B: EthSpec>: Send + Sync {
|
||||
|
||||
fn best_block_root(&self) -> Hash256;
|
||||
|
||||
fn finalized_head(&self) -> RwLockReadGuard<CheckPoint<B>>;
|
||||
fn finalized_head(&self) -> RwLockReadGuard<CheckPoint<E>>;
|
||||
|
||||
fn finalized_epoch(&self) -> Epoch;
|
||||
|
||||
@@ -64,18 +64,18 @@ pub trait BeaconChain<B: EthSpec>: Send + Sync {
|
||||
fn is_new_block_root(&self, beacon_block_root: &Hash256) -> Result<bool, BeaconChainError>;
|
||||
}
|
||||
|
||||
impl<T, U, F, B> BeaconChain<B> for RawBeaconChain<T, U, F, B>
|
||||
impl<T, U, F, E> BeaconChain<E> for RawBeaconChain<T, U, F, E>
|
||||
where
|
||||
T: ClientDB + Sized,
|
||||
U: SlotClock,
|
||||
F: ForkChoice,
|
||||
B: EthSpec,
|
||||
E: EthSpec,
|
||||
{
|
||||
fn get_spec(&self) -> &ChainSpec {
|
||||
&self.spec
|
||||
}
|
||||
|
||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<B>> {
|
||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<E>> {
|
||||
self.state.read()
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ where
|
||||
self.get_state().slot
|
||||
}
|
||||
|
||||
fn head(&self) -> RwLockReadGuard<CheckPoint<B>> {
|
||||
fn head(&self) -> RwLockReadGuard<CheckPoint<E>> {
|
||||
self.head()
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ where
|
||||
self.get_state().finalized_epoch
|
||||
}
|
||||
|
||||
fn finalized_head(&self) -> RwLockReadGuard<CheckPoint<B>> {
|
||||
fn finalized_head(&self) -> RwLockReadGuard<CheckPoint<E>> {
|
||||
self.finalized_head()
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ use types::EthSpec;
|
||||
// const HELLO_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// Handles messages received from the network and client and organises syncing.
|
||||
pub struct MessageHandler<B: EthSpec> {
|
||||
pub struct MessageHandler<E: EthSpec> {
|
||||
/// Currently loaded and initialised beacon chain.
|
||||
_chain: Arc<BeaconChain<B>>,
|
||||
_chain: Arc<BeaconChain<E>>,
|
||||
/// The syncing framework.
|
||||
sync: SimpleSync<B>,
|
||||
sync: SimpleSync<E>,
|
||||
/// The context required to send messages to, and process messages from peers.
|
||||
network_context: NetworkContext,
|
||||
/// The `MessageHandler` logger.
|
||||
@@ -45,10 +45,10 @@ pub enum HandlerMessage {
|
||||
PubsubMessage(PeerId, Box<PubsubMessage>),
|
||||
}
|
||||
|
||||
impl<B: EthSpec> MessageHandler<B> {
|
||||
impl<E: EthSpec> MessageHandler<E> {
|
||||
/// Initializes and runs the MessageHandler.
|
||||
pub fn spawn(
|
||||
beacon_chain: Arc<BeaconChain<B>>,
|
||||
beacon_chain: Arc<BeaconChain<E>>,
|
||||
network_send: crossbeam_channel::Sender<NetworkMessage>,
|
||||
executor: &tokio::runtime::TaskExecutor,
|
||||
log: slog::Logger,
|
||||
|
||||
@@ -16,17 +16,17 @@ use tokio::runtime::TaskExecutor;
|
||||
use types::{EthSpec, Topic};
|
||||
|
||||
/// Service that handles communication between internal services and the eth2_libp2p network service.
|
||||
pub struct Service<B: EthSpec> {
|
||||
pub struct Service<E: EthSpec> {
|
||||
//libp2p_service: Arc<Mutex<LibP2PService>>,
|
||||
_libp2p_exit: oneshot::Sender<()>,
|
||||
network_send: crossbeam_channel::Sender<NetworkMessage>,
|
||||
_phantom: PhantomData<B>, //message_handler: MessageHandler,
|
||||
_phantom: PhantomData<E>, //message_handler: MessageHandler,
|
||||
//message_handler_send: Sender<HandlerMessage>
|
||||
}
|
||||
|
||||
impl<B: EthSpec> Service<B> {
|
||||
impl<E: EthSpec> Service<E> {
|
||||
pub fn new(
|
||||
beacon_chain: Arc<BeaconChain<B>>,
|
||||
beacon_chain: Arc<BeaconChain<E>>,
|
||||
config: &NetworkConfig,
|
||||
executor: &TaskExecutor,
|
||||
log: slog::Logger,
|
||||
|
||||
@@ -19,8 +19,8 @@ use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, EthSpec, Hash256, S
|
||||
/// `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: EthSpec> {
|
||||
pub chain: Arc<BeaconChain<B>>,
|
||||
pub struct ImportQueue<E: EthSpec> {
|
||||
pub chain: Arc<BeaconChain<E>>,
|
||||
/// Partially imported blocks, keyed by the root of `BeaconBlockBody`.
|
||||
pub partials: Vec<PartialBeaconBlock>,
|
||||
/// Time before a queue entry is considered state.
|
||||
@@ -29,9 +29,9 @@ pub struct ImportQueue<B: EthSpec> {
|
||||
log: slog::Logger,
|
||||
}
|
||||
|
||||
impl<B: EthSpec> ImportQueue<B> {
|
||||
impl<E: EthSpec> ImportQueue<E> {
|
||||
/// Return a new, empty queue.
|
||||
pub fn new(chain: Arc<BeaconChain<B>>, stale_time: Duration, log: slog::Logger) -> Self {
|
||||
pub fn new(chain: Arc<BeaconChain<E>>, stale_time: Duration, log: slog::Logger) -> Self {
|
||||
Self {
|
||||
chain,
|
||||
partials: vec![],
|
||||
|
||||
@@ -88,8 +88,8 @@ impl From<HelloMessage> for PeerSyncInfo {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: EthSpec> From<&Arc<BeaconChain<B>>> for PeerSyncInfo {
|
||||
fn from(chain: &Arc<BeaconChain<B>>) -> PeerSyncInfo {
|
||||
impl<E: EthSpec> From<&Arc<BeaconChain<E>>> for PeerSyncInfo {
|
||||
fn from(chain: &Arc<BeaconChain<E>>) -> PeerSyncInfo {
|
||||
Self::from(chain.hello_message())
|
||||
}
|
||||
}
|
||||
@@ -103,22 +103,22 @@ pub enum SyncState {
|
||||
}
|
||||
|
||||
/// Simple Syncing protocol.
|
||||
pub struct SimpleSync<B: EthSpec> {
|
||||
pub struct SimpleSync<E: EthSpec> {
|
||||
/// A reference to the underlying beacon chain.
|
||||
chain: Arc<BeaconChain<B>>,
|
||||
chain: Arc<BeaconChain<E>>,
|
||||
/// A mapping of Peers to their respective PeerSyncInfo.
|
||||
known_peers: HashMap<PeerId, PeerSyncInfo>,
|
||||
/// A queue to allow importing of blocks
|
||||
import_queue: ImportQueue<B>,
|
||||
import_queue: ImportQueue<E>,
|
||||
/// The current state of the syncing protocol.
|
||||
state: SyncState,
|
||||
/// Sync logger.
|
||||
log: slog::Logger,
|
||||
}
|
||||
|
||||
impl<B: EthSpec> SimpleSync<B> {
|
||||
impl<E: EthSpec> SimpleSync<E> {
|
||||
/// Instantiate a `SimpleSync` instance, with no peers and an empty queue.
|
||||
pub fn new(beacon_chain: Arc<BeaconChain<B>>, log: &slog::Logger) -> Self {
|
||||
pub fn new(beacon_chain: Arc<BeaconChain<E>>, log: &slog::Logger) -> Self {
|
||||
let sync_logger = log.new(o!("Service"=> "Sync"));
|
||||
|
||||
let queue_item_stale_time = Duration::from_secs(QUEUE_STALE_SECS);
|
||||
|
||||
Reference in New Issue
Block a user