mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-12 02:14:10 +00:00
Add attester to beacon chain test harness
This commit is contained in:
@@ -9,12 +9,14 @@ pub struct AttestationAggregator {
|
||||
store: HashMap<Vec<u8>, Attestation>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ProcessOutcome {
|
||||
AggregationNotRequired,
|
||||
Aggregated,
|
||||
NewAttestationCreated,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ProcessError {
|
||||
BadValidatorIndex,
|
||||
BadSignature,
|
||||
47
beacon_node/beacon_chain/src/attestation_processing.rs
Normal file
47
beacon_node/beacon_chain/src/attestation_processing.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use super::{BeaconChain, ClientDB, SlotClock};
|
||||
pub use crate::attestation_aggregator::{ProcessError as AggregatorError, ProcessOutcome};
|
||||
use crate::canonical_head::Error as HeadError;
|
||||
use types::{AttestationData, Signature};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
PresentSlotUnknown,
|
||||
AggregatorError(AggregatorError),
|
||||
HeadError(HeadError),
|
||||
}
|
||||
|
||||
impl<T, U> BeaconChain<T, U>
|
||||
where
|
||||
T: ClientDB,
|
||||
U: SlotClock,
|
||||
{
|
||||
pub fn process_free_attestation(
|
||||
&self,
|
||||
attestation_data: &AttestationData,
|
||||
signature: &Signature,
|
||||
validator_index: u64,
|
||||
) -> Result<ProcessOutcome, Error> {
|
||||
let present_slot = self
|
||||
.present_slot()
|
||||
.ok_or_else(|| Error::PresentSlotUnknown)?;
|
||||
let state = self.state(present_slot)?;
|
||||
|
||||
self.attestation_aggregator
|
||||
.write()
|
||||
.expect("Aggregator unlock failed.")
|
||||
.process_free_attestation(&state, attestation_data, signature, validator_index)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AggregatorError> for Error {
|
||||
fn from(e: AggregatorError) -> Error {
|
||||
Error::AggregatorError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeadError> for Error {
|
||||
fn from(e: HeadError) -> Error {
|
||||
Error::HeadError(e)
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,6 @@ use types::{AttestationData, Hash256};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
/*
|
||||
DBError(String),
|
||||
StateTransitionError(TransitionError),
|
||||
PresentSlotIsNone,
|
||||
*/
|
||||
SlotTooOld,
|
||||
PresentSlotUnknown,
|
||||
StateError,
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::{BeaconChain, CheckPoint, ClientDB, SlotClock};
|
||||
use std::sync::RwLockReadGuard;
|
||||
use types::{beacon_state::SlotProcessingError, BeaconBlock, BeaconState, Hash256};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
PastSlot,
|
||||
UnableToDetermineProducer,
|
||||
|
||||
@@ -52,4 +52,11 @@ where
|
||||
.beacon_block
|
||||
.slot
|
||||
}
|
||||
|
||||
pub fn validator_attestion_slot_and_shard(&self, validator_index: usize) -> Option<(u64, u64)> {
|
||||
let present_slot = self.present_slot()?;
|
||||
let state = self.state(present_slot).ok()?;
|
||||
|
||||
Some(state.attestation_slot_and_shard_for_validator(validator_index, &self.spec))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
mod attestation_aggregation;
|
||||
mod attestation_aggregator;
|
||||
pub mod attestation_processing;
|
||||
mod attestation_production;
|
||||
mod attestation_targets;
|
||||
mod block_graph;
|
||||
@@ -14,7 +15,7 @@ mod state_transition;
|
||||
|
||||
use self::attestation_targets::AttestationTargets;
|
||||
use self::block_graph::BlockGraph;
|
||||
use attestation_aggregation::AttestationAggregator;
|
||||
use attestation_aggregator::AttestationAggregator;
|
||||
use db::{
|
||||
stores::{BeaconBlockStore, BeaconStateStore},
|
||||
ClientDB, DBError,
|
||||
|
||||
Reference in New Issue
Block a user