Consolidate reqresp_pre_import_cache into data_availability_checker (#8045)

This PR consolidates the `reqresp_pre_import_cache` into the `data_availability_checker` for the following reasons:
- the `reqresp_pre_import_cache` suffers from the same TOCTOU bug we had with `data_availability_checker` earlier, and leads to unbounded memory leak, which we have observed over the last 6 months on some nodes.
- the `reqresp_pre_import_cache` is no longer necessary, because we now hold blocks in the `data_availability_checker` for longer since (#7961), and recent blocks can be served from the DA checker.

This PR also maintains the following functionalities
- Serving pre-executed blocks over RPC, and they're now served from the `data_availability_checker` instead.
- Using the cache for de-duplicating lookup requests.


  


Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>

Co-Authored-By: Jimmy Chen <jimmy@sigmaprime.io>
This commit is contained in:
Jimmy Chen
2025-09-19 17:01:13 +10:00
committed by GitHub
parent 4111bcb39b
commit 78d330e4b7
9 changed files with 239 additions and 208 deletions

View File

@@ -1500,11 +1500,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
let result = self
.chain
.process_block_with_early_caching(
.process_block(
block_root,
verified_block,
BlockImportSource::Gossip,
NotifyExecutionLayer::Yes,
BlockImportSource::Gossip,
|| Ok(()),
)
.await;
register_process_result_metrics(&result, metrics::BlockSource::Gossip, "block");

View File

@@ -168,11 +168,12 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
let signed_beacon_block = block.block_cloned();
let result = self
.chain
.process_block_with_early_caching(
.process_block(
block_root,
block,
BlockImportSource::Lookup,
NotifyExecutionLayer::Yes,
BlockImportSource::Lookup,
|| Ok(()),
)
.await;
register_process_result_metrics(&result, metrics::BlockSource::Rpc, "block");

View File

@@ -1079,7 +1079,7 @@ impl TestRig {
.harness
.chain
.data_availability_checker
.put_pending_executed_block(executed_block)
.put_executed_block(executed_block)
.unwrap()
{
Availability::Available(_) => panic!("block removed from da_checker, available"),
@@ -1109,20 +1109,19 @@ impl TestRig {
};
}
fn insert_block_to_processing_cache(&mut self, block: Arc<SignedBeaconBlock<E>>) {
fn insert_block_to_availability_cache(&mut self, block: Arc<SignedBeaconBlock<E>>) {
self.harness
.chain
.reqresp_pre_import_cache
.write()
.insert(block.canonical_root(), block);
.data_availability_checker
.put_pre_execution_block(block.canonical_root(), block)
.unwrap();
}
fn simulate_block_gossip_processing_becomes_invalid(&mut self, block_root: Hash256) {
self.harness
.chain
.reqresp_pre_import_cache
.write()
.remove(&block_root);
.data_availability_checker
.remove_block_on_execution_error(&block_root);
self.send_sync_message(SyncMessage::GossipBlockProcessResult {
block_root,
@@ -1135,11 +1134,6 @@ impl TestRig {
block: Arc<SignedBeaconBlock<E>>,
) {
let block_root = block.canonical_root();
self.harness
.chain
.reqresp_pre_import_cache
.write()
.remove(&block_root);
self.insert_block_to_da_checker(block);
@@ -1841,7 +1835,7 @@ fn block_in_processing_cache_becomes_invalid() {
let (block, blobs) = r.rand_block_and_blobs(NumBlobs::Number(1));
let block_root = block.canonical_root();
let peer_id = r.new_connected_peer();
r.insert_block_to_processing_cache(block.clone().into());
r.insert_block_to_availability_cache(block.clone().into());
r.trigger_unknown_block_from_attestation(block_root, peer_id);
// Should trigger blob request
let id = r.expect_blob_lookup_request(block_root);
@@ -1867,7 +1861,7 @@ fn block_in_processing_cache_becomes_valid_imported() {
let (block, blobs) = r.rand_block_and_blobs(NumBlobs::Number(1));
let block_root = block.canonical_root();
let peer_id = r.new_connected_peer();
r.insert_block_to_processing_cache(block.clone().into());
r.insert_block_to_availability_cache(block.clone().into());
r.trigger_unknown_block_from_attestation(block_root, peer_id);
// Should trigger blob request
let id = r.expect_blob_lookup_request(block_root);