mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22: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:
@@ -2,7 +2,6 @@ use super::state_lru_cache::DietAvailabilityPendingExecutedBlock;
|
||||
use crate::blob_verification::KzgVerifiedBlob;
|
||||
use crate::block_verification_types::AsBlock;
|
||||
use crate::data_availability_checker::overflow_lru_cache::PendingComponents;
|
||||
use crate::data_availability_checker::ProcessingComponents;
|
||||
use kzg::KzgCommitment;
|
||||
use ssz_types::FixedVector;
|
||||
use std::sync::Arc;
|
||||
@@ -178,14 +177,6 @@ macro_rules! impl_availability_view {
|
||||
};
|
||||
}
|
||||
|
||||
impl_availability_view!(
|
||||
ProcessingComponents,
|
||||
Arc<SignedBeaconBlock<E>>,
|
||||
KzgCommitment,
|
||||
block,
|
||||
blob_commitments
|
||||
);
|
||||
|
||||
impl_availability_view!(
|
||||
PendingComponents,
|
||||
DietAvailabilityPendingExecutedBlock<E>,
|
||||
@@ -293,32 +284,6 @@ pub mod tests {
|
||||
(block, blobs, invalid_blobs)
|
||||
}
|
||||
|
||||
type ProcessingViewSetup<E> = (
|
||||
Arc<SignedBeaconBlock<E>>,
|
||||
FixedVector<Option<KzgCommitment>, <E as EthSpec>::MaxBlobsPerBlock>,
|
||||
FixedVector<Option<KzgCommitment>, <E as EthSpec>::MaxBlobsPerBlock>,
|
||||
);
|
||||
|
||||
pub fn setup_processing_components(
|
||||
block: SignedBeaconBlock<E>,
|
||||
valid_blobs: FixedVector<Option<Arc<BlobSidecar<E>>>, <E as EthSpec>::MaxBlobsPerBlock>,
|
||||
invalid_blobs: FixedVector<Option<Arc<BlobSidecar<E>>>, <E as EthSpec>::MaxBlobsPerBlock>,
|
||||
) -> ProcessingViewSetup<E> {
|
||||
let blobs = FixedVector::from(
|
||||
valid_blobs
|
||||
.iter()
|
||||
.map(|blob_opt| blob_opt.as_ref().map(|blob| blob.kzg_commitment))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
let invalid_blobs = FixedVector::from(
|
||||
invalid_blobs
|
||||
.iter()
|
||||
.map(|blob_opt| blob_opt.as_ref().map(|blob| blob.kzg_commitment))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
(Arc::new(block), blobs, invalid_blobs)
|
||||
}
|
||||
|
||||
type PendingComponentsSetup<E> = (
|
||||
DietAvailabilityPendingExecutedBlock<E>,
|
||||
FixedVector<Option<KzgVerifiedBlob<E>>, <E as EthSpec>::MaxBlobsPerBlock>,
|
||||
@@ -490,13 +455,6 @@ pub mod tests {
|
||||
};
|
||||
}
|
||||
|
||||
generate_tests!(
|
||||
processing_components_tests,
|
||||
ProcessingComponents::<E>,
|
||||
kzg_commitments,
|
||||
processing_blobs,
|
||||
setup_processing_components
|
||||
);
|
||||
generate_tests!(
|
||||
pending_components_tests,
|
||||
PendingComponents<E>,
|
||||
|
||||
@@ -305,6 +305,11 @@ impl<T: BeaconChainTypes> Critical<T> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns true if the block root is known, without altering the LRU ordering
|
||||
pub fn has_block(&self, block_root: &Hash256) -> bool {
|
||||
self.in_memory.peek(block_root).is_some() || self.store_keys.contains(block_root)
|
||||
}
|
||||
|
||||
/// This only checks for the blobs in memory
|
||||
pub fn peek_blob(
|
||||
&self,
|
||||
@@ -322,6 +327,13 @@ impl<T: BeaconChainTypes> Critical<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn peek_pending_components(
|
||||
&self,
|
||||
block_root: &Hash256,
|
||||
) -> Option<&PendingComponents<T::EthSpec>> {
|
||||
self.in_memory.peek(block_root)
|
||||
}
|
||||
|
||||
/// Puts the pending components in the LRU cache. If the cache
|
||||
/// is at capacity, the LRU entry is written to the store first
|
||||
pub fn put_pending_components(
|
||||
@@ -409,6 +421,11 @@ impl<T: BeaconChainTypes> OverflowLRUCache<T> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns true if the block root is known, without altering the LRU ordering
|
||||
pub fn has_block(&self, block_root: &Hash256) -> bool {
|
||||
self.critical.read().has_block(block_root)
|
||||
}
|
||||
|
||||
/// Fetch a blob from the cache without affecting the LRU ordering
|
||||
pub fn peek_blob(
|
||||
&self,
|
||||
@@ -425,6 +442,14 @@ impl<T: BeaconChainTypes> OverflowLRUCache<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_pending_components<R, F: FnOnce(Option<&PendingComponents<T::EthSpec>>) -> R>(
|
||||
&self,
|
||||
block_root: &Hash256,
|
||||
f: F,
|
||||
) -> R {
|
||||
f(self.critical.read().peek_pending_components(block_root))
|
||||
}
|
||||
|
||||
pub fn put_kzg_verified_blobs<I: IntoIterator<Item = KzgVerifiedBlob<T::EthSpec>>>(
|
||||
&self,
|
||||
block_root: Hash256,
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
use crate::data_availability_checker::AvailabilityView;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use types::beacon_block_body::KzgCommitmentOpts;
|
||||
use types::{EthSpec, Hash256, SignedBeaconBlock};
|
||||
|
||||
/// This cache is used only for gossip blocks/blobs and single block/blob lookups, to give req/resp
|
||||
/// a view of what we have and what we require. This cache serves a slightly different purpose than
|
||||
/// gossip caches because it allows us to process duplicate blobs that are valid in gossip.
|
||||
/// See `AvailabilityView`'s trait definition.
|
||||
#[derive(Default)]
|
||||
pub struct ProcessingCache<E: EthSpec> {
|
||||
processing_cache: HashMap<Hash256, ProcessingComponents<E>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ProcessingCache<E> {
|
||||
pub fn get(&self, block_root: &Hash256) -> Option<&ProcessingComponents<E>> {
|
||||
self.processing_cache.get(block_root)
|
||||
}
|
||||
pub fn entry(&mut self, block_root: Hash256) -> Entry<'_, Hash256, ProcessingComponents<E>> {
|
||||
self.processing_cache.entry(block_root)
|
||||
}
|
||||
pub fn remove(&mut self, block_root: &Hash256) {
|
||||
self.processing_cache.remove(block_root);
|
||||
}
|
||||
pub fn has_block(&self, block_root: &Hash256) -> bool {
|
||||
self.processing_cache
|
||||
.get(block_root)
|
||||
.map_or(false, |b| b.block_exists())
|
||||
}
|
||||
pub fn len(&self) -> usize {
|
||||
self.processing_cache.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ProcessingComponents<E: EthSpec> {
|
||||
/// Blobs required for a block can only be known if we have seen the block. So `Some` here
|
||||
/// means we've seen it, a `None` means we haven't. The `kzg_commitments` value helps us figure
|
||||
/// out whether incoming blobs actually match the block.
|
||||
pub block: Option<Arc<SignedBeaconBlock<E>>>,
|
||||
/// `KzgCommitments` for blobs are always known, even if we haven't seen the block. See
|
||||
/// `AvailabilityView`'s trait definition for more details.
|
||||
pub blob_commitments: KzgCommitmentOpts<E>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ProcessingComponents<E> {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
// Not safe for use outside of tests as this always required a slot.
|
||||
#[cfg(test)]
|
||||
impl<E: EthSpec> ProcessingComponents<E> {
|
||||
pub fn empty(_block_root: Hash256) -> Self {
|
||||
Self {
|
||||
block: None,
|
||||
blob_commitments: KzgCommitmentOpts::<E>::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user