This commit is contained in:
Pawan Dhananjay
2023-03-21 00:46:31 +05:30
parent 38f2b88dd0
commit 0958ce610f
12 changed files with 44 additions and 196 deletions

View File

@@ -8,14 +8,13 @@ use crate::beacon_proposer_cache::compute_proposer_duties_from_head;
use crate::beacon_proposer_cache::BeaconProposerCache;
use crate::blob_cache::BlobCache;
use crate::blob_verification::{
self, AsBlock, AvailableBlock, BlobError, BlockWrapper, GossipVerifiedBlob, IntoAvailableBlock,
VerifiedBlobs,
self, AsBlock, AvailableBlock, BlobError, BlockWrapper, GossipVerifiedBlob,
};
use crate::block_times_cache::BlockTimesCache;
use crate::block_verification::{
check_block_is_finalized_checkpoint_or_descendant, check_block_relevancy, get_block_root,
signature_verify_chain_segment, BlockError, ExecutedBlock, ExecutionPendingBlock,
GossipVerifiedBlock, IntoExecutionPendingBlock, PayloadVerificationOutcome, POS_PANDA_BANNER,
GossipVerifiedBlock, IntoExecutionPendingBlock, POS_PANDA_BANNER,
};
pub use crate::canonical_head::{CanonicalHead, CanonicalHeadRwLock};
use crate::chain_config::ChainConfig;
@@ -78,7 +77,6 @@ use futures::channel::mpsc::Sender;
use itertools::process_results;
use itertools::Itertools;
use kzg::Kzg;
use oneshot_broadcast::Receiver;
use operation_pool::{AttestationRef, OperationPool, PersistedOperationPool, ReceivedPreCapella};
use parking_lot::{Mutex, RwLock};
use proto_array::{CountUnrealizedFull, DoNotReOrg, ProposerHeadError};
@@ -87,7 +85,6 @@ use slasher::Slasher;
use slog::{crit, debug, error, info, trace, warn, Logger};
use slot_clock::SlotClock;
use ssz::Encode;
use state_processing::per_block_processing::eip4844::eip4844::verify_kzg_commitments_against_transactions;
use state_processing::{
common::get_attesting_indices_from_state,
per_block_processing,
@@ -103,7 +100,6 @@ use std::borrow::Cow;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::collections::HashSet;
use std::future::Future;
use std::io::prelude::*;
use std::marker::PhantomData;
use std::sync::Arc;
@@ -113,7 +109,6 @@ use store::{
DatabaseBlock, Error as DBError, HotColdDB, KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
};
use task_executor::{ShutdownReason, TaskExecutor};
use tokio::task::JoinHandle;
use tree_hash::TreeHash;
use types::beacon_block_body::KzgCommitments;
use types::beacon_state::CloneConfig;
@@ -990,7 +985,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub async fn get_block_and_blobs_checking_early_attester_cache(
&self,
block_root: &Hash256,
_block_root: &Hash256,
) -> Result<Option<()>, Error> {
//TODO(sean) use the rpc blobs cache and revert this to the current block cache logic
Ok(Some(()))
@@ -2711,7 +2706,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// TODO(log required errors)
let executed_block = self
.clone()
.into_executed_block(execution_pending, count_unrealized)
.into_executed_block(execution_pending)
.await
.map_err(|e| self.handle_block_error(e))?;
@@ -2733,7 +2728,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
async fn into_executed_block(
self: Arc<Self>,
execution_pending_block: ExecutionPendingBlock<T>,
count_unrealized: CountUnrealized,
) -> Result<ExecutedBlock<T::EthSpec>, BlockError<T::EthSpec>> {
let ExecutionPendingBlock {
block,
@@ -2843,7 +2837,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
confirmed_state_roots,
consensus_context,
payload_verification_outcome,
} = block;
} = *block;
let available_block = match block {
BlockWrapper::Available(block) => block,

View File

@@ -1,5 +1,4 @@
use slot_clock::SlotClock;
use state_processing::ConsensusContext;
use std::sync::Arc;
use crate::beacon_chain::{
@@ -7,7 +6,6 @@ use crate::beacon_chain::{
VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT,
};
use crate::gossip_blob_cache::AvailabilityCheckError;
use crate::snapshot_cache::PreProcessingSnapshot;
use crate::BeaconChainError;
use derivative::Derivative;
use state_processing::per_block_processing::eip4844::eip4844::verify_kzg_commitments_against_transactions;
@@ -221,7 +219,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
.map_err(BlobError::BeaconChainError)?;
let pubkey = pubkey_cache
.get(proposer_index as usize)
.get(proposer_index)
.ok_or_else(|| BlobError::UnknownValidator(proposer_index as u64))?;
signed_blob_sidecar.verify_signature(
@@ -265,7 +263,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
}
pub fn verify_data_availability<T: BeaconChainTypes>(
blob_sidecar: &BlobSidecarList<T::EthSpec>,
_blob_sidecar: &BlobSidecarList<T::EthSpec>,
kzg_commitments: &[KzgCommitment],
transactions: &Transactions<T::EthSpec>,
_block_slot: Slot,
@@ -316,8 +314,8 @@ pub trait IntoAvailableBlock<T: BeaconChainTypes> {
impl<T: BeaconChainTypes> IntoAvailableBlock<T> for BlockWrapper<T::EthSpec> {
fn into_available_block(
self,
block_root: Hash256,
chain: &BeaconChain<T>,
_block_root: Hash256,
_chain: &BeaconChain<T>,
) -> Result<AvailableBlock<T::EthSpec>, BlobError> {
todo!()
}
@@ -436,7 +434,7 @@ impl<E: EthSpec> AsBlock<E> for BlockWrapper<E> {
fn as_block(&self) -> &SignedBeaconBlock<E> {
match &self {
BlockWrapper::Available(block) => &block.block,
BlockWrapper::AvailabilityPending(block) => &block,
BlockWrapper::AvailabilityPending(block) => block,
}
}
fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> {
@@ -493,7 +491,7 @@ impl<E: EthSpec> AsBlock<E> for &BlockWrapper<E> {
fn as_block(&self) -> &SignedBeaconBlock<E> {
match &self {
BlockWrapper::Available(block) => &block.block,
BlockWrapper::AvailabilityPending(block) => &block,
BlockWrapper::AvailabilityPending(block) => block,
}
}
fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> {

View File

@@ -949,7 +949,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
.set_kzg_commitments_consistent(true);
Ok(Self {
block: block,
block,
block_root,
parent,
consensus_context,
@@ -1149,8 +1149,6 @@ impl<T: BeaconChainTypes> IntoExecutionPendingBlock<T> for Arc<SignedBeaconBlock
let block_root = check_block_relevancy(&self, block_root, chain)
.map_err(|e| BlockSlashInfo::SignatureNotChecked(self.signed_block_header(), e))?;
let header = self.signed_block_header();
SignatureVerifiedBlock::check_slashable(self, block_root, chain)?
.into_execution_pending_block_slashable(block_root, chain, notify_execution_layer)
}
@@ -1182,10 +1180,7 @@ impl<T: BeaconChainTypes> IntoExecutionPendingBlock<T> for BlockWrapper<T::EthSp
let block = execution_pending_block.block.block_cloned();
let available_execution_pending_block =
BlockWrapper::Available(AvailableBlock { block, blobs });
std::mem::replace(
&mut execution_pending_block.block,
available_execution_pending_block,
);
execution_pending_block.block = available_execution_pending_block;
Ok(execution_pending_block)
}
}

View File

@@ -1,6 +1,5 @@
use crate::beacon_chain::{CanonicalHead, BEACON_CHAIN_DB_KEY, ETH1_CACHE_DB_KEY, OP_POOL_DB_KEY};
use crate::blob_cache::BlobCache;
use crate::block_verification::ExecutedBlock;
use crate::eth1_chain::{CachingEth1Backend, SszEth1};
use crate::eth1_finalization_cache::Eth1FinalizationCache;
use crate::fork_choice_signal::ForkChoiceSignalTx;

View File

@@ -1,20 +1,15 @@
use crate::blob_verification::{
verify_data_availability, AsBlock, AvailableBlock, BlockWrapper, VerifiedBlobs,
};
use crate::block_verification::{ExecutedBlock, IntoExecutionPendingBlock};
use crate::blob_verification::{AsBlock, AvailableBlock, BlockWrapper, VerifiedBlobs};
use crate::block_verification::ExecutedBlock;
use crate::kzg_utils::validate_blob;
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes, BlockError};
use kzg::Error as KzgError;
use kzg::{Kzg, KzgCommitment};
use kzg::Kzg;
use parking_lot::{Mutex, RwLock};
use ssz_types::{Error, VariableList};
use std::collections::hash_map::Entry;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::future::Future;
use std::sync::{mpsc, Arc};
use tokio::sync::mpsc::Sender;
use std::collections::HashMap;
use std::sync::Arc;
use types::blob_sidecar::{BlobIdentifier, BlobSidecar};
use types::{EthSpec, Hash256, SignedBeaconBlock, SignedBlobSidecar};
use types::{EthSpec, Hash256};
#[derive(Debug)]
pub enum AvailabilityCheckError {
@@ -43,7 +38,7 @@ pub struct DataAvailabilityChecker<T: EthSpec> {
pub enum Availability<T: EthSpec> {
PendingBlobs(Vec<BlobIdentifier>),
PendingBlock(Hash256),
Available(ExecutedBlock<T>),
Available(Box<ExecutedBlock<T>>),
}
struct GossipBlobCache<T: EthSpec> {
@@ -71,13 +66,8 @@ impl<T: EthSpec> DataAvailabilityChecker<T> {
blob: Arc<BlobSidecar<T>>,
) -> Result<Availability<T>, AvailabilityCheckError> {
let verified = if let Some(kzg) = self.kzg.as_ref() {
validate_blob::<T>(
kzg,
blob.blob.clone(),
blob.kzg_commitment.clone(),
blob.kzg_proof,
)
.map_err(|e| AvailabilityCheckError::Kzg(e))?
validate_blob::<T>(kzg, blob.blob.clone(), blob.kzg_commitment, blob.kzg_proof)
.map_err(AvailabilityCheckError::Kzg)?
} else {
false
// error wrong fork
@@ -91,7 +81,7 @@ impl<T: EthSpec> DataAvailabilityChecker<T> {
// Gossip cache.
blob_cache
.entry(blob.block_root)
.and_modify(|mut inner| {
.and_modify(|inner| {
// All blobs reaching this cache should be gossip verified and gossip verification
// should filter duplicates, as well as validate indices.
inner
@@ -145,7 +135,7 @@ impl<T: EthSpec> DataAvailabilityChecker<T> {
let block_clone = executed_block.block.clone();
let availability = match block_clone {
BlockWrapper::Available(available_block) => Availability::Available(executed_block),
BlockWrapper::Available(_) => Availability::Available(Box::new(executed_block)),
BlockWrapper::AvailabilityPending(block) => {
if let Ok(kzg_commitments) = block.message().body().blob_kzg_commitments() {
// first check if the blockwrapper contains blobs, if so, use those
@@ -193,7 +183,7 @@ impl<T: EthSpec> DataAvailabilityChecker<T> {
consensus_context,
payload_verification_outcome,
};
Availability::Available(available_executed)
Availability::Available(Box::new(available_executed))
} else {
let mut missing_blobs = Vec::with_capacity(kzg_commitments.len());
for i in 0..kzg_commitments.len() {
@@ -207,7 +197,7 @@ impl<T: EthSpec> DataAvailabilityChecker<T> {
//TODO(sean) add a check that missing blobs > 0
let _ = cache.executed_block.insert(executed_block.clone());
let _ = cache.executed_block.insert(executed_block);
// log that we cached the block?
Availability::PendingBlobs(missing_blobs)
}
@@ -230,27 +220,10 @@ impl<T: EthSpec> DataAvailabilityChecker<T> {
}
}
} else {
Availability::Available(executed_block)
Availability::Available(Box::new(executed_block))
}
}
};
Ok(availability)
}
/// Adds the blob to the cache. Returns true if adding the blob completes
/// all the required blob sidecars for a given block root.
///
/// Note: we can only know this if we know `block.kzg_commitments.len()`
pub fn put_blob_temp(
&self,
blob: Arc<SignedBlobSidecar<T>>,
) -> Result<bool, AvailabilityCheckError> {
unimplemented!()
}
/// Returns all blobs associated with a given block root otherwise returns
/// a UnavailableBlobs error.
pub fn blobs(&self, block_root: Hash256) -> Result<VerifiedBlobs<T>, AvailabilityCheckError> {
unimplemented!()
}
}