mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
formatting
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::errors::{BeaconChainError as Error, BlockProductionError};
|
||||
use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
|
||||
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;
|
||||
@@ -11,19 +12,18 @@ use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use slog::{error, info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use state_processing::per_block_processing::errors::{
|
||||
AttesterSlashingValidationError, DepositValidationError,
|
||||
ExitValidationError, ProposerSlashingValidationError, TransferValidationError,
|
||||
AttesterSlashingValidationError, DepositValidationError, ExitValidationError,
|
||||
ProposerSlashingValidationError, TransferValidationError,
|
||||
};
|
||||
use state_processing::{
|
||||
per_block_processing, per_block_processing_without_verifying_block_signature,
|
||||
per_slot_processing, BlockProcessingError, common
|
||||
common, per_block_processing, per_block_processing_without_verifying_block_signature,
|
||||
per_slot_processing, BlockProcessingError,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use store::iter::{BestBlockRootsIterator, BlockIterator, BlockRootsIterator, StateRootsIterator};
|
||||
use store::{Error as DBError, Store};
|
||||
use tree_hash::TreeHash;
|
||||
use types::*;
|
||||
use crate::BeaconChainError;
|
||||
|
||||
// Text included in blocks.
|
||||
// Must be 32-bytes or panic.
|
||||
@@ -511,17 +511,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
///
|
||||
/// If valid, the attestation is added to the `op_pool` and aggregated with another attestation
|
||||
/// if possible.
|
||||
pub fn process_attestation(
|
||||
&self,
|
||||
attestation: Attestation<T::EthSpec>,
|
||||
) -> Result<(), Error> {
|
||||
pub fn process_attestation(&self, attestation: Attestation<T::EthSpec>) -> Result<(), Error> {
|
||||
self.metrics.attestation_processing_requests.inc();
|
||||
let timer = self.metrics.attestation_processing_times.start_timer();
|
||||
|
||||
if let Some(state) = self.get_attestation_state(&attestation) {
|
||||
if self.fork_choice.should_process_attestation(&state, &attestation)? {
|
||||
if self
|
||||
.fork_choice
|
||||
.should_process_attestation(&state, &attestation)?
|
||||
{
|
||||
let indexed_attestation = common::get_indexed_attestation(&state, &attestation)?;
|
||||
per_block_processing::is_valid_indexed_attestation(&state, &indexed_attestation, &self.spec)?;
|
||||
per_block_processing::is_valid_indexed_attestation(
|
||||
&state,
|
||||
&indexed_attestation,
|
||||
&self.spec,
|
||||
)?;
|
||||
self.fork_choice.process_attestation(&state, &attestation)?;
|
||||
}
|
||||
}
|
||||
@@ -540,12 +544,20 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
}
|
||||
|
||||
/// Retrieves the `BeaconState` used to create the attestation.
|
||||
fn get_attestation_state(&self, attestation: &Attestation<T::EthSpec>) -> Option<BeaconState<T::EthSpec>> {
|
||||
fn get_attestation_state(
|
||||
&self,
|
||||
attestation: &Attestation<T::EthSpec>,
|
||||
) -> Option<BeaconState<T::EthSpec>> {
|
||||
// Current state is used if the attestation targets a historic block and a slot within an
|
||||
// equal or adjacent epoch.
|
||||
let slots_per_epoch = T::EthSpec::slots_per_epoch();
|
||||
let min_slot = (self.state.read().slot.epoch(slots_per_epoch) - 1).start_slot(slots_per_epoch);
|
||||
let blocks = BestBlockRootsIterator::owned(self.store.clone(), self.state.read().clone(), self.state.read().slot.clone());
|
||||
let min_slot =
|
||||
(self.state.read().slot.epoch(slots_per_epoch) - 1).start_slot(slots_per_epoch);
|
||||
let blocks = BestBlockRootsIterator::owned(
|
||||
self.store.clone(),
|
||||
self.state.read().clone(),
|
||||
self.state.read().slot.clone(),
|
||||
);
|
||||
for (root, slot) in blocks {
|
||||
if root == attestation.data.target.root {
|
||||
return Some(self.state.read().clone());
|
||||
@@ -554,15 +566,18 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
if slot == min_slot {
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// A different state is retrieved from the database.
|
||||
match self.store.get::<BeaconBlock<T::EthSpec>>(&attestation.data.target.root) {
|
||||
match self
|
||||
.store
|
||||
.get::<BeaconBlock<T::EthSpec>>(&attestation.data.target.root)
|
||||
{
|
||||
Ok(Some(block)) => match self.store.get::<BeaconState<T::EthSpec>>(&block.state_root) {
|
||||
Ok(state) => state,
|
||||
_ => None
|
||||
_ => None,
|
||||
},
|
||||
_ => None
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1031,4 +1046,3 @@ impl From<BeaconStateError> for Error {
|
||||
Error::BeaconStateError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use crate::fork_choice::Error as ForkChoiceError;
|
||||
use crate::metrics::Error as MetricsError;
|
||||
use state_processing::per_block_processing::errors::{
|
||||
AttestationValidationError, IndexedAttestationValidationError,
|
||||
};
|
||||
use state_processing::BlockProcessingError;
|
||||
use state_processing::SlotProcessingError;
|
||||
use types::*;
|
||||
use state_processing::per_block_processing::errors::{AttestationValidationError, IndexedAttestationValidationError};
|
||||
|
||||
macro_rules! easy_from_to {
|
||||
($from: ident, $to: ident) => {
|
||||
@@ -33,7 +35,7 @@ pub enum BeaconChainError {
|
||||
SlotProcessingError(SlotProcessingError),
|
||||
MetricsError(String),
|
||||
AttestationValidationError(AttestationValidationError),
|
||||
IndexedAttestationValidationError(IndexedAttestationValidationError)
|
||||
IndexedAttestationValidationError(IndexedAttestationValidationError),
|
||||
}
|
||||
|
||||
easy_from_to!(SlotProcessingError, BeaconChainError);
|
||||
|
||||
@@ -3,7 +3,9 @@ use lmd_ghost::LmdGhost;
|
||||
use state_processing::common::get_attesting_indices;
|
||||
use std::sync::Arc;
|
||||
use store::{Error as StoreError, Store};
|
||||
use types::{Attestation, BeaconBlock, BeaconState, BeaconStateError, Epoch, EthSpec, Hash256, Slot};
|
||||
use types::{
|
||||
Attestation, BeaconBlock, BeaconState, BeaconStateError, Epoch, EthSpec, Hash256, Slot,
|
||||
};
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
@@ -171,7 +173,11 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
|
||||
}
|
||||
|
||||
/// Determines whether or not the given attestation contains a latest message.
|
||||
pub fn should_process_attestation(&self, state: &BeaconState<T::EthSpec>, attestation: &Attestation<T::EthSpec>) -> Result<bool> {
|
||||
pub fn should_process_attestation(
|
||||
&self,
|
||||
state: &BeaconState<T::EthSpec>,
|
||||
attestation: &Attestation<T::EthSpec>,
|
||||
) -> Result<bool> {
|
||||
let validator_indices =
|
||||
get_attesting_indices(state, &attestation.data, &attestation.aggregation_bits)?;
|
||||
|
||||
@@ -179,12 +185,11 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
|
||||
|
||||
Ok(validator_indices
|
||||
.iter()
|
||||
.find(|&&v| {
|
||||
match self.backend.latest_message(v) {
|
||||
Some((_, slot)) => block_slot > slot,
|
||||
None => true
|
||||
}
|
||||
}).is_some())
|
||||
.find(|&&v| match self.backend.latest_message(v) {
|
||||
Some((_, slot)) => block_slot > slot,
|
||||
None => true,
|
||||
})
|
||||
.is_some())
|
||||
}
|
||||
|
||||
// Returns the latest message for a given validator
|
||||
@@ -224,4 +229,3 @@ impl From<String> for Error {
|
||||
Error::BackendError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,12 +178,7 @@ where
|
||||
if let BlockProcessingOutcome::Processed { block_root } = outcome {
|
||||
head_block_root = Some(block_root);
|
||||
|
||||
self.add_free_attestations(
|
||||
&attestation_strategy,
|
||||
&new_state,
|
||||
block_root,
|
||||
slot,
|
||||
);
|
||||
self.add_free_attestations(&attestation_strategy, &new_state, block_root, slot);
|
||||
} else {
|
||||
panic!("block should be successfully processed: {:?}", outcome);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user