mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 23:04:53 +00:00
Merge parent and current sync lookups (#5655)
* Drop lookup type trait for a simple arg * Drop reconstructed for processing * Send parent blocks one by one * Merge current and parent lookups * Merge current and parent lookups clean up todos * Merge current and parent lookups tests * Merge remote-tracking branch 'origin/unstable' into sync-merged-lookup * Merge branch 'unstable' of https://github.com/sigp/lighthouse into sync-merged-lookup * fix compile after merge * #5655 pr review (#26) * fix compile after merge * remove todos, fix typos etc * fix compile * stable rng * delete TODO and unfilled out test * make download result a struct * enums instead of bools as params * fix comment * Various fixes * Track ignored child components * Track dropped lookup reason as metric * fix test * add comment describing behavior of avail check error * update ordering
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
use crate::block_verification_types::RpcBlock;
|
||||
use bls::Hash256;
|
||||
use std::sync::Arc;
|
||||
use types::blob_sidecar::FixedBlobSidecarList;
|
||||
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
|
||||
|
||||
/// For requests triggered by an `UnknownBlockParent` or `UnknownBlobParent`, this struct
|
||||
/// is used to cache components as they are sent to the network service. We can't use the
|
||||
/// data availability cache currently because any blocks or blobs without parents
|
||||
/// won't pass validation and therefore won't make it into the cache.
|
||||
pub struct ChildComponents<E: EthSpec> {
|
||||
pub block_root: Hash256,
|
||||
pub downloaded_block: Option<Arc<SignedBeaconBlock<E>>>,
|
||||
pub downloaded_blobs: FixedBlobSidecarList<E>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<RpcBlock<E>> for ChildComponents<E> {
|
||||
fn from(value: RpcBlock<E>) -> Self {
|
||||
let (block_root, block, blobs) = value.deconstruct();
|
||||
let fixed_blobs = blobs.map(|blobs| {
|
||||
FixedBlobSidecarList::from(blobs.into_iter().map(Some).collect::<Vec<_>>())
|
||||
});
|
||||
Self::new(block_root, Some(block), fixed_blobs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ChildComponents<E> {
|
||||
pub fn empty(block_root: Hash256) -> Self {
|
||||
Self {
|
||||
block_root,
|
||||
downloaded_block: None,
|
||||
downloaded_blobs: <_>::default(),
|
||||
}
|
||||
}
|
||||
pub fn new(
|
||||
block_root: Hash256,
|
||||
block: Option<Arc<SignedBeaconBlock<E>>>,
|
||||
blobs: Option<FixedBlobSidecarList<E>>,
|
||||
) -> Self {
|
||||
let mut cache = Self::empty(block_root);
|
||||
if let Some(block) = block {
|
||||
cache.merge_block(block);
|
||||
}
|
||||
if let Some(blobs) = blobs {
|
||||
cache.merge_blobs(blobs);
|
||||
}
|
||||
cache
|
||||
}
|
||||
|
||||
pub fn merge_block(&mut self, block: Arc<SignedBeaconBlock<E>>) {
|
||||
self.downloaded_block = Some(block);
|
||||
}
|
||||
|
||||
pub fn merge_blob(&mut self, blob: Arc<BlobSidecar<E>>) {
|
||||
if let Some(blob_ref) = self.downloaded_blobs.get_mut(blob.index as usize) {
|
||||
*blob_ref = Some(blob);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_blobs(&mut self, blobs: FixedBlobSidecarList<E>) {
|
||||
for blob in blobs.iter().flatten() {
|
||||
self.merge_blob(blob.clone());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear_blobs(&mut self) {
|
||||
self.downloaded_blobs = FixedBlobSidecarList::default();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ pub enum Error {
|
||||
SlotClockError,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub enum ErrorCategory {
|
||||
/// Internal Errors (not caused by peers)
|
||||
Internal,
|
||||
|
||||
@@ -569,7 +569,7 @@ impl<T: BeaconChainTypes> OverflowLRUCache<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_pending_components<R, F: FnOnce(Option<&PendingComponents<T::EthSpec>>) -> R>(
|
||||
pub fn peek_pending_components<R, F: FnOnce(Option<&PendingComponents<T::EthSpec>>) -> R>(
|
||||
&self,
|
||||
block_root: &Hash256,
|
||||
f: F,
|
||||
|
||||
Reference in New Issue
Block a user