mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
remove ForceBlockLookup
This commit is contained in:
@@ -41,13 +41,6 @@ pub type RootBlockTuple<T> = (Hash256, BlockWrapper<T>);
|
|||||||
const FAILED_CHAINS_CACHE_EXPIRY_SECONDS: u64 = 60;
|
const FAILED_CHAINS_CACHE_EXPIRY_SECONDS: u64 = 60;
|
||||||
const SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS: u8 = 3;
|
const SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS: u8 = 3;
|
||||||
|
|
||||||
/// This is used to resolve the scenario where we request a parent from before the data availability
|
|
||||||
/// boundary and need to retry with a request for only the block.
|
|
||||||
pub enum ForceBlockRequest {
|
|
||||||
True,
|
|
||||||
False,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct BlockLookups<T: BeaconChainTypes> {
|
pub(crate) struct BlockLookups<T: BeaconChainTypes> {
|
||||||
/// Parent chain lookups being downloaded.
|
/// Parent chain lookups being downloaded.
|
||||||
parent_lookups: SmallVec<[ParentLookup<T>; 3]>,
|
parent_lookups: SmallVec<[ParentLookup<T>; 3]>,
|
||||||
@@ -204,7 +197,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let parent_lookup = ParentLookup::new(block_root, block, peer_id);
|
let parent_lookup = ParentLookup::new(block_root, block, peer_id);
|
||||||
self.request_parent(parent_lookup, cx, ForceBlockRequest::False);
|
self.request_parent(parent_lookup, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lookup responses */
|
/* Lookup responses */
|
||||||
@@ -330,7 +323,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
cx.report_peer(peer_id, PeerAction::LowToleranceError, e);
|
cx.report_peer(peer_id, PeerAction::LowToleranceError, e);
|
||||||
|
|
||||||
// We try again if possible.
|
// We try again if possible.
|
||||||
self.request_parent(parent_lookup, cx, ForceBlockRequest::False);
|
self.request_parent(parent_lookup, cx);
|
||||||
}
|
}
|
||||||
VerifyError::PreviousFailure { parent_root } => {
|
VerifyError::PreviousFailure { parent_root } => {
|
||||||
debug!(
|
debug!(
|
||||||
@@ -406,7 +399,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
{
|
{
|
||||||
let parent_lookup = self.parent_lookups.remove(pos);
|
let parent_lookup = self.parent_lookups.remove(pos);
|
||||||
trace!(self.log, "Parent lookup's peer disconnected"; &parent_lookup);
|
trace!(self.log, "Parent lookup's peer disconnected"; &parent_lookup);
|
||||||
self.request_parent(parent_lookup, cx, ForceBlockRequest::False);
|
self.request_parent(parent_lookup, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,18 +420,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
parent_lookup.download_failed();
|
parent_lookup.download_failed();
|
||||||
trace!(self.log, "Parent lookup request failed"; &parent_lookup);
|
trace!(self.log, "Parent lookup request failed"; &parent_lookup);
|
||||||
|
|
||||||
// `ResourceUnavailable` indicates we requested a parent block from prior to the 4844 fork epoch.
|
self.request_parent(parent_lookup, cx);
|
||||||
let force_block_request = if let RPCError::ErrorResponse(
|
|
||||||
RPCResponseErrorCode::ResourceUnavailable,
|
|
||||||
_,
|
|
||||||
) = error
|
|
||||||
{
|
|
||||||
debug!(self.log, "RPC parent lookup for block and blobs failed. Retrying the request for just a block"; "peer_id" => %peer_id);
|
|
||||||
ForceBlockRequest::True
|
|
||||||
} else {
|
|
||||||
ForceBlockRequest::False
|
|
||||||
};
|
|
||||||
self.request_parent(parent_lookup, cx, force_block_request);
|
|
||||||
} else {
|
} else {
|
||||||
return debug!(self.log, "RPC failure for a parent lookup request that was not found"; "peer_id" => %peer_id);
|
return debug!(self.log, "RPC failure for a parent lookup request that was not found"; "peer_id" => %peer_id);
|
||||||
};
|
};
|
||||||
@@ -603,7 +585,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
// need to keep looking for parents
|
// need to keep looking for parents
|
||||||
// add the block back to the queue and continue the search
|
// add the block back to the queue and continue the search
|
||||||
parent_lookup.add_block(block);
|
parent_lookup.add_block(block);
|
||||||
self.request_parent(parent_lookup, cx, ForceBlockRequest::False);
|
self.request_parent(parent_lookup, cx);
|
||||||
}
|
}
|
||||||
BlockProcessResult::Ok
|
BlockProcessResult::Ok
|
||||||
| BlockProcessResult::Err(BlockError::BlockIsAlreadyKnown { .. }) => {
|
| BlockProcessResult::Err(BlockError::BlockIsAlreadyKnown { .. }) => {
|
||||||
@@ -665,7 +647,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
|
|
||||||
// Try again if possible
|
// Try again if possible
|
||||||
parent_lookup.processing_failed();
|
parent_lookup.processing_failed();
|
||||||
self.request_parent(parent_lookup, cx, ForceBlockRequest::False);
|
self.request_parent(parent_lookup, cx);
|
||||||
}
|
}
|
||||||
BlockProcessResult::Ignored => {
|
BlockProcessResult::Ignored => {
|
||||||
// Beacon processor signalled to ignore the block processing result.
|
// Beacon processor signalled to ignore the block processing result.
|
||||||
@@ -758,9 +740,8 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut parent_lookup: ParentLookup<T>,
|
mut parent_lookup: ParentLookup<T>,
|
||||||
cx: &mut SyncNetworkContext<T>,
|
cx: &mut SyncNetworkContext<T>,
|
||||||
force_block_request: ForceBlockRequest,
|
|
||||||
) {
|
) {
|
||||||
match parent_lookup.request_parent(cx, force_block_request) {
|
match parent_lookup.request_parent(cx) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(self.log, "Failed to request parent"; &parent_lookup, "error" => e.as_static());
|
debug!(self.log, "Failed to request parent"; &parent_lookup, "error" => e.as_static());
|
||||||
match e {
|
match e {
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
use super::RootBlockTuple;
|
use super::RootBlockTuple;
|
||||||
|
use crate::sync::{
|
||||||
|
manager::{Id, SLOT_IMPORT_TOLERANCE},
|
||||||
|
network_context::SyncNetworkContext,
|
||||||
|
};
|
||||||
use beacon_chain::blob_verification::AsBlock;
|
use beacon_chain::blob_verification::AsBlock;
|
||||||
use beacon_chain::blob_verification::BlockWrapper;
|
use beacon_chain::blob_verification::BlockWrapper;
|
||||||
use beacon_chain::BeaconChainTypes;
|
use beacon_chain::BeaconChainTypes;
|
||||||
@@ -6,12 +10,6 @@ use lighthouse_network::PeerId;
|
|||||||
use store::Hash256;
|
use store::Hash256;
|
||||||
use strum::IntoStaticStr;
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
use crate::sync::block_lookups::ForceBlockRequest;
|
|
||||||
use crate::sync::{
|
|
||||||
manager::{Id, SLOT_IMPORT_TOLERANCE},
|
|
||||||
network_context::SyncNetworkContext,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::single_block_lookup::{self, SingleBlockRequest};
|
use super::single_block_lookup::{self, SingleBlockRequest};
|
||||||
|
|
||||||
/// How many attempts we try to find a parent of a block before we give up trying.
|
/// How many attempts we try to find a parent of a block before we give up trying.
|
||||||
@@ -73,18 +71,14 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to request the next unknown parent. If the request fails, it should be removed.
|
/// Attempts to request the next unknown parent. If the request fails, it should be removed.
|
||||||
pub fn request_parent(
|
pub fn request_parent(&mut self, cx: &mut SyncNetworkContext<T>) -> Result<(), RequestError> {
|
||||||
&mut self,
|
|
||||||
cx: &mut SyncNetworkContext<T>,
|
|
||||||
force_block_request: ForceBlockRequest,
|
|
||||||
) -> Result<(), RequestError> {
|
|
||||||
// check to make sure this request hasn't failed
|
// check to make sure this request hasn't failed
|
||||||
if self.downloaded_blocks.len() >= PARENT_DEPTH_TOLERANCE {
|
if self.downloaded_blocks.len() >= PARENT_DEPTH_TOLERANCE {
|
||||||
return Err(RequestError::ChainTooLong);
|
return Err(RequestError::ChainTooLong);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (peer_id, request) = self.current_parent_request.request_block()?;
|
let (peer_id, request) = self.current_parent_request.request_block()?;
|
||||||
match cx.parent_lookup_request(peer_id, request, force_block_request) {
|
match cx.parent_lookup_request(peer_id, request) {
|
||||||
Ok(request_id) => {
|
Ok(request_id) => {
|
||||||
self.current_parent_request_id = Some(request_id);
|
self.current_parent_request_id = Some(request_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use super::range_sync::{BatchId, ByRangeRequestType, ChainId};
|
|||||||
use crate::beacon_processor::WorkEvent;
|
use crate::beacon_processor::WorkEvent;
|
||||||
use crate::service::{NetworkMessage, RequestId};
|
use crate::service::{NetworkMessage, RequestId};
|
||||||
use crate::status::ToStatusMessage;
|
use crate::status::ToStatusMessage;
|
||||||
use crate::sync::block_lookups::ForceBlockRequest;
|
|
||||||
use beacon_chain::blob_verification::BlockWrapper;
|
use beacon_chain::blob_verification::BlockWrapper;
|
||||||
use beacon_chain::{BeaconChain, BeaconChainTypes, EngineState};
|
use beacon_chain::{BeaconChain, BeaconChainTypes, EngineState};
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
@@ -453,13 +452,11 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
request: BlocksByRootRequest,
|
request: BlocksByRootRequest,
|
||||||
force_block_request: ForceBlockRequest,
|
|
||||||
) -> Result<Id, &'static str> {
|
) -> Result<Id, &'static str> {
|
||||||
let request = if self
|
let request = if self
|
||||||
.chain
|
.chain
|
||||||
.is_data_availability_check_required()
|
.is_data_availability_check_required()
|
||||||
.map_err(|_| "Unable to read slot clock")?
|
.map_err(|_| "Unable to read slot clock")?
|
||||||
&& matches!(force_block_request, ForceBlockRequest::False)
|
|
||||||
{
|
{
|
||||||
trace!(
|
trace!(
|
||||||
self.log,
|
self.log,
|
||||||
|
|||||||
Reference in New Issue
Block a user