Use E for EthSpec trait, instead of B

This commit is contained in:
Paul Hauner 2019-05-13 14:44:43 +10:00
parent afa8fff31a
commit fcabef91da
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
20 changed files with 110 additions and 110 deletions

View File

@ -83,31 +83,31 @@ impl BlockProcessingOutcome {
}
}
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, B: EthSpec> {
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, E: EthSpec> {
pub block_store: Arc<BeaconBlockStore<T>>,
pub state_store: Arc<BeaconStateStore<T>>,
pub slot_clock: U,
pub op_pool: OperationPool<B>,
canonical_head: RwLock<CheckPoint<B>>,
finalized_head: RwLock<CheckPoint<B>>,
pub state: RwLock<BeaconState<B>>,
pub op_pool: OperationPool<E>,
canonical_head: RwLock<CheckPoint<E>>,
finalized_head: RwLock<CheckPoint<E>>,
pub state: RwLock<BeaconState<E>>,
pub spec: ChainSpec,
pub fork_choice: RwLock<F>,
}
impl<T, U, F, B> BeaconChain<T, U, F, B>
impl<T, U, F, E> BeaconChain<T, U, F, E>
where
T: ClientDB,
U: SlotClock,
F: ForkChoice,
B: EthSpec,
E: EthSpec,
{
/// Instantiate a new Beacon Chain, from genesis.
pub fn from_genesis(
state_store: Arc<BeaconStateStore<T>>,
block_store: Arc<BeaconBlockStore<T>>,
slot_clock: U,
mut genesis_state: BeaconState<B>,
mut genesis_state: BeaconState<E>,
genesis_block: BeaconBlock,
spec: ChainSpec,
fork_choice: F,
@ -230,7 +230,7 @@ where
Err(BeaconStateError::SlotOutOfBounds) => {
// Read the earliest historic state in the current slot.
let earliest_historic_slot =
state.slot - Slot::from(B::SlotsPerHistoricalRoot::to_usize());
state.slot - Slot::from(E::SlotsPerHistoricalRoot::to_usize());
// Load the earlier state from disk.
let new_state_root = state.get_state_root(earliest_historic_slot)?;
@ -270,7 +270,7 @@ where
&self,
new_beacon_block: BeaconBlock,
new_beacon_block_root: Hash256,
new_beacon_state: BeaconState<B>,
new_beacon_state: BeaconState<E>,
new_beacon_state_root: Hash256,
) {
debug!(
@ -292,7 +292,7 @@ where
/// It is important to note that the `beacon_state` returned may not match the present slot. It
/// is the state as it was when the head block was received, which could be some slots prior to
/// now.
pub fn head(&self) -> RwLockReadGuard<CheckPoint<B>> {
pub fn head(&self) -> RwLockReadGuard<CheckPoint<E>> {
self.canonical_head.read()
}
@ -302,7 +302,7 @@ where
/// state and calling `catchup_state` as it will not result in an old state being installed and
/// then having it iteratively updated -- in such a case it's possible for another thread to
/// find the state at an old slot.
pub fn update_state(&self, mut state: BeaconState<B>) -> Result<(), Error> {
pub fn update_state(&self, mut state: BeaconState<E>) -> Result<(), Error> {
let present_slot = match self.slot_clock.present_slot() {
Ok(Some(slot)) => slot,
_ => return Err(Error::UnableToReadSlot),
@ -357,7 +357,7 @@ where
&self,
new_beacon_block: BeaconBlock,
new_beacon_block_root: Hash256,
new_beacon_state: BeaconState<B>,
new_beacon_state: BeaconState<E>,
new_beacon_state_root: Hash256,
) {
let mut finalized_head = self.finalized_head.write();
@ -371,7 +371,7 @@ where
/// Returns a read-lock guarded `CheckPoint` struct for reading the justified head (as chosen,
/// indirectly, by the fork-choice rule).
pub fn finalized_head(&self) -> RwLockReadGuard<CheckPoint<B>> {
pub fn finalized_head(&self) -> RwLockReadGuard<CheckPoint<E>> {
self.finalized_head.read()
}
@ -664,7 +664,7 @@ where
pub fn produce_block(
&self,
randao_reveal: Signature,
) -> Result<(BeaconBlock, BeaconState<B>), BlockProductionError> {
) -> Result<(BeaconBlock, BeaconState<E>), BlockProductionError> {
debug!("Producing block at slot {}...", self.state.read().slot);
let mut state = self.state.read().clone();
@ -759,7 +759,7 @@ where
///
/// This could be a very expensive operation and should only be done in testing/analysis
/// activities.
pub fn chain_dump(&self) -> Result<Vec<CheckPoint<B>>, Error> {
pub fn chain_dump(&self) -> Result<Vec<CheckPoint<E>>, Error> {
let mut dump = vec![];
let mut last_slot = CheckPoint {

View File

@ -4,19 +4,19 @@ 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: EthSpec> {
pub struct CheckPoint<E: EthSpec> {
pub beacon_block: BeaconBlock,
pub beacon_block_root: Hash256,
pub beacon_state: BeaconState<B>,
pub beacon_state: BeaconState<E>,
pub beacon_state_root: Hash256,
}
impl<B: EthSpec> CheckPoint<B> {
impl<E: EthSpec> CheckPoint<E> {
/// Create a new checkpoint.
pub fn new(
beacon_block: BeaconBlock,
beacon_block_root: Hash256,
beacon_state: BeaconState<B>,
beacon_state: BeaconState<E>,
beacon_state_root: Hash256,
) -> Self {
Self {
@ -32,7 +32,7 @@ impl<B: EthSpec> CheckPoint<B> {
&mut self,
beacon_block: BeaconBlock,
beacon_block_root: Hash256,
beacon_state: BeaconState<B>,
beacon_state: BeaconState<E>,
beacon_state_root: Hash256,
) {
self.beacon_block = beacon_block;

View File

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

View File

@ -144,12 +144,12 @@ impl<TClientType: ClientTypes> Client<TClientType> {
}
}
fn do_state_catchup<T, U, F, B>(chain: &Arc<BeaconChain<T, U, F, B>>, log: &slog::Logger)
fn do_state_catchup<T, U, F, E>(chain: &Arc<BeaconChain<T, U, F, E>>, log: &slog::Logger)
where
T: ClientDB,
U: SlotClock,
F: ForkChoice,
B: EthSpec,
E: EthSpec,
{
if let Some(genesis_height) = chain.slots_since_genesis() {
let result = chain.catchup_state();

View File

@ -19,14 +19,14 @@ impl<T: ClientDB> BeaconStateStore<T> {
Self { db }
}
pub fn get_deserialized<B: EthSpec>(
pub fn get_deserialized<E: EthSpec>(
&self,
hash: &Hash256,
) -> Result<Option<BeaconState<B>>, DBError> {
) -> Result<Option<BeaconState<E>>, DBError> {
match self.get(&hash)? {
None => Ok(None),
Some(ssz) => {
let state = decode::<BeaconState<B>>(&ssz).map_err(|_| DBError {
let state = decode::<BeaconState<E>>(&ssz).map_err(|_| DBError {
message: "Bad State SSZ.".to_string(),
})?;
Ok(Some(state))

View File

@ -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()
}

View File

@ -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,

View File

@ -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,

View File

@ -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![],

View File

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

View File

@ -12,12 +12,12 @@ use std::sync::Arc;
use types::{Attestation, EthSpec};
#[derive(Clone)]
pub struct AttestationServiceInstance<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
pub struct AttestationServiceInstance<E: EthSpec> {
pub chain: Arc<BeaconChain<E>>,
pub log: slog::Logger,
}
impl<B: EthSpec> AttestationService for AttestationServiceInstance<B> {
impl<E: EthSpec> AttestationService for AttestationServiceInstance<E> {
/// Produce the `AttestationData` for signing by a validator.
fn produce_attestation_data(
&mut self,

View File

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

View File

@ -11,12 +11,12 @@ pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome};
use types::{Attestation, AttestationData, BeaconBlock, EthSpec};
/// The RPC'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 get_mut_state(&self) -> RwLockWriteGuard<BeaconState<B>>;
fn get_mut_state(&self) -> RwLockWriteGuard<BeaconState<E>>;
fn process_block(&self, block: BeaconBlock)
-> Result<BlockProcessingOutcome, BeaconChainError>;
@ -24,7 +24,7 @@ pub trait BeaconChain<B: EthSpec>: Send + Sync {
fn produce_block(
&self,
randao_reveal: Signature,
) -> Result<(BeaconBlock, BeaconState<B>), BlockProductionError>;
) -> Result<(BeaconBlock, BeaconState<E>), BlockProductionError>;
fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, BeaconChainError>;
@ -34,22 +34,22 @@ pub trait BeaconChain<B: EthSpec>: Send + Sync {
) -> Result<(), AttestationValidationError>;
}
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()
}
fn get_mut_state(&self) -> RwLockWriteGuard<BeaconState<B>> {
fn get_mut_state(&self) -> RwLockWriteGuard<BeaconState<E>> {
self.state.write()
}
@ -63,7 +63,7 @@ where
fn produce_block(
&self,
randao_reveal: Signature,
) -> Result<(BeaconBlock, BeaconState<B>), BlockProductionError> {
) -> Result<(BeaconBlock, BeaconState<E>), BlockProductionError> {
self.produce_block(randao_reveal)
}

View File

@ -8,12 +8,12 @@ use std::sync::Arc;
use types::EthSpec;
#[derive(Clone)]
pub struct BeaconNodeServiceInstance<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
pub struct BeaconNodeServiceInstance<E: EthSpec> {
pub chain: Arc<BeaconChain<E>>,
pub log: slog::Logger,
}
impl<B: EthSpec> BeaconNodeService for BeaconNodeServiceInstance<B> {
impl<E: EthSpec> BeaconNodeService for BeaconNodeServiceInstance<E> {
/// 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

@ -23,11 +23,11 @@ use std::sync::Arc;
use tokio::runtime::TaskExecutor;
use types::EthSpec;
pub fn start_server<B: EthSpec>(
pub fn start_server<E: EthSpec>(
config: &RPCConfig,
executor: &TaskExecutor,
network_chan: crossbeam_channel::Sender<NetworkMessage>,
beacon_chain: Arc<BeaconChain<B>>,
beacon_chain: Arc<BeaconChain<E>>,
log: &slog::Logger,
) -> exit_future::Signal {
let log = log.new(o!("Service"=>"RPC"));

View File

@ -10,13 +10,13 @@ use std::sync::Arc;
use types::{Epoch, EthSpec, RelativeEpoch};
#[derive(Clone)]
pub struct ValidatorServiceInstance<B: EthSpec> {
pub chain: Arc<BeaconChain<B>>,
pub struct ValidatorServiceInstance<E: EthSpec> {
pub chain: Arc<BeaconChain<E>>,
pub log: slog::Logger,
}
//TODO: Refactor Errors
impl<B: EthSpec> ValidatorService for ValidatorServiceInstance<B> {
impl<E: EthSpec> ValidatorService for ValidatorServiceInstance<E> {
/// 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.

View File

@ -34,7 +34,7 @@ fn power_of_2_below(x: u64) -> u64 {
}
/// Stores the necessary data structures to run the optimised bitwise lmd ghost algorithm.
pub struct BitwiseLMDGhost<T: ClientDB + Sized, B> {
pub struct BitwiseLMDGhost<T: ClientDB + Sized, E> {
/// A cache of known ancestors at given heights for a specific block.
//TODO: Consider FnvHashMap
cache: HashMap<CacheKey<u64>, Hash256>,
@ -51,10 +51,10 @@ pub struct BitwiseLMDGhost<T: ClientDB + Sized, B> {
/// State storage access.
state_store: Arc<BeaconStateStore<T>>,
max_known_height: SlotHeight,
_phantom: PhantomData<B>,
_phantom: PhantomData<E>,
}
impl<T, B: EthSpec> BitwiseLMDGhost<T, B>
impl<T, E: EthSpec> BitwiseLMDGhost<T, E>
where
T: ClientDB + Sized,
{
@ -88,7 +88,7 @@ where
// build a hashmap of block_hash to weighted votes
let mut latest_votes: HashMap<Hash256, u64> = HashMap::new();
// gets the current weighted votes
let current_state: BeaconState<B> = self
let current_state: BeaconState<E> = self
.state_store
.get_deserialized(&state_root)?
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?;
@ -243,7 +243,7 @@ where
}
}
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for BitwiseLMDGhost<T, B> {
impl<T: ClientDB + Sized, E: EthSpec> ForkChoice for BitwiseLMDGhost<T, E> {
fn add_block(
&mut self,
block: &BeaconBlock,

View File

@ -34,7 +34,7 @@ fn power_of_2_below(x: u64) -> u64 {
}
/// Stores the necessary data structures to run the optimised lmd ghost algorithm.
pub struct OptimizedLMDGhost<T: ClientDB + Sized, B> {
pub struct OptimizedLMDGhost<T: ClientDB + Sized, E> {
/// A cache of known ancestors at given heights for a specific block.
//TODO: Consider FnvHashMap
cache: HashMap<CacheKey<u64>, Hash256>,
@ -51,10 +51,10 @@ pub struct OptimizedLMDGhost<T: ClientDB + Sized, B> {
/// State storage access.
state_store: Arc<BeaconStateStore<T>>,
max_known_height: SlotHeight,
_phantom: PhantomData<B>,
_phantom: PhantomData<E>,
}
impl<T, B: EthSpec> OptimizedLMDGhost<T, B>
impl<T, E: EthSpec> OptimizedLMDGhost<T, E>
where
T: ClientDB + Sized,
{
@ -88,7 +88,7 @@ where
// build a hashmap of block_hash to weighted votes
let mut latest_votes: HashMap<Hash256, u64> = HashMap::new();
// gets the current weighted votes
let current_state: BeaconState<B> = self
let current_state: BeaconState<E> = self
.state_store
.get_deserialized(&state_root)?
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?;
@ -214,7 +214,7 @@ where
}
}
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for OptimizedLMDGhost<T, B> {
impl<T: ClientDB + Sized, E: EthSpec> ForkChoice for OptimizedLMDGhost<T, E> {
fn add_block(
&mut self,
block: &BeaconBlock,

View File

@ -13,7 +13,7 @@ use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot};
//TODO: Pruning and syncing
pub struct SlowLMDGhost<T: ClientDB + Sized, B> {
pub struct SlowLMDGhost<T: ClientDB + Sized, E> {
/// The latest attestation targets as a map of validator index to block hash.
//TODO: Could this be a fixed size vec
latest_attestation_targets: HashMap<u64, Hash256>,
@ -23,10 +23,10 @@ pub struct SlowLMDGhost<T: ClientDB + Sized, B> {
block_store: Arc<BeaconBlockStore<T>>,
/// State storage access.
state_store: Arc<BeaconStateStore<T>>,
_phantom: PhantomData<B>,
_phantom: PhantomData<E>,
}
impl<T, B: EthSpec> SlowLMDGhost<T, B>
impl<T, E: EthSpec> SlowLMDGhost<T, E>
where
T: ClientDB + Sized,
{
@ -57,7 +57,7 @@ where
// build a hashmap of block_hash to weighted votes
let mut latest_votes: HashMap<Hash256, u64> = HashMap::new();
// gets the current weighted votes
let current_state: BeaconState<B> = self
let current_state: BeaconState<E> = self
.state_store
.get_deserialized(&state_root)?
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?;
@ -108,7 +108,7 @@ where
}
}
impl<T: ClientDB + Sized, B: EthSpec> ForkChoice for SlowLMDGhost<T, B> {
impl<T: ClientDB + Sized, E: EthSpec> ForkChoice for SlowLMDGhost<T, E> {
/// Process when a block is added
fn add_block(
&mut self,

View File

@ -539,10 +539,10 @@ where
/// The keys in the map should be validator indices, which will be looked up
/// in the state's validator registry and then passed to `prune_if`.
/// Entries for unknown validators will be kept.
fn prune_validator_hash_map<T, F, B: EthSpec>(
fn prune_validator_hash_map<T, F, E: EthSpec>(
map: &mut HashMap<u64, T>,
prune_if: F,
finalized_state: &BeaconState<B>,
finalized_state: &BeaconState<E>,
) where
F: Fn(&Validator) -> bool,
{
@ -722,12 +722,12 @@ mod tests {
/// Create a signed attestation for use in tests.
/// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`.
fn signed_attestation<R: std::slice::SliceIndex<[usize], Output = [usize]>, B: EthSpec>(
fn signed_attestation<R: std::slice::SliceIndex<[usize], Output = [usize]>, E: EthSpec>(
committee: &CrosslinkCommittee,
keypairs: &[Keypair],
signing_range: R,
slot: Slot,
state: &BeaconState<B>,
state: &BeaconState<E>,
spec: &ChainSpec,
extra_signer: Option<usize>,
) -> Attestation {
@ -754,10 +754,10 @@ mod tests {
}
/// Test state for attestation-related tests.
fn attestation_test_state<B: EthSpec>(
fn attestation_test_state<E: EthSpec>(
num_committees: usize,
) -> (BeaconState<B>, Vec<Keypair>, ChainSpec) {
let spec = B::spec();
) -> (BeaconState<E>, Vec<Keypair>, ChainSpec) {
let spec = E::spec();
let num_validators =
num_committees * (spec.slots_per_epoch * spec.target_committee_size) as usize;
@ -775,9 +775,9 @@ mod tests {
}
/// Set the latest crosslink in the state to match the attestation.
fn fake_latest_crosslink<B: EthSpec>(
fn fake_latest_crosslink<E: EthSpec>(
att: &Attestation,
state: &mut BeaconState<B>,
state: &mut BeaconState<E>,
spec: &ChainSpec,
) {
state.latest_crosslinks[att.data.shard as usize] = Crosslink {