Realized unrealized experimentation (#3322)

## Issue Addressed

Add a flag that optionally enables unrealized vote tracking.  Would like to test out on testnets and benchmark differences in methods of vote tracking. This PR includes a DB schema upgrade to enable to new vote tracking style.


Co-authored-by: realbigsean <sean@sigmaprime.io>
Co-authored-by: Paul Hauner <paul@paulhauner.com>
Co-authored-by: sean <seananderson33@gmail.com>
Co-authored-by: Mac L <mjladson@pm.me>
This commit is contained in:
realbigsean
2022-07-25 23:53:26 +00:00
parent bb5a6d2cca
commit 20ebf1f3c1
47 changed files with 1254 additions and 338 deletions

View File

@@ -93,6 +93,7 @@ use types::beacon_state::CloneConfig;
use types::*;
pub use crate::canonical_head::{CanonicalHead, CanonicalHeadRwLock};
pub use fork_choice::CountUnrealized;
pub type ForkChoiceError = fork_choice::Error<crate::ForkChoiceStoreError>;
@@ -1740,6 +1741,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.slot()?,
verified.indexed_attestation(),
AttestationFromBlock::False,
&self.spec,
)
.map_err(Into::into)
}
@@ -2220,6 +2222,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub async fn process_chain_segment(
self: &Arc<Self>,
chain_segment: Vec<Arc<SignedBeaconBlock<T::EthSpec>>>,
count_unrealized: CountUnrealized,
) -> ChainSegmentResult<T::EthSpec> {
let mut imported_blocks = 0;
@@ -2284,7 +2287,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// Import the blocks into the chain.
for signature_verified_block in signature_verified_blocks {
match self.process_block(signature_verified_block).await {
match self
.process_block(signature_verified_block, count_unrealized)
.await
{
Ok(_) => imported_blocks += 1,
Err(error) => {
return ChainSegmentResult::Failed {
@@ -2368,6 +2374,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub async fn process_block<B: IntoExecutionPendingBlock<T>>(
self: &Arc<Self>,
unverified_block: B,
count_unrealized: CountUnrealized,
) -> Result<Hash256, BlockError<T::EthSpec>> {
// Start the Prometheus timer.
let _full_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_TIMES);
@@ -2383,7 +2390,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let import_block = async move {
let execution_pending = unverified_block.into_execution_pending_block(&chain)?;
chain
.import_execution_pending_block(execution_pending)
.import_execution_pending_block(execution_pending, count_unrealized)
.await
};
@@ -2441,6 +2448,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
async fn import_execution_pending_block(
self: Arc<Self>,
execution_pending_block: ExecutionPendingBlock<T>,
count_unrealized: CountUnrealized,
) -> Result<Hash256, BlockError<T::EthSpec>> {
let ExecutionPendingBlock {
block,
@@ -2499,6 +2507,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state,
confirmed_state_roots,
payload_verification_status,
count_unrealized,
)
},
"payload_verification_handle",
@@ -2520,6 +2529,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
mut state: BeaconState<T::EthSpec>,
confirmed_state_roots: Vec<Hash256>,
payload_verification_status: PayloadVerificationStatus,
count_unrealized: CountUnrealized,
) -> Result<Hash256, BlockError<T::EthSpec>> {
let current_slot = self.slot()?;
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());
@@ -2665,6 +2675,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&state,
payload_verification_status,
&self.spec,
count_unrealized.and(self.config.count_unrealized.into()),
)
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
}
@@ -2690,6 +2701,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
current_slot,
&indexed_attestation,
AttestationFromBlock::True,
&self.spec,
) {
Ok(()) => Ok(()),
// Ignore invalid attestations whilst importing attestations from a block. The