mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Add untested minimum viable block processing
This commit is contained in:
@@ -1,33 +1,27 @@
|
||||
extern crate db;
|
||||
extern crate types;
|
||||
extern crate naive_fork_choice;
|
||||
extern crate state_transition;
|
||||
extern crate ssz;
|
||||
extern crate ssz_helpers;
|
||||
extern crate types;
|
||||
extern crate validation;
|
||||
extern crate validator_induction;
|
||||
extern crate validator_shuffling;
|
||||
|
||||
mod stores;
|
||||
mod block_context;
|
||||
mod block_processing;
|
||||
mod maps;
|
||||
mod genesis;
|
||||
mod maps;
|
||||
mod transition;
|
||||
mod stores;
|
||||
|
||||
use db::ClientDB;
|
||||
use genesis::genesis_states;
|
||||
use maps::{
|
||||
generate_attester_and_proposer_maps,
|
||||
AttesterAndProposerMapError,
|
||||
};
|
||||
use maps::{generate_attester_and_proposer_maps, AttesterAndProposerMapError};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use stores::BeaconChainStore;
|
||||
use types::{
|
||||
ActiveState,
|
||||
AttesterMap,
|
||||
ChainConfig,
|
||||
CrystallizedState,
|
||||
Hash256,
|
||||
ProposerMap,
|
||||
};
|
||||
use types::{ActiveState, AttesterMap, ChainConfig, CrystallizedState, Hash256, ProposerMap};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BeaconChainError {
|
||||
@@ -37,12 +31,6 @@ pub enum BeaconChainError {
|
||||
DBError(String),
|
||||
}
|
||||
|
||||
impl From<AttesterAndProposerMapError> for BeaconChainError {
|
||||
fn from(e: AttesterAndProposerMapError) -> BeaconChainError {
|
||||
BeaconChainError::UnableToGenerateMaps(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BeaconChain<T: ClientDB + Sized> {
|
||||
/// The last slot which has been finalized, this is common to all forks.
|
||||
pub last_finalized_slot: u64,
|
||||
@@ -63,11 +51,10 @@ pub struct BeaconChain<T: ClientDB + Sized> {
|
||||
}
|
||||
|
||||
impl<T> BeaconChain<T>
|
||||
where T: ClientDB + Sized
|
||||
where
|
||||
T: ClientDB + Sized,
|
||||
{
|
||||
pub fn new(store: BeaconChainStore<T>, config: ChainConfig)
|
||||
-> Result<Self, BeaconChainError>
|
||||
{
|
||||
pub fn new(store: BeaconChainStore<T>, config: ChainConfig) -> Result<Self, BeaconChainError> {
|
||||
if config.initial_validators.is_empty() {
|
||||
return Err(BeaconChainError::InsufficientValidators);
|
||||
}
|
||||
@@ -82,15 +69,18 @@ impl<T> BeaconChain<T>
|
||||
let mut attester_proposer_maps = HashMap::new();
|
||||
|
||||
let (attester_map, proposer_map) = generate_attester_and_proposer_maps(
|
||||
&crystallized_state.shard_and_committee_for_slots, 0)?;
|
||||
&crystallized_state.shard_and_committee_for_slots,
|
||||
0,
|
||||
)?;
|
||||
|
||||
active_states.insert(canonical_latest_block_hash, active_state);
|
||||
crystallized_states.insert(canonical_latest_block_hash, crystallized_state);
|
||||
attester_proposer_maps.insert(
|
||||
canonical_latest_block_hash,
|
||||
(Arc::new(attester_map), Arc::new(proposer_map)));
|
||||
(Arc::new(attester_map), Arc::new(proposer_map)),
|
||||
);
|
||||
|
||||
Ok(Self{
|
||||
Ok(Self {
|
||||
last_finalized_slot: 0,
|
||||
head_block_hashes,
|
||||
canonical_head_block_hash,
|
||||
@@ -102,19 +92,24 @@ impl<T> BeaconChain<T>
|
||||
})
|
||||
}
|
||||
|
||||
pub fn canonical_block_hash(self) -> Hash256 {
|
||||
pub fn canonical_block_hash(&self) -> Hash256 {
|
||||
self.head_block_hashes[self.canonical_head_block_hash]
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AttesterAndProposerMapError> for BeaconChainError {
|
||||
fn from(e: AttesterAndProposerMapError) -> BeaconChainError {
|
||||
BeaconChainError::UnableToGenerateMaps(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use super::*;
|
||||
use types::ValidatorRegistration;
|
||||
use db::MemoryDB;
|
||||
use db::stores::*;
|
||||
use db::MemoryDB;
|
||||
use std::sync::Arc;
|
||||
use types::ValidatorRegistration;
|
||||
|
||||
#[test]
|
||||
fn test_new_chain() {
|
||||
@@ -129,7 +124,9 @@ mod tests {
|
||||
};
|
||||
|
||||
for _ in 0..config.cycle_length * 2 {
|
||||
config.initial_validators.push(ValidatorRegistration::random())
|
||||
config
|
||||
.initial_validators
|
||||
.push(ValidatorRegistration::random())
|
||||
}
|
||||
|
||||
let chain = BeaconChain::new(store, config.clone()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user