Refactor deneb block processing (#4511)

* Revert "fix merge"

This reverts commit 405e95b0ce.

* refactor deneb block processing

* cargo fmt

* fix ci
This commit is contained in:
realbigsean
2023-07-25 10:51:10 -04:00
committed by GitHub
parent 3735450749
commit 33dd13c798
33 changed files with 931 additions and 952 deletions

View File

@@ -10,7 +10,7 @@ use super::{
use crate::metrics;
use crate::network_beacon_processor::ChainSegmentProcessId;
use crate::sync::block_lookups::single_block_lookup::LookupId;
use beacon_chain::blob_verification::{AsBlock, BlockWrapper};
use beacon_chain::block_verification_types::{AsBlock, RpcBlock};
use beacon_chain::data_availability_checker::{AvailabilityCheckError, DataAvailabilityChecker};
use beacon_chain::{AvailabilityProcessingStatus, BeaconChainTypes, BlockError};
use lighthouse_network::rpc::RPCError;
@@ -34,7 +34,7 @@ mod single_block_lookup;
#[cfg(test)]
mod tests;
pub type DownloadedBlocks<T> = (Hash256, BlockWrapper<T>);
pub type DownloadedBlocks<T> = (Hash256, RpcBlock<T>);
pub type RootBlockTuple<T> = (Hash256, Arc<SignedBeaconBlock<T>>);
pub type RootBlobsTuple<T> = (Hash256, FixedBlobSidecarList<T>);
@@ -381,7 +381,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
if !has_pending_parent_request {
let rpc_block = request_ref
.get_downloaded_block()
.unwrap_or(BlockWrapper::Block(block));
.unwrap_or(RpcBlock::new_without_blobs(block));
// This is the correct block, send it for processing
match self.send_block_for_processing(
block_root,
@@ -910,11 +910,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
BlockError::ParentUnknown(block) => {
let slot = block.slot();
let parent_root = block.parent_root();
let (block, blobs) = block.deconstruct();
request_ref.add_unknown_parent_components(UnknownParentComponents::new(
Some(block),
blobs,
));
request_ref.add_unknown_parent_components(block.into());
self.search_parent(slot, root, parent_root, peer_id.to_peer_id(), cx);
ShouldRemoveLookup::False
}
@@ -1226,7 +1222,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
fn send_block_for_processing(
&mut self,
block_root: Hash256,
block: BlockWrapper<T::EthSpec>,
block: RpcBlock<T::EthSpec>,
duration: Duration,
process_type: BlockProcessType,
cx: &mut SyncNetworkContext<T>,

View File

@@ -3,8 +3,8 @@ use super::{BlobRequestId, BlockRequestId, DownloadedBlocks, PeerShouldHave, Res
use crate::sync::block_lookups::single_block_lookup::{State, UnknownParentComponents};
use crate::sync::block_lookups::{RootBlobsTuple, RootBlockTuple};
use crate::sync::{manager::SLOT_IMPORT_TOLERANCE, network_context::SyncNetworkContext};
use beacon_chain::blob_verification::AsBlock;
use beacon_chain::blob_verification::BlockWrapper;
use beacon_chain::block_verification_types::AsBlock;
use beacon_chain::block_verification_types::RpcBlock;
use beacon_chain::data_availability_checker::DataAvailabilityChecker;
use beacon_chain::BeaconChainTypes;
use lighthouse_network::PeerId;
@@ -147,7 +147,7 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
.check_peer_disconnected(peer_id)
}
pub fn add_unknown_parent_block(&mut self, block: BlockWrapper<T::EthSpec>) {
pub fn add_unknown_parent_block(&mut self, block: RpcBlock<T::EthSpec>) {
let next_parent = block.parent_root();
// Cache the block.
@@ -203,7 +203,7 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
self,
) -> (
Hash256,
Vec<BlockWrapper<T::EthSpec>>,
Vec<RpcBlock<T::EthSpec>>,
Vec<Hash256>,
SingleBlockLookup<PARENT_FAIL_TOLERANCE, T>,
) {

View File

@@ -1,6 +1,6 @@
use crate::sync::block_lookups::{BlobRequestId, BlockRequestId, RootBlobsTuple, RootBlockTuple};
use crate::sync::network_context::SyncNetworkContext;
use beacon_chain::blob_verification::BlockWrapper;
use beacon_chain::block_verification_types::RpcBlock;
use beacon_chain::data_availability_checker::DataAvailabilityChecker;
use beacon_chain::{get_block_root, BeaconChainTypes};
use lighthouse_network::rpc::methods::BlobsByRootRequest;
@@ -138,6 +138,16 @@ pub struct UnknownParentComponents<E: EthSpec> {
pub downloaded_blobs: FixedBlobSidecarList<E>,
}
impl<E: EthSpec> From<RpcBlock<E>> for UnknownParentComponents<E> {
fn from(value: RpcBlock<E>) -> Self {
let (block, blobs) = value.deconstruct();
let fixed_blobs = blobs.map(|blobs| {
FixedBlobSidecarList::from(blobs.into_iter().map(Some).collect::<Vec<_>>())
});
Self::new(Some(block), fixed_blobs)
}
}
impl<E: EthSpec> UnknownParentComponents<E> {
pub fn new(
block: Option<Arc<SignedBeaconBlock<E>>>,
@@ -284,7 +294,7 @@ impl<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> SingleBlockLookup<MAX_ATTEMPTS
};
}
pub fn get_downloaded_block(&mut self) -> Option<BlockWrapper<T::EthSpec>> {
pub fn get_downloaded_block(&mut self) -> Option<RpcBlock<T::EthSpec>> {
self.unknown_parent_components
.as_mut()
.and_then(|components| {
@@ -302,8 +312,16 @@ impl<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> SingleBlockLookup<MAX_ATTEMPTS
downloaded_block,
downloaded_blobs,
} = components;
downloaded_block.as_ref().map(|block| {
BlockWrapper::BlockAndBlobs(block.clone(), std::mem::take(downloaded_blobs))
downloaded_block.as_ref().and_then(|block| {
//TODO(sean) figure out how to properly deal with a consistency error here,
// should we downscore the peer sending blobs?
let blobs = std::mem::take(downloaded_blobs);
let filtered = blobs
.into_iter()
.filter_map(|b| b.clone())
.collect::<Vec<_>>();
let blobs = VariableList::from(filtered);
RpcBlock::new(block.clone(), Some(blobs)).ok()
})
} else {
None

View File

@@ -1474,7 +1474,7 @@ mod deneb_only {
fn parent_block_unknown_parent(mut self) -> Self {
self.bl.parent_block_processed(
self.block_root,
BlockProcessingResult::Err(BlockError::ParentUnknown(BlockWrapper::Block(
BlockProcessingResult::Err(BlockError::ParentUnknown(RpcBlock::new_without_blobs(
self.parent_block.clone().expect("parent block"),
))),
ResponseType::Block,