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.
|
/// 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.
|
/// A cache of known ancestors at given heights for a specific block.
|
||||||
//TODO: Consider FnvHashMap
|
//TODO: Consider FnvHashMap
|
||||||
cache: HashMap<CacheKey<u64>, Hash256>,
|
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.
|
/// 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.
|
/// A cache of known ancestors at given heights for a specific block.
|
||||||
//TODO: Consider FnvHashMap
|
//TODO: Consider FnvHashMap
|
||||||
cache: HashMap<CacheKey<u64>, Hash256>,
|
cache: HashMap<CacheKey<u64>, Hash256>,
|
||||||
|
@ -13,7 +13,7 @@ use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot
|
|||||||
|
|
||||||
//TODO: Pruning and syncing
|
//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.
|
/// The latest attestation targets as a map of validator index to block hash.
|
||||||
//TODO: Could this be a fixed size vec
|
//TODO: Could this be a fixed size vec
|
||||||
latest_attestation_targets: HashMap<u64, Hash256>,
|
latest_attestation_targets: HashMap<u64, Hash256>,
|
||||||
|
@ -25,7 +25,10 @@ use std::collections::HashMap;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{fs::File, io::prelude::*, path::PathBuf};
|
use std::{fs::File, io::prelude::*, path::PathBuf};
|
||||||
use types::test_utils::TestingBeaconStateBuilder;
|
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;
|
use yaml_rust::yaml;
|
||||||
|
|
||||||
// Note: We Assume the block Id's are hex-encoded.
|
// 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);
|
let test_cases = load_test_cases_from_yaml(yaml_file_path);
|
||||||
|
|
||||||
// default vars
|
// default vars
|
||||||
let spec = ChainSpec::foundation();
|
let spec = FoundationStateTypes::spec();
|
||||||
let zero_hash = Hash256::zero();
|
let zero_hash = Hash256::zero();
|
||||||
let eth1_data = Eth1Data {
|
let eth1_data = Eth1Data {
|
||||||
deposit_root: zero_hash.clone(),
|
deposit_root: zero_hash.clone(),
|
||||||
@ -227,23 +230,27 @@ fn setup_inital_state(
|
|||||||
|
|
||||||
// the fork choice instantiation
|
// the fork choice instantiation
|
||||||
let fork_choice: Box<ForkChoice> = match fork_choice_algo {
|
let fork_choice: Box<ForkChoice> = match fork_choice_algo {
|
||||||
ForkChoiceAlgorithm::OptimizedLMDGhost => Box::new(OptimizedLMDGhost::new(
|
ForkChoiceAlgorithm::OptimizedLMDGhost => {
|
||||||
block_store.clone(),
|
let f: OptimizedLMDGhost<MemoryDB, FoundationStateTypes> =
|
||||||
state_store.clone(),
|
OptimizedLMDGhost::new(block_store.clone(), state_store.clone());
|
||||||
)),
|
Box::new(f)
|
||||||
ForkChoiceAlgorithm::BitwiseLMDGhost => Box::new(BitwiseLMDGhost::new(
|
}
|
||||||
block_store.clone(),
|
ForkChoiceAlgorithm::BitwiseLMDGhost => {
|
||||||
state_store.clone(),
|
let f: BitwiseLMDGhost<MemoryDB, FoundationStateTypes> =
|
||||||
)),
|
BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
|
||||||
|
Box::new(f)
|
||||||
|
}
|
||||||
ForkChoiceAlgorithm::SlowLMDGhost => {
|
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())),
|
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);
|
TestingBeaconStateBuilder::from_single_keypair(num_validators, &Keypair::random(), &spec);
|
||||||
state_builder.build_caches(&spec).unwrap();
|
state_builder.build_caches(&spec).unwrap();
|
||||||
let (state, _keypairs) = state_builder.build();
|
let (state, _keypairs) = state_builder.build();
|
||||||
|
Loading…
Reference in New Issue
Block a user