mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 09:16:00 +00:00
refactor single block processed method
This commit is contained in:
@@ -796,24 +796,15 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
response_type: ResponseType,
|
response_type: ResponseType,
|
||||||
cx: &mut SyncNetworkContext<T>,
|
cx: &mut SyncNetworkContext<T>,
|
||||||
) {
|
) {
|
||||||
let (index, req_id, req) = match self.single_block_lookups.iter_mut().enumerate().find_map(
|
let lookup_components_opt = self.single_block_lookups.iter_mut().enumerate().find_map(
|
||||||
|(index, (block_id, blob_id, req))| match response_type {
|
|(index, (block_id_opt, blob_id_opt, req))| {
|
||||||
ResponseType::Block => {
|
block_id_opt
|
||||||
if block_id == &Some(id) {
|
.as_mut()
|
||||||
Some((index, block_id, req))
|
.or(blob_id_opt.as_mut())
|
||||||
} else {
|
.and_then(|id_ref| (*id_ref != id).then(|| (index, id_ref, req)))
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResponseType::Blob => {
|
|
||||||
if blob_id == &Some(id) {
|
|
||||||
Some((index, blob_id, req))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
) {
|
);
|
||||||
|
let (index, request_id_ref, request_ref) = match lookup_components_opt {
|
||||||
Some(req) => req,
|
Some(req) => req,
|
||||||
None => {
|
None => {
|
||||||
return debug!(
|
return debug!(
|
||||||
@@ -823,28 +814,28 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let root = req.requested_block_root;
|
let root = request_ref.requested_block_root;
|
||||||
let peer_id = match response_type {
|
let peer_id = match response_type {
|
||||||
ResponseType::Block => match req.block_request_state.processing_peer() {
|
ResponseType::Block => match request_ref.block_request_state.processing_peer() {
|
||||||
Ok(peer) => peer,
|
Ok(peer) => peer,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
},
|
},
|
||||||
ResponseType::Blob => match req.blob_request_state.processing_peer() {
|
ResponseType::Blob => match request_ref.blob_request_state.processing_peer() {
|
||||||
Ok(peer) => peer,
|
Ok(peer) => peer,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let remove = match result {
|
let should_remove_lookup = match result {
|
||||||
BlockPartProcessingResult::Ok(status) => match status {
|
BlockPartProcessingResult::Ok(status) => match status {
|
||||||
AvailabilityProcessingStatus::Imported(hash) => {
|
AvailabilityProcessingStatus::Imported(hash) => {
|
||||||
trace!(self.log, "Single block processing succeeded"; "block" => %root);
|
trace!(self.log, "Single block processing succeeded"; "block" => %root);
|
||||||
true
|
ShouldRemoveLookup::True
|
||||||
}
|
}
|
||||||
AvailabilityProcessingStatus::MissingComponents(_, block_root) => {
|
AvailabilityProcessingStatus::MissingComponents(_, block_root) => {
|
||||||
// At this point we don't know what the peer *should* have.
|
// At this point we don't know what the peer *should* have.
|
||||||
self.search_block(block_root, peer_id, PeerShouldHave::Neither, cx);
|
self.search_block(block_root, peer_id, PeerShouldHave::Neither, cx);
|
||||||
false
|
ShouldRemoveLookup::False
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
BlockPartProcessingResult::Ignored => {
|
BlockPartProcessingResult::Ignored => {
|
||||||
@@ -855,24 +846,23 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
"Single block processing was ignored, cpu might be overloaded";
|
"Single block processing was ignored, cpu might be overloaded";
|
||||||
"action" => "dropping single block request"
|
"action" => "dropping single block request"
|
||||||
);
|
);
|
||||||
true
|
ShouldRemoveLookup::True
|
||||||
}
|
}
|
||||||
BlockPartProcessingResult::Err(e) => {
|
BlockPartProcessingResult::Err(e) => {
|
||||||
trace!(self.log, "Single block processing failed"; "block" => %root, "error" => %e);
|
trace!(self.log, "Single block processing failed"; "block" => %root, "error" => %e);
|
||||||
match e {
|
match e {
|
||||||
BlockError::BlockIsAlreadyKnown => {
|
BlockError::BlockIsAlreadyKnown => {
|
||||||
// No error here
|
// No error here
|
||||||
true
|
ShouldRemoveLookup::True
|
||||||
}
|
}
|
||||||
BlockError::BeaconChainError(e) => {
|
BlockError::BeaconChainError(e) => {
|
||||||
// Internal error
|
// Internal error
|
||||||
error!(self.log, "Beacon chain error processing single block"; "block_root" => %root, "error" => ?e);
|
error!(self.log, "Beacon chain error processing single block"; "block_root" => %root, "error" => ?e);
|
||||||
true
|
ShouldRemoveLookup::True
|
||||||
}
|
}
|
||||||
BlockError::ParentUnknown(block) => {
|
BlockError::ParentUnknown(block) => {
|
||||||
self.search_parent(block.slot(), root, block.parent_root(), peer_id, cx);
|
self.search_parent(block.slot(), root, block.parent_root(), peer_id, cx);
|
||||||
//TODO(sean) - handle request for parts of this block
|
ShouldRemoveLookup::False
|
||||||
false
|
|
||||||
}
|
}
|
||||||
ref e @ BlockError::ExecutionPayloadError(ref epe) if !epe.penalize_peer() => {
|
ref e @ BlockError::ExecutionPayloadError(ref epe) if !epe.penalize_peer() => {
|
||||||
// These errors indicate that the execution layer is offline
|
// These errors indicate that the execution layer is offline
|
||||||
@@ -883,8 +873,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
"root" => %root,
|
"root" => %root,
|
||||||
"error" => ?e
|
"error" => ?e
|
||||||
);
|
);
|
||||||
//TODO(sean) is this right?
|
ShouldRemoveLookup::True
|
||||||
true
|
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
warn!(self.log, "Peer sent invalid block in single block lookup"; "root" => %root, "error" => ?other, "peer_id" => %peer_id);
|
warn!(self.log, "Peer sent invalid block in single block lookup"; "root" => %root, "error" => ?other, "peer_id" => %peer_id);
|
||||||
@@ -894,48 +883,20 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
"single_block_failure",
|
"single_block_failure",
|
||||||
);
|
);
|
||||||
// Try it again if possible.
|
// Try it again if possible.
|
||||||
match response_type {
|
retry_request_after_failure(
|
||||||
ResponseType::Block => {
|
request_id_ref,
|
||||||
req.block_request_state.register_failure_processing();
|
request_ref,
|
||||||
match req.request_block() {
|
response_type,
|
||||||
Ok(Some((peer_id, request))) => {
|
&peer_id,
|
||||||
if let Ok(request_id) =
|
cx,
|
||||||
cx.single_block_lookup_request(peer_id, request)
|
&self.log,
|
||||||
{
|
)
|
||||||
*req_id = Some(request_id);
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None) => false,
|
|
||||||
Err(_) => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResponseType::Blob => {
|
|
||||||
req.blob_request_state.register_failure_processing();
|
|
||||||
match req.request_blobs() {
|
|
||||||
Ok(Some((peer_id, request))) => {
|
|
||||||
if let Ok(request_id) =
|
|
||||||
cx.single_blobs_lookup_request(peer_id, request)
|
|
||||||
{
|
|
||||||
*req_id = Some(request_id);
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None) => false,
|
|
||||||
Err(_) => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if remove {
|
if matches!(should_remove_lookup, ShouldRemoveLookup::True) {
|
||||||
self.single_block_lookups.remove(index);
|
self.single_block_lookups.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user