Merge branch 'master' into block-processing-times

This commit is contained in:
Paul Hauner 2019-08-14 12:25:28 +10:00
commit 072eb82fe4
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 85 additions and 109 deletions

View File

@ -25,3 +25,4 @@ lmd_ghost = { path = "../../eth2/lmd_ghost" }
[dev-dependencies]
rand = "0.5.5"
lazy_static = "1.3.0"

View File

@ -558,31 +558,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.store
.get::<BeaconBlock<T::EthSpec>>(&attestation.data.beacon_block_root)?
{
let finalized_epoch = self.head().beacon_state.finalized_checkpoint.epoch;
if attestation_head_block.slot
<= finalized_epoch.start_slot(T::EthSpec::slots_per_epoch())
{
// Ignore any attestation where the slot of `data.beacon_block_root` is equal to or
// prior to the finalized epoch.
//
// For any valid attestation if the `beacon_block_root` is prior to finalization, then
// all other parameters (source, target, etc) must all be prior to finalization and
// therefore no longer interesting.
return Ok(AttestationProcessingOutcome::FinalizedSlot {
attestation: attestation_head_block.epoch(),
finalized: finalized_epoch,
});
}
// Attempt to process the attestation using the `self.head()` state.
//
// This is purely an effort to avoid loading a `BeaconState` unnecessarily from the DB.
let optional_outcome: Option<Result<AttestationProcessingOutcome, Error>> = {
// Take a read lock on the head beacon state.
//
// The purpose of this whole `let processed ...` block is to ensure that the read
// lock is dropped if we don't end up using the head beacon state.
let state = &self.head().beacon_state;
// If it turns out that the attestation was made using the head state, then there
@ -605,20 +584,19 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
{
// The head state is able to be used to validate this attestation. No need to load
// anything from the database.
Some(self.process_attestation_for_state_and_block(
return self.process_attestation_for_state_and_block(
attestation.clone(),
state,
&attestation_head_block,
))
} else {
None
);
}
};
if let Some(outcome) = optional_outcome {
// Verification was already completed with an in-memory state. Return that result.
outcome
} else {
// Ensure the read-lock from `self.head()` is dropped.
//
// This is likely unnecessary, however it remains as a reminder to ensure this lock
// isn't hogged.
std::mem::drop(state);
// Use the `data.beacon_block_root` to load the state from the latest non-skipped
// slot preceding the attestation's creation.
//
@ -669,7 +647,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&attestation_head_block,
)
}
}
} else {
// Drop any attestation where we have not processed `attestation.data.beacon_block_root`.
//
@ -737,7 +714,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
result
};
let result = if block.slot <= finalized_epoch.start_slot(T::EthSpec::slots_per_epoch()) {
if block.slot <= finalized_epoch.start_slot(T::EthSpec::slots_per_epoch()) {
// Ignore any attestation where the slot of `data.beacon_block_root` is equal to or
// prior to the finalized epoch.
//
@ -774,9 +751,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
metrics::inc_counter(&metrics::ATTESTATION_PROCESSING_SUCCESSES);
Ok(AttestationProcessingOutcome::Processed)
};
result
}
}
/// Accept some deposit and queue it for inclusion in an appropriate block.