mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
deal with rpc blobs in groups per block in the da checker. don't cache missing blob ids in the da checker.
This commit is contained in:
@@ -625,15 +625,17 @@ impl<T: BeaconChainTypes> WorkEvent<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rpc_blob(
|
||||
blob: Arc<BlobSidecar<T::EthSpec>>,
|
||||
pub fn rpc_blobs(
|
||||
block_root: Hash256,
|
||||
blobs: Vec<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
seen_timestamp: Duration,
|
||||
process_type: BlockProcessType,
|
||||
) -> Self {
|
||||
Self {
|
||||
drop_during_sync: false,
|
||||
work: Work::RpcBlob {
|
||||
block: blob,
|
||||
work: Work::RpcBlobs {
|
||||
block_root,
|
||||
blobs,
|
||||
seen_timestamp,
|
||||
process_type,
|
||||
},
|
||||
@@ -936,8 +938,9 @@ pub enum Work<T: BeaconChainTypes> {
|
||||
process_type: BlockProcessType,
|
||||
should_process: bool,
|
||||
},
|
||||
RpcBlob {
|
||||
block: Arc<BlobSidecar<T::EthSpec>>,
|
||||
RpcBlobs {
|
||||
block_root: Hash256,
|
||||
blobs: Vec<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
seen_timestamp: Duration,
|
||||
process_type: BlockProcessType,
|
||||
},
|
||||
@@ -1000,7 +1003,7 @@ impl<T: BeaconChainTypes> Work<T> {
|
||||
Work::GossipLightClientFinalityUpdate { .. } => GOSSIP_LIGHT_CLIENT_FINALITY_UPDATE,
|
||||
Work::GossipLightClientOptimisticUpdate { .. } => GOSSIP_LIGHT_CLIENT_OPTIMISTIC_UPDATE,
|
||||
Work::RpcBlock { .. } => RPC_BLOCK,
|
||||
Work::RpcBlob { .. } => RPC_BLOB,
|
||||
Work::RpcBlobs { .. } => RPC_BLOB,
|
||||
Work::ChainSegment { .. } => CHAIN_SEGMENT,
|
||||
Work::Status { .. } => STATUS_PROCESSING,
|
||||
Work::BlocksByRangeRequest { .. } => BLOCKS_BY_RANGE_REQUEST,
|
||||
@@ -1513,7 +1516,7 @@ impl<T: BeaconChainTypes> BeaconProcessor<T> {
|
||||
optimistic_update_queue.push(work, work_id, &self.log)
|
||||
}
|
||||
Work::RpcBlock { .. } => rpc_block_queue.push(work, work_id, &self.log),
|
||||
Work::RpcBlob { .. } => rpc_blob_queue.push(work, work_id, &self.log),
|
||||
Work::RpcBlobs { .. } => rpc_blob_queue.push(work, work_id, &self.log),
|
||||
Work::ChainSegment { ref process_id, .. } => match process_id {
|
||||
ChainSegmentProcessId::RangeBatchId { .. }
|
||||
| ChainSegmentProcessId::ParentLookup { .. } => {
|
||||
@@ -1936,12 +1939,14 @@ impl<T: BeaconChainTypes> BeaconProcessor<T> {
|
||||
duplicate_cache,
|
||||
should_process,
|
||||
)),
|
||||
Work::RpcBlob {
|
||||
block,
|
||||
Work::RpcBlobs {
|
||||
block_root,
|
||||
blobs,
|
||||
seen_timestamp,
|
||||
process_type,
|
||||
} => task_spawner.spawn_async(worker.process_rpc_blob(
|
||||
block,
|
||||
} => task_spawner.spawn_async(worker.process_rpc_blobs(
|
||||
block_root,
|
||||
blobs,
|
||||
seen_timestamp,
|
||||
process_type,
|
||||
)),
|
||||
|
||||
@@ -136,16 +136,21 @@ impl<T: BeaconChainTypes> Worker<T> {
|
||||
drop(handle);
|
||||
}
|
||||
|
||||
pub async fn process_rpc_blob(
|
||||
pub async fn process_rpc_blobs(
|
||||
self,
|
||||
blob: Arc<BlobSidecar<T::EthSpec>>,
|
||||
block_root: Hash256,
|
||||
blobs: Vec<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
seen_timestamp: Duration,
|
||||
process_type: BlockProcessType,
|
||||
) {
|
||||
let result = self
|
||||
.chain
|
||||
.check_availability_and_maybe_import(
|
||||
|chain| chain.data_availability_checker.put_rpc_blob(blob),
|
||||
|chain| {
|
||||
chain
|
||||
.data_availability_checker
|
||||
.put_rpc_blobs(block_root, blobs)
|
||||
},
|
||||
CountUnrealized::True,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
@@ -19,6 +19,7 @@ use types::{BlobSidecar, SignedBeaconBlock};
|
||||
|
||||
use crate::beacon_processor::{ChainSegmentProcessId, WorkEvent};
|
||||
use crate::metrics;
|
||||
use crate::sync::block_lookups::single_block_lookup::SingleBlobRequest;
|
||||
|
||||
use self::parent_lookup::PARENT_FAIL_TOLERANCE;
|
||||
use self::{
|
||||
@@ -59,6 +60,8 @@ pub(crate) struct BlockLookups<T: BeaconChainTypes> {
|
||||
/// The flag allows us to determine if the peer returned data or sent us nothing.
|
||||
single_block_lookups: FnvHashMap<Id, SingleBlockRequest<SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS>>,
|
||||
|
||||
single_blob_lookups: FnvHashMap<Id, SingleBlobRequest<SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS>>,
|
||||
|
||||
/// The logger for the import manager.
|
||||
log: Logger,
|
||||
}
|
||||
@@ -72,6 +75,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
FAILED_CHAINS_CACHE_EXPIRY_SECONDS,
|
||||
)),
|
||||
single_block_lookups: Default::default(),
|
||||
single_blob_lookups: Default::default(),
|
||||
log,
|
||||
}
|
||||
}
|
||||
@@ -137,6 +141,56 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
cx: &mut SyncNetworkContext<T>,
|
||||
) {
|
||||
todo!()
|
||||
|
||||
//
|
||||
// let hash = Hash256::zero();
|
||||
//
|
||||
// // Do not re-request a blo that is already being requested
|
||||
// if self
|
||||
// .single_blob_lookups
|
||||
// .values_mut()
|
||||
// .any(|single_block_request| single_block_request.add_peer(&hash, &peer_id))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if self.parent_lookups.iter_mut().any(|parent_req| {
|
||||
// parent_req.add_peer(&hash, &peer_id) || parent_req.contains_block(&hash)
|
||||
// }) {
|
||||
// // If the block was already downloaded, or is being downloaded in this moment, do not
|
||||
// // request it.
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if self
|
||||
// .processing_parent_lookups
|
||||
// .values()
|
||||
// .any(|(hashes, _last_parent_request)| hashes.contains(&hash))
|
||||
// {
|
||||
// // we are already processing this block, ignore it.
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// debug!(
|
||||
// self.log,
|
||||
// "Searching for block";
|
||||
// "peer_id" => %peer_id,
|
||||
// "block" => %hash
|
||||
// );
|
||||
//
|
||||
// let mut single_block_request = SingleBlobRequest::new(hash, peer_id);
|
||||
//
|
||||
// let (peer_id, request) = single_block_request
|
||||
// .request_block()
|
||||
// .expect("none of the possible failure cases apply for a newly created block lookup");
|
||||
// if let Ok(request_id) = cx.single_block_lookup_request(peer_id, request) {
|
||||
// self.single_blob_lookups
|
||||
// .insert(request_id, single_block_request);
|
||||
//
|
||||
// metrics::set_gauge(
|
||||
// &metrics::SYNC_SINGLE_BLOB_LOOKUPS,
|
||||
// self.single_blob_lookups.len() as i64,
|
||||
// );
|
||||
}
|
||||
|
||||
pub fn search_block_delayed(
|
||||
@@ -171,6 +225,13 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
peer_id: PeerId,
|
||||
cx: &mut SyncNetworkContext<T>,
|
||||
) {
|
||||
//
|
||||
// let missing_ids = cx.chain.data_availability_checker.get_missing_blob_ids(block, Some(root));
|
||||
// // TODO(sean) how do we handle this erroring?
|
||||
// if let Ok(missing_ids) = missing_ids {
|
||||
// self.search_blobs(missing_ids, peer_id, cx);
|
||||
// }
|
||||
|
||||
let parent_root = block.parent_root();
|
||||
// If this block or it's parent is part of a known failed chain, ignore it.
|
||||
if self.failed_chains.contains(&parent_root) || self.failed_chains.contains(&block_root) {
|
||||
@@ -497,19 +558,17 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
};
|
||||
|
||||
match result {
|
||||
BlockProcessResult::Ok(status) => {
|
||||
match status {
|
||||
AvailabilityProcessingStatus::Imported(hash) => {
|
||||
trace!(self.log, "Single block processing succeeded"; "block" => %root);
|
||||
}
|
||||
AvailabilityProcessingStatus::PendingBlobs(blobs) => {
|
||||
// trigger?
|
||||
}
|
||||
AvailabilityProcessingStatus::PendingBlock(hash) => {
|
||||
// logic error
|
||||
}
|
||||
BlockProcessResult::Ok(status) => match status {
|
||||
AvailabilityProcessingStatus::Imported(hash) => {
|
||||
trace!(self.log, "Single block processing succeeded"; "block" => %root);
|
||||
}
|
||||
}
|
||||
AvailabilityProcessingStatus::PendingBlobs(blobs_ids) => {
|
||||
self.search_blobs(blobs_ids, peer_id, cx);
|
||||
}
|
||||
AvailabilityProcessingStatus::PendingBlock(hash) => {
|
||||
warn!(self.log, "Block processed but returned PendingBlock"; "block" => %hash);
|
||||
}
|
||||
},
|
||||
BlockProcessResult::Ignored => {
|
||||
// Beacon processor signalled to ignore the block processing result.
|
||||
// This implies that the cpu is overloaded. Drop the request.
|
||||
@@ -620,13 +679,18 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
BlockProcessResult::Ok(AvailabilityProcessingStatus::PendingBlock(_)) => {
|
||||
// doesn't make sense
|
||||
}
|
||||
BlockProcessResult::Ok(AvailabilityProcessingStatus::PendingBlobs(blobs)) => {
|
||||
// trigger
|
||||
BlockProcessResult::Ok(AvailabilityProcessingStatus::PendingBlobs(blobs_ids)) => {
|
||||
self.search_blobs(blobs_ids, peer_id, cx);
|
||||
}
|
||||
BlockProcessResult::Err(BlockError::ParentUnknown(block)) => {
|
||||
// need to keep looking for parents
|
||||
// add the block back to the queue and continue the search
|
||||
// TODO(sean) how do we handle this erroring?
|
||||
let missing_ids = cx
|
||||
.chain
|
||||
.data_availability_checker
|
||||
.get_missing_blob_ids(block.clone(), None)
|
||||
.unwrap_or_default();
|
||||
parent_lookup.add_block(block);
|
||||
self.search_blobs(missing_ids, peer_id, cx);
|
||||
self.request_parent(parent_lookup, cx);
|
||||
}
|
||||
BlockProcessResult::Ok(AvailabilityProcessingStatus::Imported(_))
|
||||
|
||||
@@ -29,7 +29,23 @@ pub struct SingleBlockRequest<const MAX_ATTEMPTS: u8> {
|
||||
failed_processing: u8,
|
||||
/// How many times have we attempted to download this block.
|
||||
failed_downloading: u8,
|
||||
missing_blobs: Vec<BlobIdentifier>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct SingleBlobRequest<const MAX_ATTEMPTS: u8> {
|
||||
/// The hash of the requested block.
|
||||
pub hash: Hash256,
|
||||
pub blob_ids: Vec<BlobIdentifier>,
|
||||
/// State of this request.
|
||||
pub state: State,
|
||||
/// Peers that should have this block.
|
||||
pub available_peers: HashSet<PeerId>,
|
||||
/// Peers from which we have requested this block.
|
||||
pub used_peers: HashSet<PeerId>,
|
||||
/// How many times have we attempted to process this block.
|
||||
failed_processing: u8,
|
||||
/// How many times have we attempted to download this block.
|
||||
failed_downloading: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@@ -65,7 +81,6 @@ impl<const MAX_ATTEMPTS: u8> SingleBlockRequest<MAX_ATTEMPTS> {
|
||||
used_peers: HashSet::default(),
|
||||
failed_processing: 0,
|
||||
failed_downloading: 0,
|
||||
missing_blobs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ pub struct SyncNetworkContext<T: BeaconChainTypes> {
|
||||
/// Channel to send work to the beacon processor.
|
||||
beacon_processor_send: mpsc::Sender<WorkEvent<T>>,
|
||||
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
pub chain: Arc<BeaconChain<T>>,
|
||||
|
||||
/// Logger for the `SyncNetworkContext`.
|
||||
log: slog::Logger,
|
||||
@@ -411,6 +411,8 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(sean) add single blob lookup + parent lookup request methods
|
||||
|
||||
/// Sends a blocks by root request for a single block lookup.
|
||||
pub fn single_block_lookup_request(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user