mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
should remove lookup refactor
This commit is contained in:
@@ -91,6 +91,12 @@ pub enum PeerShouldHave {
|
|||||||
Neither,
|
Neither,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub enum ShouldRemoveLookup {
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: BeaconChainTypes> BlockLookups<T> {
|
impl<T: BeaconChainTypes> BlockLookups<T> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
da_checker: Arc<DataAvailabilityChecker<T::EthSpec, T::SlotClock>>,
|
da_checker: Arc<DataAvailabilityChecker<T::EthSpec, T::SlotClock>>,
|
||||||
@@ -302,35 +308,39 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
request_id_ref,
|
request_id_ref,
|
||||||
request_ref,
|
request_ref,
|
||||||
e,
|
e,
|
||||||
|
ResponseType::Block,
|
||||||
&log,
|
&log,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
false
|
ShouldRemoveLookup::False
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This is the correct block, send it for processing
|
// This is the correct block, send it for processing
|
||||||
self.send_block_for_processing(
|
match self.send_block_for_processing(
|
||||||
root,
|
root,
|
||||||
BlockWrapper::Block(block),
|
BlockWrapper::Block(block),
|
||||||
seen_timestamp,
|
seen_timestamp,
|
||||||
BlockProcessType::SingleBlock { id },
|
BlockProcessType::SingleBlock { id },
|
||||||
cx,
|
cx,
|
||||||
)
|
) {
|
||||||
.is_err()
|
Ok(()) => ShouldRemoveLookup::False,
|
||||||
|
Err(()) => ShouldRemoveLookup::True,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None) => false,
|
Ok(None) => ShouldRemoveLookup::False,
|
||||||
Err(e) => Self::handle_block_lookup_verify_error(
|
Err(e) => Self::handle_block_lookup_verify_error(
|
||||||
peer_id,
|
peer_id,
|
||||||
cx,
|
cx,
|
||||||
request_id_ref,
|
request_id_ref,
|
||||||
request_ref,
|
request_ref,
|
||||||
e,
|
e,
|
||||||
|
ResponseType::Block,
|
||||||
&log,
|
&log,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
if should_remove {
|
if matches!(should_remove, ShouldRemoveLookup::True) {
|
||||||
self.single_block_lookups
|
self.single_block_lookups
|
||||||
.retain(|(block_id, _, _)| block_id != &Some(id));
|
.retain(|(block_id, _, _)| block_id != &Some(id));
|
||||||
}
|
}
|
||||||
@@ -364,41 +374,45 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
// The lookup status here is irrelevant because we wait until the parent chain
|
// The lookup status here is irrelevant because we wait until the parent chain
|
||||||
// is complete before processing the block.
|
// is complete before processing the block.
|
||||||
if let Err(e) = request_ref.add_blobs(block_root, blobs) {
|
if let Err(e) = request_ref.add_blobs(block_root, blobs) {
|
||||||
Self::handle_blob_lookup_verify_error(
|
Self::handle_block_lookup_verify_error(
|
||||||
peer_id,
|
peer_id,
|
||||||
cx,
|
cx,
|
||||||
request_id_ref,
|
request_id_ref,
|
||||||
request_ref,
|
request_ref,
|
||||||
e,
|
e,
|
||||||
|
ResponseType::Blob,
|
||||||
&log,
|
&log,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
false
|
ShouldRemoveLookup::False
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// These are the correct blobs, send them for processing
|
// These are the correct blobs, send them for processing
|
||||||
self.send_blobs_for_processing(
|
match self.send_blobs_for_processing(
|
||||||
block_root,
|
block_root,
|
||||||
blobs,
|
blobs,
|
||||||
seen_timestamp,
|
seen_timestamp,
|
||||||
BlockProcessType::SingleBlock { id },
|
BlockProcessType::SingleBlock { id },
|
||||||
cx,
|
cx,
|
||||||
)
|
) {
|
||||||
.is_err()
|
Ok(()) => ShouldRemoveLookup::False,
|
||||||
|
Err(()) => ShouldRemoveLookup::True,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None) => false,
|
Ok(None) => ShouldRemoveLookup::False,
|
||||||
Err(e) => Self::handle_blob_lookup_verify_error(
|
Err(e) => Self::handle_block_lookup_verify_error(
|
||||||
peer_id,
|
peer_id,
|
||||||
cx,
|
cx,
|
||||||
request_id_ref,
|
request_id_ref,
|
||||||
request_ref,
|
request_ref,
|
||||||
e,
|
e,
|
||||||
|
ResponseType::Blob,
|
||||||
&log,
|
&log,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
if should_remove {
|
if matches!(should_remove, ShouldRemoveLookup::True) {
|
||||||
self.single_block_lookups
|
self.single_block_lookups
|
||||||
.retain(|(_, blob_id, _)| blob_id != &Some(id));
|
.retain(|(_, blob_id, _)| blob_id != &Some(id));
|
||||||
}
|
}
|
||||||
@@ -409,73 +423,61 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(sean) reduce duplicate code
|
|
||||||
fn handle_block_lookup_verify_error(
|
fn handle_block_lookup_verify_error(
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
cx: &mut SyncNetworkContext<T>,
|
cx: &mut SyncNetworkContext<T>,
|
||||||
request_id_ref: &mut Id,
|
request_id_ref: &mut Id,
|
||||||
request_ref: &mut SingleBlockLookup<3, T>,
|
request_ref: &mut SingleBlockLookup<3, T>,
|
||||||
error: LookupVerifyError,
|
error: LookupVerifyError,
|
||||||
|
response_type: ResponseType,
|
||||||
log: &Logger,
|
log: &Logger,
|
||||||
) -> bool {
|
) -> ShouldRemoveLookup {
|
||||||
let requested_block_root = request_ref.requested_block_root;
|
let requested_block_root = request_ref.requested_block_root;
|
||||||
|
|
||||||
let msg: &str = error.into();
|
let msg: &str = error.into();
|
||||||
cx.report_peer(peer_id, PeerAction::LowToleranceError, msg);
|
cx.report_peer(peer_id, PeerAction::LowToleranceError, msg);
|
||||||
|
|
||||||
debug!(log, "Single block lookup failed";
|
debug!(log, "Single block lookup failed";
|
||||||
"peer_id" => %peer_id, "error" => msg, "block_root" => ?requested_block_root);
|
"peer_id" => %peer_id,
|
||||||
|
"error" => msg,
|
||||||
|
"block_root" => ?requested_block_root,
|
||||||
|
"response_type" => ?response_type
|
||||||
|
);
|
||||||
// try the request again if possible
|
// try the request again if possible
|
||||||
match request_ref.request_block() {
|
let id_opt = match response_type {
|
||||||
Ok(Some((peer_id, request))) => {
|
ResponseType::Block => request_ref.request_block().map(|request_opt| {
|
||||||
if let Ok(id) = cx.single_block_lookup_request(peer_id, request) {
|
request_opt
|
||||||
*request_id_ref = id;
|
.map(|(peer_id, request)| cx.single_block_lookup_request(peer_id, request))
|
||||||
} else {
|
}),
|
||||||
return true;
|
ResponseType::Blob => request_ref.request_blobs().map(|request_opt| {
|
||||||
}
|
request_opt
|
||||||
|
.map(|(peer_id, request)| cx.single_blobs_lookup_request(peer_id, request))
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
match id_opt {
|
||||||
|
Ok(Some(Ok(id))) => {
|
||||||
|
*request_id_ref = id;
|
||||||
|
}
|
||||||
|
Ok(Some(Err(e))) => {
|
||||||
|
debug!(log, "Single block lookup failed";
|
||||||
|
"peer_id" => %peer_id,
|
||||||
|
"error" => ?e,
|
||||||
|
"block_root" => ?requested_block_root,
|
||||||
|
"response_type" => ?response_type);
|
||||||
|
return ShouldRemoveLookup::True;
|
||||||
}
|
}
|
||||||
Ok(None) => {}
|
Ok(None) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(log, "Single block lookup failed";
|
debug!(log, "Single block lookup failed";
|
||||||
"peer_id" => %peer_id, "error" => ?e, "block_root" => %requested_block_root);
|
"peer_id" => %peer_id,
|
||||||
return true;
|
"error" => ?e,
|
||||||
|
"block_root" => ?requested_block_root,
|
||||||
|
"response_type" => ?response_type);
|
||||||
|
return ShouldRemoveLookup::True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
ShouldRemoveLookup::False
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_blob_lookup_verify_error(
|
|
||||||
peer_id: PeerId,
|
|
||||||
cx: &mut SyncNetworkContext<T>,
|
|
||||||
request_id_ref: &mut Id,
|
|
||||||
request_ref: &mut SingleBlockLookup<3, T>,
|
|
||||||
error: LookupVerifyError,
|
|
||||||
log: &Logger,
|
|
||||||
) -> bool {
|
|
||||||
let requested_block_root = request_ref.requested_block_root;
|
|
||||||
|
|
||||||
let msg: &str = error.into();
|
|
||||||
cx.report_peer(peer_id, PeerAction::LowToleranceError, msg);
|
|
||||||
|
|
||||||
debug!(log, "Single block lookup failed";
|
|
||||||
"peer_id" => %peer_id, "error" => msg, "block_root" => ?requested_block_root);
|
|
||||||
// try the request again if possible
|
|
||||||
match request_ref.request_blobs() {
|
|
||||||
Ok(Some((peer_id, request))) => {
|
|
||||||
if let Ok(id) = cx.single_blobs_lookup_request(peer_id, request) {
|
|
||||||
*request_id_ref = id;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None) => {}
|
|
||||||
Err(e) => {
|
|
||||||
debug!(log, "Single block lookup failed";
|
|
||||||
"peer_id" => %peer_id, "error" => ?e, "block_root" => %requested_block_root);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_single_lookup_request(
|
fn find_single_lookup_request(
|
||||||
|
|||||||
Reference in New Issue
Block a user