mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 22:08:30 +00:00
Remove grandparents from snapshot cache (#2917)
## Issue Addressed NA ## Proposed Changes In https://github.com/sigp/lighthouse/pull/2832 we made some changes to the `SnapshotCache` to help deal with the one-block reorgs seen on mainnet (and testnets). I believe the change in #2832 is good and we should keep it, but I think that in its present form it is causing the `SnapshotCache` to hold onto states that it doesn't need anymore. For example, a skip slot will result in one more `BeaconSnapshot` being stored in the cache. This PR adds a new type of pruning that happens after a block is inserted to the cache. We will remove any snapshot from the cache that is a *grandparent* of the block being imported. Since we know the grandparent has two valid blocks built atop it, it is not at risk from a one-block re-org. ## Additional Info NA
This commit is contained in:
@@ -2796,6 +2796,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
beacon_block_root: block_root,
|
||||
},
|
||||
None,
|
||||
&self.spec,
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|e| {
|
||||
@@ -3740,6 +3741,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.try_write_for(BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT)
|
||||
.map(|mut snapshot_cache| {
|
||||
snapshot_cache.prune(new_finalized_checkpoint.epoch);
|
||||
debug!(
|
||||
self.log,
|
||||
"Snapshot cache pruned";
|
||||
"new_len" => snapshot_cache.len(),
|
||||
"remaining_roots" => ?snapshot_cache.beacon_block_roots(),
|
||||
);
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
error!(
|
||||
|
||||
Reference in New Issue
Block a user