mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Move processing cache out of DA (#5420)
* Move processing cache out of DA * Merge branch 'sigp/unstable' into non-da-processing-cach * Merge branch 'unstable' of https://github.com/sigp/lighthouse into non-da-processing-cache * remove unused file, remove outdated TODO, add is_deneb check to missing blob id calculations * Merge branch 'unstable' of https://github.com/sigp/lighthouse into non-da-processing-cache * fix lints
This commit is contained in:
@@ -7,11 +7,8 @@ pub use crate::data_availability_checker::availability_view::{
|
||||
};
|
||||
pub use crate::data_availability_checker::child_components::ChildComponents;
|
||||
use crate::data_availability_checker::overflow_lru_cache::OverflowLRUCache;
|
||||
use crate::data_availability_checker::processing_cache::ProcessingCache;
|
||||
use crate::{BeaconChain, BeaconChainTypes, BeaconStore};
|
||||
use kzg::Kzg;
|
||||
use parking_lot::RwLock;
|
||||
pub use processing_cache::ProcessingComponents;
|
||||
use slasher::test_utils::E;
|
||||
use slog::{debug, error, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
@@ -21,7 +18,6 @@ use std::fmt::Debug;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::sync::Arc;
|
||||
use task_executor::TaskExecutor;
|
||||
use types::beacon_block_body::KzgCommitmentOpts;
|
||||
use types::blob_sidecar::{BlobIdentifier, BlobSidecar, FixedBlobSidecarList};
|
||||
use types::{BlobSidecarList, ChainSpec, Epoch, EthSpec, Hash256, SignedBeaconBlock};
|
||||
|
||||
@@ -29,7 +25,6 @@ mod availability_view;
|
||||
mod child_components;
|
||||
mod error;
|
||||
mod overflow_lru_cache;
|
||||
mod processing_cache;
|
||||
mod state_lru_cache;
|
||||
|
||||
pub use error::{Error as AvailabilityCheckError, ErrorCategory as AvailabilityCheckErrorCategory};
|
||||
@@ -50,7 +45,6 @@ pub const STATE_LRU_CAPACITY: usize = STATE_LRU_CAPACITY_NON_ZERO.get();
|
||||
/// `DataAvailabilityChecker` is responsible for KZG verification of block components as well as
|
||||
/// checking whether a "availability check" is required at all.
|
||||
pub struct DataAvailabilityChecker<T: BeaconChainTypes> {
|
||||
processing_cache: RwLock<ProcessingCache<T::EthSpec>>,
|
||||
availability_cache: Arc<OverflowLRUCache<T>>,
|
||||
slot_clock: T::SlotClock,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
@@ -89,7 +83,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
) -> Result<Self, AvailabilityCheckError> {
|
||||
let overflow_cache = OverflowLRUCache::new(OVERFLOW_LRU_CAPACITY, store, spec.clone())?;
|
||||
Ok(Self {
|
||||
processing_cache: <_>::default(),
|
||||
availability_cache: Arc::new(overflow_cache),
|
||||
slot_clock,
|
||||
log: log.clone(),
|
||||
@@ -98,17 +91,25 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Checks if the given block root is cached.
|
||||
/// Checks if the block root is currenlty in the availability cache awaiting processing because
|
||||
/// of missing components.
|
||||
pub fn has_block(&self, block_root: &Hash256) -> bool {
|
||||
self.processing_cache.read().has_block(block_root)
|
||||
self.availability_cache.has_block(block_root)
|
||||
}
|
||||
|
||||
/// Get the processing info for a block.
|
||||
pub fn get_processing_components(
|
||||
&self,
|
||||
block_root: Hash256,
|
||||
) -> Option<ProcessingComponents<T::EthSpec>> {
|
||||
self.processing_cache.read().get(&block_root).cloned()
|
||||
pub fn get_missing_blob_ids_with(&self, block_root: Hash256) -> MissingBlobs {
|
||||
self.availability_cache
|
||||
.with_pending_components(&block_root, |pending_components| match pending_components {
|
||||
Some(pending_components) => self.get_missing_blob_ids(
|
||||
block_root,
|
||||
pending_components
|
||||
.get_cached_block()
|
||||
.as_ref()
|
||||
.map(|b| b.as_block()),
|
||||
&pending_components.verified_blobs,
|
||||
),
|
||||
None => MissingBlobs::new_without_block(block_root, self.is_deneb()),
|
||||
})
|
||||
}
|
||||
|
||||
/// If there's no block, all possible ids will be returned that don't exist in the given blobs.
|
||||
@@ -116,7 +117,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
pub fn get_missing_blob_ids<V>(
|
||||
&self,
|
||||
block_root: Hash256,
|
||||
block: &Option<Arc<SignedBeaconBlock<T::EthSpec>>>,
|
||||
block: Option<&SignedBeaconBlock<T::EthSpec>>,
|
||||
blobs: &FixedVector<Option<V>, <T::EthSpec as EthSpec>::MaxBlobsPerBlock>,
|
||||
) -> MissingBlobs {
|
||||
let Some(current_slot) = self.slot_clock.now_or_genesis() else {
|
||||
@@ -132,10 +133,15 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
if self.da_check_required_for_epoch(current_epoch) {
|
||||
match block {
|
||||
Some(cached_block) => {
|
||||
let block_commitments = cached_block.get_commitments();
|
||||
let block_commitments_len = cached_block
|
||||
.message()
|
||||
.body()
|
||||
.blob_kzg_commitments()
|
||||
.map(|v| v.len())
|
||||
.unwrap_or(0);
|
||||
let blob_ids = blobs
|
||||
.iter()
|
||||
.take(block_commitments.len())
|
||||
.take(block_commitments_len)
|
||||
.enumerate()
|
||||
.filter_map(|(index, blob_commitment_opt)| {
|
||||
blob_commitment_opt.is_none().then_some(BlobIdentifier {
|
||||
@@ -163,14 +169,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
self.availability_cache.peek_blob(blob_id)
|
||||
}
|
||||
|
||||
/// Get a block from the availability cache. Includes any blocks we are currently processing.
|
||||
pub fn get_block(&self, block_root: &Hash256) -> Option<Arc<SignedBeaconBlock<T::EthSpec>>> {
|
||||
self.processing_cache
|
||||
.read()
|
||||
.get(block_root)
|
||||
.and_then(|cached| cached.block.clone())
|
||||
}
|
||||
|
||||
/// Put a list of blobs received via RPC into the availability cache. This performs KZG
|
||||
/// verification on the blobs in the list.
|
||||
pub fn put_rpc_blobs(
|
||||
@@ -323,52 +321,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
block.num_expected_blobs() > 0 && self.da_check_required_for_epoch(block.epoch())
|
||||
}
|
||||
|
||||
/// Adds a block to the processing cache. This block's commitments are unverified but caching
|
||||
/// them here is useful to avoid duplicate downloads of blocks, as well as understanding
|
||||
/// our blob download requirements. We will also serve this over RPC.
|
||||
pub fn notify_block(&self, block_root: Hash256, block: Arc<SignedBeaconBlock<T::EthSpec>>) {
|
||||
self.processing_cache
|
||||
.write()
|
||||
.entry(block_root)
|
||||
.or_default()
|
||||
.merge_block(block);
|
||||
}
|
||||
|
||||
/// Add a single blob commitment to the processing cache. This commitment is unverified but caching
|
||||
/// them here is useful to avoid duplicate downloads of blobs, as well as understanding
|
||||
/// our block and blob download requirements.
|
||||
pub fn notify_gossip_blob(&self, block_root: Hash256, blob: &GossipVerifiedBlob<T>) {
|
||||
let index = blob.index();
|
||||
let commitment = blob.kzg_commitment();
|
||||
self.processing_cache
|
||||
.write()
|
||||
.entry(block_root)
|
||||
.or_default()
|
||||
.merge_single_blob(index as usize, commitment);
|
||||
}
|
||||
|
||||
/// Adds blob commitments to the processing cache. These commitments are unverified but caching
|
||||
/// them here is useful to avoid duplicate downloads of blobs, as well as understanding
|
||||
/// our block and blob download requirements.
|
||||
pub fn notify_rpc_blobs(&self, block_root: Hash256, blobs: &FixedBlobSidecarList<T::EthSpec>) {
|
||||
let mut commitments = KzgCommitmentOpts::<T::EthSpec>::default();
|
||||
for blob in blobs.iter().flatten() {
|
||||
if let Some(commitment) = commitments.get_mut(blob.index as usize) {
|
||||
*commitment = Some(blob.kzg_commitment);
|
||||
}
|
||||
}
|
||||
self.processing_cache
|
||||
.write()
|
||||
.entry(block_root)
|
||||
.or_default()
|
||||
.merge_blobs(commitments);
|
||||
}
|
||||
|
||||
/// Clears the block and all blobs from the processing cache for a give root if they exist.
|
||||
pub fn remove_notified(&self, block_root: &Hash256) {
|
||||
self.processing_cache.write().remove(block_root)
|
||||
}
|
||||
|
||||
/// The epoch at which we require a data availability check in block processing.
|
||||
/// `None` if the `Deneb` fork is disabled.
|
||||
pub fn data_availability_boundary(&self) -> Option<Epoch> {
|
||||
@@ -410,7 +362,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
/// Collects metrics from the data availability checker.
|
||||
pub fn metrics(&self) -> DataAvailabilityCheckerMetrics {
|
||||
DataAvailabilityCheckerMetrics {
|
||||
processing_cache_size: self.processing_cache.read().len(),
|
||||
num_store_entries: self.availability_cache.num_store_entries(),
|
||||
state_cache_size: self.availability_cache.state_cache_size(),
|
||||
block_cache_size: self.availability_cache.block_cache_size(),
|
||||
@@ -420,7 +371,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
|
||||
/// Helper struct to group data availability checker metrics.
|
||||
pub struct DataAvailabilityCheckerMetrics {
|
||||
pub processing_cache_size: usize,
|
||||
pub num_store_entries: usize,
|
||||
pub state_cache_size: usize,
|
||||
pub block_cache_size: usize,
|
||||
|
||||
Reference in New Issue
Block a user