Tidy attestation processing

This commit is contained in:
Paul Hauner
2019-08-07 16:40:49 +10:00
parent fe2402b361
commit 378fe05c89
4 changed files with 33 additions and 23 deletions

View File

@@ -4,7 +4,6 @@ use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
use crate::iter::{ReverseBlockRootIterator, ReverseStateRootIterator};
use crate::metrics::Metrics;
use crate::persisted_beacon_chain::{PersistedBeaconChain, BEACON_CHAIN_DB_KEY};
use crate::BeaconChainError;
use lmd_ghost::LmdGhost;
use log::trace;
use operation_pool::DepositInsertStatus;
@@ -615,7 +614,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&self,
attestation: Attestation<T::EthSpec>,
state: &BeaconState<T::EthSpec>,
head_block: &BeaconBlock<T::EthSpec>,
_head_block: &BeaconBlock<T::EthSpec>,
) -> Result<AttestationProcessingOutcome, Error> {
self.metrics.attestation_processing_requests.inc();
let timer = self.metrics.attestation_processing_times.start_timer();
@@ -649,19 +648,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.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.
fn get_attestation_state(

View File

@@ -84,14 +84,30 @@ where
{
/// Instantiate a new harness with `validator_count` initial validators.
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 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);
genesis_block.state_root = Hash256::from_slice(&genesis_state.tree_hash_root());