Tidy attestation processing
This commit is contained in:
parent
fe2402b361
commit
378fe05c89
@ -24,3 +24,4 @@ lmd_ghost = { path = "../../eth2/lmd_ghost" }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.5.5"
|
rand = "0.5.5"
|
||||||
|
lazy_static = "1.3.0"
|
||||||
|
@ -4,7 +4,6 @@ use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
|
|||||||
use crate::iter::{ReverseBlockRootIterator, ReverseStateRootIterator};
|
use crate::iter::{ReverseBlockRootIterator, ReverseStateRootIterator};
|
||||||
use crate::metrics::Metrics;
|
use crate::metrics::Metrics;
|
||||||
use crate::persisted_beacon_chain::{PersistedBeaconChain, BEACON_CHAIN_DB_KEY};
|
use crate::persisted_beacon_chain::{PersistedBeaconChain, BEACON_CHAIN_DB_KEY};
|
||||||
use crate::BeaconChainError;
|
|
||||||
use lmd_ghost::LmdGhost;
|
use lmd_ghost::LmdGhost;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use operation_pool::DepositInsertStatus;
|
use operation_pool::DepositInsertStatus;
|
||||||
@ -615,7 +614,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
&self,
|
&self,
|
||||||
attestation: Attestation<T::EthSpec>,
|
attestation: Attestation<T::EthSpec>,
|
||||||
state: &BeaconState<T::EthSpec>,
|
state: &BeaconState<T::EthSpec>,
|
||||||
head_block: &BeaconBlock<T::EthSpec>,
|
_head_block: &BeaconBlock<T::EthSpec>,
|
||||||
) -> Result<AttestationProcessingOutcome, Error> {
|
) -> Result<AttestationProcessingOutcome, Error> {
|
||||||
self.metrics.attestation_processing_requests.inc();
|
self.metrics.attestation_processing_requests.inc();
|
||||||
let timer = self.metrics.attestation_processing_times.start_timer();
|
let timer = self.metrics.attestation_processing_times.start_timer();
|
||||||
@ -649,19 +648,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
.map_err(|e| Error::AttestationValidationError(e))
|
.map_err(|e| Error::AttestationValidationError(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state_can_process_attestation(
|
|
||||||
state: &BeaconState<T::EthSpec>,
|
|
||||||
data: &AttestationData,
|
|
||||||
head_block: &BeaconBlock<T::EthSpec>,
|
|
||||||
) -> bool {
|
|
||||||
(state.current_epoch() - 1 <= data.target.epoch)
|
|
||||||
&& (data.target.epoch <= state.current_epoch() + 1)
|
|
||||||
&& state
|
|
||||||
.get_block_root(head_block.slot)
|
|
||||||
.map(|root| *root == data.beacon_block_root)
|
|
||||||
.unwrap_or_else(|_| false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/// Retrieves the `BeaconState` used to create the attestation.
|
/// Retrieves the `BeaconState` used to create the attestation.
|
||||||
fn get_attestation_state(
|
fn get_attestation_state(
|
||||||
|
@ -84,14 +84,30 @@ where
|
|||||||
{
|
{
|
||||||
/// Instantiate a new harness with `validator_count` initial validators.
|
/// Instantiate a new harness with `validator_count` initial validators.
|
||||||
pub fn new(validator_count: usize) -> Self {
|
pub fn new(validator_count: usize) -> Self {
|
||||||
|
let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(
|
||||||
|
validator_count,
|
||||||
|
&E::default_spec(),
|
||||||
|
);
|
||||||
|
let (genesis_state, keypairs) = state_builder.build();
|
||||||
|
|
||||||
|
Self::from_state_and_keypairs(genesis_state, keypairs)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instantiate a new harness with an initial validator for each key supplied.
|
||||||
|
pub fn from_keypairs(keypairs: Vec<Keypair>) -> Self {
|
||||||
|
let state_builder = TestingBeaconStateBuilder::from_keypairs(keypairs, &E::default_spec());
|
||||||
|
let (genesis_state, keypairs) = state_builder.build();
|
||||||
|
|
||||||
|
Self::from_state_and_keypairs(genesis_state, keypairs)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instantiate a new harness with the given genesis state and a keypair for each of the
|
||||||
|
/// initial validators in the given state.
|
||||||
|
pub fn from_state_and_keypairs(genesis_state: BeaconState<E>, keypairs: Vec<Keypair>) -> Self {
|
||||||
let spec = E::default_spec();
|
let spec = E::default_spec();
|
||||||
|
|
||||||
let store = Arc::new(MemoryStore::open());
|
let store = Arc::new(MemoryStore::open());
|
||||||
|
|
||||||
let state_builder =
|
|
||||||
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(validator_count, &spec);
|
|
||||||
let (genesis_state, keypairs) = state_builder.build();
|
|
||||||
|
|
||||||
let mut genesis_block = BeaconBlock::empty(&spec);
|
let mut genesis_block = BeaconBlock::empty(&spec);
|
||||||
genesis_block.state_root = Hash256::from_slice(&genesis_state.tree_hash_root());
|
genesis_block.state_root = Hash256::from_slice(&genesis_state.tree_hash_root());
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#![cfg(not(debug_assertions))]
|
#![cfg(not(debug_assertions))]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
use beacon_chain::test_utils::{
|
use beacon_chain::test_utils::{
|
||||||
AttestationStrategy, BeaconChainHarness, BlockStrategy, CommonTypes, PersistedBeaconChain,
|
AttestationStrategy, BeaconChainHarness, BlockStrategy, CommonTypes, PersistedBeaconChain,
|
||||||
BEACON_CHAIN_DB_KEY,
|
BEACON_CHAIN_DB_KEY,
|
||||||
@ -9,17 +12,21 @@ use lmd_ghost::ThreadSafeReducedTree;
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use store::{MemoryStore, Store};
|
use store::{MemoryStore, Store};
|
||||||
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use types::{Deposit, EthSpec, Hash256, MinimalEthSpec, RelativeEpoch, Slot};
|
use types::{Deposit, EthSpec, Hash256, Keypair, MinimalEthSpec, RelativeEpoch, Slot};
|
||||||
|
|
||||||
// Should ideally be divisible by 3.
|
// Should ideally be divisible by 3.
|
||||||
pub const VALIDATOR_COUNT: usize = 24;
|
pub const VALIDATOR_COUNT: usize = 24;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
/// A cached set of keys.
|
||||||
|
static ref KEYPAIRS: Vec<Keypair> = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
type TestForkChoice = ThreadSafeReducedTree<MemoryStore, MinimalEthSpec>;
|
type TestForkChoice = ThreadSafeReducedTree<MemoryStore, MinimalEthSpec>;
|
||||||
|
|
||||||
fn get_harness(validator_count: usize) -> BeaconChainHarness<TestForkChoice, MinimalEthSpec> {
|
fn get_harness(validator_count: usize) -> BeaconChainHarness<TestForkChoice, MinimalEthSpec> {
|
||||||
let harness = BeaconChainHarness::new(validator_count);
|
let harness = BeaconChainHarness::from_keypairs(KEYPAIRS[0..validator_count].to_vec());
|
||||||
|
|
||||||
// Move past the zero slot.
|
|
||||||
harness.advance_slot();
|
harness.advance_slot();
|
||||||
|
|
||||||
harness
|
harness
|
||||||
@ -300,7 +307,7 @@ fn free_attestations_added_to_fork_choice_some_none() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn free_attestations_over_slots() {
|
fn attestations_with_increasing_slots() {
|
||||||
let num_blocks_produced = MinimalEthSpec::slots_per_epoch() * 5;
|
let num_blocks_produced = MinimalEthSpec::slots_per_epoch() * 5;
|
||||||
|
|
||||||
let harness = get_harness(VALIDATOR_COUNT);
|
let harness = get_harness(VALIDATOR_COUNT);
|
||||||
|
Loading…
Reference in New Issue
Block a user