mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Ensure lookup sync checks caches correctly (#5840)
* Ensure lookup sync checks caches correctly * fix tests and remove unused method * Simplify BlockProcessStatus
This commit is contained in:
@@ -1452,13 +1452,16 @@ fn block_in_processing_cache_becomes_invalid() {
|
||||
let peer_id = r.new_connected_peer();
|
||||
r.insert_block_to_processing_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);
|
||||
// Should not trigger block request
|
||||
r.expect_empty_network();
|
||||
// Simulate invalid block, removing it from processing cache
|
||||
r.simulate_block_gossip_processing_becomes_invalid(block_root);
|
||||
// Should download block, then issue blobs request
|
||||
r.complete_lookup_block_download(block);
|
||||
let id = r.expect_blob_lookup_request(block_root);
|
||||
// Should not trigger block or blob request
|
||||
r.expect_empty_network();
|
||||
r.complete_lookup_block_import_valid(block_root, false);
|
||||
// Resolve blob and expect lookup completed
|
||||
r.complete_single_lookup_blob_lookup_valid(id, peer_id, blobs, true);
|
||||
@@ -1475,11 +1478,14 @@ fn block_in_processing_cache_becomes_valid_imported() {
|
||||
let peer_id = r.new_connected_peer();
|
||||
r.insert_block_to_processing_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);
|
||||
// Should not trigger block request
|
||||
r.expect_empty_network();
|
||||
// Resolve the block from processing step
|
||||
r.simulate_block_gossip_processing_becomes_valid_missing_components(block.into());
|
||||
let id = r.expect_blob_lookup_request(block_root);
|
||||
// Should not trigger block or blob request
|
||||
r.expect_empty_network();
|
||||
// Resolve blob and expect lookup completed
|
||||
r.complete_single_lookup_blob_lookup_valid(id, peer_id, blobs, true);
|
||||
r.expect_no_active_lookups();
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::status::ToStatusMessage;
|
||||
use crate::sync::block_lookups::SingleLookupId;
|
||||
use crate::sync::manager::{BlockProcessType, SingleLookupReqId};
|
||||
use beacon_chain::block_verification_types::RpcBlock;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes, EngineState};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockProcessStatus, EngineState};
|
||||
use fnv::FnvHashMap;
|
||||
use lighthouse_network::rpc::methods::BlobsByRangeRequest;
|
||||
use lighthouse_network::rpc::{BlocksByRangeRequest, GoodbyeReason, RPCError};
|
||||
@@ -337,26 +337,17 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
peer_id: PeerId,
|
||||
block_root: Hash256,
|
||||
) -> Result<LookupRequestResult, RpcRequestSendError> {
|
||||
// da_checker includes block that are execution verified, but are missing components
|
||||
if self
|
||||
.chain
|
||||
.data_availability_checker
|
||||
.has_execution_valid_block(&block_root)
|
||||
{
|
||||
return Ok(LookupRequestResult::NoRequestNeeded);
|
||||
}
|
||||
|
||||
// reqresp_pre_import_cache includes blocks that may not be yet execution verified
|
||||
if self
|
||||
.chain
|
||||
.reqresp_pre_import_cache
|
||||
.read()
|
||||
.contains_key(&block_root)
|
||||
{
|
||||
// A block is on the `reqresp_pre_import_cache` but NOT in the
|
||||
// `data_availability_checker` only if it is actively processing. We can expect a future
|
||||
// event with the result of processing
|
||||
return Ok(LookupRequestResult::Pending);
|
||||
match self.chain.get_block_process_status(&block_root) {
|
||||
// Unknown block, continue request to download
|
||||
BlockProcessStatus::Unknown => {}
|
||||
// Block is known are currently processing, expect a future event with the result of
|
||||
// processing.
|
||||
BlockProcessStatus::NotValidated { .. } => return Ok(LookupRequestResult::Pending),
|
||||
// Block is fully validated. If it's not yet imported it's waiting for missing block
|
||||
// components. Consider this request completed and do nothing.
|
||||
BlockProcessStatus::ExecutionValidated { .. } => {
|
||||
return Ok(LookupRequestResult::NoRequestNeeded)
|
||||
}
|
||||
}
|
||||
|
||||
let req_id = self.next_id();
|
||||
@@ -401,9 +392,14 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
downloaded_block_expected_blobs: Option<usize>,
|
||||
) -> Result<LookupRequestResult, RpcRequestSendError> {
|
||||
let Some(expected_blobs) = downloaded_block_expected_blobs.or_else(|| {
|
||||
self.chain
|
||||
.data_availability_checker
|
||||
.num_expected_blobs(&block_root)
|
||||
// If the block is already being processed or fully validated, retrieve how many blobs
|
||||
// it expects. Consider any stage of the block. If the block root has been validated, we
|
||||
// can assert that this is the correct value of `blob_kzg_commitments_count`.
|
||||
match self.chain.get_block_process_status(&block_root) {
|
||||
BlockProcessStatus::Unknown => None,
|
||||
BlockProcessStatus::NotValidated(block)
|
||||
| BlockProcessStatus::ExecutionValidated(block) => Some(block.num_expected_blobs()),
|
||||
}
|
||||
}) else {
|
||||
// Wait to download the block before downloading blobs. Then we can be sure that the
|
||||
// block has data, so there's no need to do "blind" requests for all possible blobs and
|
||||
|
||||
Reference in New Issue
Block a user