mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
Drop overflow cache (#5891)
* Drop overflow cache * Update docs * Update beacon_node/store/src/lib.rs * Update data_availability_checker.rs * Lint
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::blob_verification::{verify_kzg_for_blob_list, GossipVerifiedBlob, Kzg
|
||||
use crate::block_verification_types::{
|
||||
AvailabilityPendingExecutedBlock, AvailableExecutedBlock, RpcBlock,
|
||||
};
|
||||
use crate::data_availability_checker::overflow_lru_cache::OverflowLRUCache;
|
||||
use crate::data_availability_checker::overflow_lru_cache::DataAvailabilityCheckerInner;
|
||||
use crate::{BeaconChain, BeaconChainTypes, BeaconStore};
|
||||
use kzg::Kzg;
|
||||
use slog::{debug, error, Logger};
|
||||
@@ -33,12 +33,32 @@ pub const OVERFLOW_LRU_CAPACITY: NonZeroUsize = new_non_zero_usize(1024);
|
||||
pub const STATE_LRU_CAPACITY_NON_ZERO: NonZeroUsize = new_non_zero_usize(2);
|
||||
pub const STATE_LRU_CAPACITY: usize = STATE_LRU_CAPACITY_NON_ZERO.get();
|
||||
|
||||
/// This includes a cache for any blocks or blobs that have been received over gossip or RPC
|
||||
/// and are awaiting more components before they can be imported. Additionally the
|
||||
/// `DataAvailabilityChecker` is responsible for KZG verification of block components as well as
|
||||
/// checking whether a "availability check" is required at all.
|
||||
/// Cache to hold fully valid data that can't be imported to fork-choice yet. After Dencun hard-fork
|
||||
/// blocks have a sidecar of data that is received separately from the network. We call the concept
|
||||
/// of a block "becoming available" when all of its import dependencies are inserted into this
|
||||
/// cache.
|
||||
///
|
||||
/// Usually a block becomes available on its slot within a second of receiving its first component
|
||||
/// over gossip. However, a block may never become available if a malicious proposer does not
|
||||
/// publish its data, or there are network issues that prevent us from receiving it. If the block
|
||||
/// does not become available after some time we can safely forget about it. Consider these two
|
||||
/// cases:
|
||||
///
|
||||
/// - Global unavailability: If nobody has received the block components it's likely that the
|
||||
/// proposer never made the block available. So we can safely forget about the block as it will
|
||||
/// never become available.
|
||||
/// - Local unavailability: Some fraction of the network has received all block components, but not us.
|
||||
/// Some of our peers will eventually attest to a descendant of that block and lookup sync will
|
||||
/// fetch its components. Therefore it's not strictly necessary to hold to the partially available
|
||||
/// block for too long as we can recover from other peers.
|
||||
///
|
||||
/// Even in periods of non-finality, the proposer is expected to publish the block's data
|
||||
/// immediately. Because this cache only holds fully valid data, its capacity is bound to 1 block
|
||||
/// per slot and fork: before inserting into this cache we check the proposer signature and correct
|
||||
/// proposer. Having a capacity > 1 is an optimization to prevent sync lookup from having re-fetch
|
||||
/// data during moments of unstable network conditions.
|
||||
pub struct DataAvailabilityChecker<T: BeaconChainTypes> {
|
||||
availability_cache: Arc<OverflowLRUCache<T>>,
|
||||
availability_cache: Arc<DataAvailabilityCheckerInner<T>>,
|
||||
slot_clock: T::SlotClock,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
log: Logger,
|
||||
@@ -74,7 +94,8 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
log: &Logger,
|
||||
spec: ChainSpec,
|
||||
) -> Result<Self, AvailabilityCheckError> {
|
||||
let overflow_cache = OverflowLRUCache::new(OVERFLOW_LRU_CAPACITY, store, spec.clone())?;
|
||||
let overflow_cache =
|
||||
DataAvailabilityCheckerInner::new(OVERFLOW_LRU_CAPACITY, store, spec.clone())?;
|
||||
Ok(Self {
|
||||
availability_cache: Arc::new(overflow_cache),
|
||||
slot_clock,
|
||||
@@ -329,15 +350,9 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Persist all in memory components to disk
|
||||
pub fn persist_all(&self) -> Result<(), AvailabilityCheckError> {
|
||||
self.availability_cache.write_all_to_disk()
|
||||
}
|
||||
|
||||
/// Collects metrics from the data availability checker.
|
||||
pub fn metrics(&self) -> DataAvailabilityCheckerMetrics {
|
||||
DataAvailabilityCheckerMetrics {
|
||||
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(),
|
||||
}
|
||||
@@ -346,7 +361,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
|
||||
/// Helper struct to group data availability checker metrics.
|
||||
pub struct DataAvailabilityCheckerMetrics {
|
||||
pub num_store_entries: usize,
|
||||
pub state_cache_size: usize,
|
||||
pub block_cache_size: usize,
|
||||
}
|
||||
@@ -372,7 +386,7 @@ pub fn start_availability_cache_maintenance_service<T: BeaconChainTypes>(
|
||||
|
||||
async fn availability_cache_maintenance_service<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
overflow_cache: Arc<OverflowLRUCache<T>>,
|
||||
overflow_cache: Arc<DataAvailabilityCheckerInner<T>>,
|
||||
) {
|
||||
let epoch_duration = chain.slot_clock.slot_duration() * T::EthSpec::slots_per_epoch() as u32;
|
||||
loop {
|
||||
|
||||
Reference in New Issue
Block a user