mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Remove DataAvailabilityView trait from ChildComponents (#5421)
* Remove DataAvailabilityView trait from ChildComponents * PR reviews * Update beacon_node/network/src/sync/block_lookups/common.rs Co-authored-by: realbigsean <seananderson33@GMAIL.com> * Merge branch 'unstable' of https://github.com/sigp/lighthouse into child_components_independent
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::sync::block_lookups::{
|
||||
use crate::sync::manager::{BlockProcessType, Id, SingleLookupReqId};
|
||||
use crate::sync::network_context::SyncNetworkContext;
|
||||
use beacon_chain::block_verification_types::RpcBlock;
|
||||
use beacon_chain::data_availability_checker::{AvailabilityView, ChildComponents};
|
||||
use beacon_chain::data_availability_checker::ChildComponents;
|
||||
use beacon_chain::{get_block_root, BeaconChainTypes};
|
||||
use lighthouse_network::rpc::methods::BlobsByRootRequest;
|
||||
use lighthouse_network::rpc::BlocksByRootRequest;
|
||||
@@ -17,7 +17,7 @@ use std::ops::IndexMut;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use types::blob_sidecar::{BlobIdentifier, FixedBlobSidecarList};
|
||||
use types::{BlobSidecar, ChainSpec, EthSpec, Hash256, SignedBeaconBlock};
|
||||
use types::{BlobSidecar, ChainSpec, Hash256, SignedBeaconBlock};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum ResponseType {
|
||||
@@ -371,27 +371,35 @@ impl<L: Lookup, T: BeaconChainTypes> RequestState<L, T> for BlobRequestState<L,
|
||||
|
||||
fn verify_response_inner(
|
||||
&mut self,
|
||||
_expected_block_root: Hash256,
|
||||
expected_block_root: Hash256,
|
||||
blob: Option<Self::ResponseType>,
|
||||
peer_id: PeerId,
|
||||
) -> Result<Option<FixedBlobSidecarList<T::EthSpec>>, LookupVerifyError> {
|
||||
match blob {
|
||||
Some(blob) => {
|
||||
let received_id = blob.id();
|
||||
if !self.requested_ids.contains(&received_id) {
|
||||
self.state.register_failure_downloading();
|
||||
Err(LookupVerifyError::UnrequestedBlobId(received_id))
|
||||
} else {
|
||||
// State should remain downloading until we receive the stream terminator.
|
||||
self.requested_ids.remove(&received_id);
|
||||
let blob_index = blob.index;
|
||||
|
||||
if blob_index >= T::EthSpec::max_blobs_per_block() as u64 {
|
||||
return Err(LookupVerifyError::InvalidIndex(blob.index));
|
||||
}
|
||||
*self.blob_download_queue.index_mut(blob_index as usize) = Some(blob);
|
||||
Ok(None)
|
||||
if !self.requested_ids.contains(&received_id) {
|
||||
Err(LookupVerifyError::UnrequestedBlobId(received_id))
|
||||
} else if !blob.verify_blob_sidecar_inclusion_proof().unwrap_or(false) {
|
||||
Err(LookupVerifyError::InvalidInclusionProof)
|
||||
} else if blob.block_root() != expected_block_root {
|
||||
Err(LookupVerifyError::UnrequestedHeader)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
.map_err(|e| {
|
||||
self.state.register_failure_downloading();
|
||||
e
|
||||
})?;
|
||||
|
||||
// State should remain downloading until we receive the stream terminator.
|
||||
self.requested_ids.remove(&received_id);
|
||||
|
||||
// The inclusion proof check above ensures `blob.index` is < MAX_BLOBS_PER_BLOCK
|
||||
let blob_index = blob.index;
|
||||
*self.blob_download_queue.index_mut(blob_index as usize) = Some(blob);
|
||||
Ok(None)
|
||||
}
|
||||
None => {
|
||||
self.state.state = State::Processing { peer_id };
|
||||
|
||||
@@ -570,6 +570,8 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||
| ParentVerifyError::NotEnoughBlobsReturned
|
||||
| ParentVerifyError::ExtraBlocksReturned
|
||||
| ParentVerifyError::UnrequestedBlobId(_)
|
||||
| ParentVerifyError::InvalidInclusionProof
|
||||
| ParentVerifyError::UnrequestedHeader
|
||||
| ParentVerifyError::ExtraBlobsReturned
|
||||
| ParentVerifyError::InvalidIndex(_) => {
|
||||
let e = e.into();
|
||||
|
||||
@@ -38,6 +38,8 @@ pub enum ParentVerifyError {
|
||||
NotEnoughBlobsReturned,
|
||||
ExtraBlocksReturned,
|
||||
UnrequestedBlobId(BlobIdentifier),
|
||||
InvalidInclusionProof,
|
||||
UnrequestedHeader,
|
||||
ExtraBlobsReturned,
|
||||
InvalidIndex(u64),
|
||||
PreviousFailure { parent_root: Hash256 },
|
||||
@@ -244,6 +246,8 @@ impl From<LookupVerifyError> for ParentVerifyError {
|
||||
E::NoBlockReturned => ParentVerifyError::NoBlockReturned,
|
||||
E::ExtraBlocksReturned => ParentVerifyError::ExtraBlocksReturned,
|
||||
E::UnrequestedBlobId(blob_id) => ParentVerifyError::UnrequestedBlobId(blob_id),
|
||||
E::InvalidInclusionProof => ParentVerifyError::InvalidInclusionProof,
|
||||
E::UnrequestedHeader => ParentVerifyError::UnrequestedHeader,
|
||||
E::ExtraBlobsReturned => ParentVerifyError::ExtraBlobsReturned,
|
||||
E::InvalidIndex(index) => ParentVerifyError::InvalidIndex(index),
|
||||
E::NotEnoughBlobsReturned => ParentVerifyError::NotEnoughBlobsReturned,
|
||||
|
||||
@@ -3,10 +3,10 @@ use crate::sync::block_lookups::common::{Lookup, RequestState};
|
||||
use crate::sync::block_lookups::Id;
|
||||
use crate::sync::network_context::SyncNetworkContext;
|
||||
use beacon_chain::block_verification_types::RpcBlock;
|
||||
use beacon_chain::data_availability_checker::ChildComponents;
|
||||
use beacon_chain::data_availability_checker::{
|
||||
AvailabilityCheckError, DataAvailabilityChecker, MissingBlobs,
|
||||
};
|
||||
use beacon_chain::data_availability_checker::{AvailabilityView, ChildComponents};
|
||||
use beacon_chain::BeaconChainTypes;
|
||||
use lighthouse_network::PeerAction;
|
||||
use slog::{trace, Logger};
|
||||
@@ -32,6 +32,8 @@ pub enum LookupVerifyError {
|
||||
NoBlockReturned,
|
||||
ExtraBlocksReturned,
|
||||
UnrequestedBlobId(BlobIdentifier),
|
||||
InvalidInclusionProof,
|
||||
UnrequestedHeader,
|
||||
ExtraBlobsReturned,
|
||||
NotEnoughBlobsReturned,
|
||||
InvalidIndex(u64),
|
||||
@@ -247,7 +249,7 @@ impl<L: Lookup, T: BeaconChainTypes> SingleBlockLookup<L, T> {
|
||||
/// Returns `true` if the block has already been downloaded.
|
||||
pub(crate) fn block_already_downloaded(&self) -> bool {
|
||||
if let Some(components) = self.child_components.as_ref() {
|
||||
components.block_exists()
|
||||
components.downloaded_block.is_some()
|
||||
} else {
|
||||
self.da_checker.has_block(&self.block_root())
|
||||
}
|
||||
@@ -274,19 +276,25 @@ impl<L: Lookup, T: BeaconChainTypes> SingleBlockLookup<L, T> {
|
||||
pub(crate) fn missing_blob_ids(&self) -> MissingBlobs {
|
||||
let block_root = self.block_root();
|
||||
if let Some(components) = self.child_components.as_ref() {
|
||||
self.da_checker.get_missing_blob_ids(block_root, components)
|
||||
self.da_checker.get_missing_blob_ids(
|
||||
block_root,
|
||||
&components.downloaded_block,
|
||||
&components.downloaded_blobs,
|
||||
)
|
||||
} else {
|
||||
let Some(processing_availability_view) =
|
||||
self.da_checker.get_processing_components(block_root)
|
||||
let Some(processing_components) = self.da_checker.get_processing_components(block_root)
|
||||
else {
|
||||
return MissingBlobs::new_without_block(block_root, self.da_checker.is_deneb());
|
||||
};
|
||||
self.da_checker
|
||||
.get_missing_blob_ids(block_root, &processing_availability_view)
|
||||
self.da_checker.get_missing_blob_ids(
|
||||
block_root,
|
||||
&processing_components.block,
|
||||
&processing_components.blob_commitments,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Penalizes a blob peer if it should have blobs but didn't return them to us.
|
||||
/// Penalizes a blob peer if it should have blobs but didn't return them to us.
|
||||
pub fn penalize_blob_peer(&mut self, cx: &SyncNetworkContext<T>) {
|
||||
if let Ok(blob_peer) = self.blob_request_state.state.processing_peer() {
|
||||
cx.report_peer(
|
||||
|
||||
Reference in New Issue
Block a user