Fix fork_choice
release-only tests
This commit is contained in:
parent
77c4b6eafe
commit
be9f8aa0bf
@ -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: BeaconStateTypes> {
|
||||
pub struct BitwiseLMDGhost<T: ClientDB + Sized, B> {
|
||||
/// A cache of known ancestors at given heights for a specific block.
|
||||
//TODO: Consider FnvHashMap
|
||||
cache: HashMap<CacheKey<u64>, Hash256>,
|
||||
|
@ -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: BeaconStateTypes> {
|
||||
pub struct OptimizedLMDGhost<T: ClientDB + Sized, B> {
|
||||
/// A cache of known ancestors at given heights for a specific block.
|
||||
//TODO: Consider FnvHashMap
|
||||
cache: HashMap<CacheKey<u64>, Hash256>,
|
||||
|
@ -13,7 +13,7 @@ use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot
|
||||
|
||||
//TODO: Pruning and syncing
|
||||
|
||||
pub struct SlowLMDGhost<T: ClientDB + Sized, B: BeaconStateTypes> {
|
||||
pub struct SlowLMDGhost<T: ClientDB + Sized, B> {
|
||||
/// 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>,
|
||||
|
@ -25,7 +25,10 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::{fs::File, io::prelude::*, path::PathBuf};
|
||||
use types::test_utils::TestingBeaconStateBuilder;
|
||||
use types::{BeaconBlock, BeaconBlockBody, ChainSpec, Eth1Data, Hash256, Keypair, Slot};
|
||||
use types::{
|
||||
BeaconBlock, BeaconBlockBody, BeaconStateTypes, Eth1Data, FoundationStateTypes, Hash256,
|
||||
Keypair, Slot,
|
||||
};
|
||||
use yaml_rust::yaml;
|
||||
|
||||
// Note: We Assume the block Id's are hex-encoded.
|
||||
@ -82,7 +85,7 @@ fn test_yaml_vectors(
|
||||
let test_cases = load_test_cases_from_yaml(yaml_file_path);
|
||||
|
||||
// default vars
|
||||
let spec = ChainSpec::foundation();
|
||||
let spec = FoundationStateTypes::spec();
|
||||
let zero_hash = Hash256::zero();
|
||||
let eth1_data = Eth1Data {
|
||||
deposit_root: zero_hash.clone(),
|
||||
@ -227,23 +230,27 @@ fn setup_inital_state(
|
||||
|
||||
// the fork choice instantiation
|
||||
let fork_choice: Box<ForkChoice> = match fork_choice_algo {
|
||||
ForkChoiceAlgorithm::OptimizedLMDGhost => Box::new(OptimizedLMDGhost::new(
|
||||
block_store.clone(),
|
||||
state_store.clone(),
|
||||
)),
|
||||
ForkChoiceAlgorithm::BitwiseLMDGhost => Box::new(BitwiseLMDGhost::new(
|
||||
block_store.clone(),
|
||||
state_store.clone(),
|
||||
)),
|
||||
ForkChoiceAlgorithm::OptimizedLMDGhost => {
|
||||
let f: OptimizedLMDGhost<MemoryDB, FoundationStateTypes> =
|
||||
OptimizedLMDGhost::new(block_store.clone(), state_store.clone());
|
||||
Box::new(f)
|
||||
}
|
||||
ForkChoiceAlgorithm::BitwiseLMDGhost => {
|
||||
let f: BitwiseLMDGhost<MemoryDB, FoundationStateTypes> =
|
||||
BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
|
||||
Box::new(f)
|
||||
}
|
||||
ForkChoiceAlgorithm::SlowLMDGhost => {
|
||||
Box::new(SlowLMDGhost::new(block_store.clone(), state_store.clone()))
|
||||
let f: SlowLMDGhost<MemoryDB, FoundationStateTypes> =
|
||||
SlowLMDGhost::new(block_store.clone(), state_store.clone());
|
||||
Box::new(f)
|
||||
}
|
||||
ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())),
|
||||
};
|
||||
|
||||
let spec = ChainSpec::foundation();
|
||||
let spec = FoundationStateTypes::spec();
|
||||
|
||||
let mut state_builder =
|
||||
let mut state_builder: TestingBeaconStateBuilder<FoundationStateTypes> =
|
||||
TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec);
|
||||
state_builder.build_caches(&spec).unwrap();
|
||||
let (state, _keypairs) = state_builder.build();
|
||||
|
Loading…
Reference in New Issue
Block a user