mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 22:34:45 +00:00
Add first changes to syncing logic
- Adds testing framework - Breaks out new `NetworkContext` object
This commit is contained in:
@@ -7,6 +7,8 @@ use beacon_chain::{
|
||||
types::{BeaconState, ChainSpec},
|
||||
CheckPoint,
|
||||
};
|
||||
use libp2p::HelloMessage;
|
||||
use types::{Epoch, Hash256, Slot};
|
||||
|
||||
/// The network's API to the beacon chain.
|
||||
pub trait BeaconChain: Send + Sync {
|
||||
@@ -14,9 +16,19 @@ pub trait BeaconChain: Send + Sync {
|
||||
|
||||
fn get_state(&self) -> RwLockReadGuard<BeaconState>;
|
||||
|
||||
fn slot(&self) -> Slot;
|
||||
|
||||
fn head(&self) -> RwLockReadGuard<CheckPoint>;
|
||||
|
||||
fn best_slot(&self) -> Slot;
|
||||
|
||||
fn best_block_root(&self) -> Hash256;
|
||||
|
||||
fn finalized_head(&self) -> RwLockReadGuard<CheckPoint>;
|
||||
|
||||
fn finalized_epoch(&self) -> Epoch;
|
||||
|
||||
fn hello_message(&self) -> HelloMessage;
|
||||
}
|
||||
|
||||
impl<T, U, F> BeaconChain for RawBeaconChain<T, U, F>
|
||||
@@ -33,11 +45,40 @@ where
|
||||
self.state.read()
|
||||
}
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
self.get_state().slot
|
||||
}
|
||||
|
||||
fn head(&self) -> RwLockReadGuard<CheckPoint> {
|
||||
self.head()
|
||||
}
|
||||
|
||||
fn finalized_epoch(&self) -> Epoch {
|
||||
self.get_state().finalized_epoch
|
||||
}
|
||||
|
||||
fn finalized_head(&self) -> RwLockReadGuard<CheckPoint> {
|
||||
self.finalized_head()
|
||||
}
|
||||
|
||||
fn best_slot(&self) -> Slot {
|
||||
self.head().beacon_block.slot
|
||||
}
|
||||
|
||||
fn best_block_root(&self) -> Hash256 {
|
||||
self.head().beacon_block_root
|
||||
}
|
||||
|
||||
fn hello_message(&self) -> HelloMessage {
|
||||
let spec = self.get_spec();
|
||||
let state = self.get_state();
|
||||
|
||||
HelloMessage {
|
||||
network_id: spec.network_id,
|
||||
latest_finalized_root: state.finalized_root,
|
||||
latest_finalized_epoch: state.finalized_epoch,
|
||||
best_root: self.best_block_root(),
|
||||
best_slot: self.best_slot(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user