improve peer scoring during certain failures in parent lookups

This commit is contained in:
realbigsean
2023-04-24 16:58:13 -04:00
parent 274aba95c7
commit 0560b7d1a5
2 changed files with 30 additions and 17 deletions

View File

@@ -1292,7 +1292,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
cx: &mut SyncNetworkContext<T>, cx: &mut SyncNetworkContext<T>,
) { ) {
let response = parent_lookup.request_parent_block(cx); let response = parent_lookup.request_parent_block(cx);
self.handle_response(parent_lookup, cx, response); self.handle_response(parent_lookup, cx, response, ResponseType::Block);
} }
fn request_parent_blob( fn request_parent_blob(
@@ -1301,7 +1301,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
cx: &mut SyncNetworkContext<T>, cx: &mut SyncNetworkContext<T>,
) { ) {
let response = parent_lookup.request_parent_blobs(cx); let response = parent_lookup.request_parent_blobs(cx);
self.handle_response(parent_lookup, cx, response); self.handle_response(parent_lookup, cx, response, ResponseType::Blob);
} }
fn request_parent_block_and_blobs( fn request_parent_block_and_blobs(
@@ -1309,18 +1309,24 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
mut parent_lookup: ParentLookup<T>, mut parent_lookup: ParentLookup<T>,
cx: &mut SyncNetworkContext<T>, cx: &mut SyncNetworkContext<T>,
) { ) {
let response = parent_lookup let block_res = parent_lookup.request_parent_block(cx);
.request_parent_block(cx) match block_res {
.and_then(|_| parent_lookup.request_parent_blobs(cx)); Ok(()) => {
self.handle_response(parent_lookup, cx, response); let blob_res = parent_lookup.request_parent_blobs(cx);
self.handle_response(parent_lookup, cx, blob_res, ResponseType::Blob)
}
Err(e) => {
self.handle_response(parent_lookup, cx, Err(e), ResponseType::Block);
}
}
} }
//TODO(sean) how should peer scoring work with failures in this method?
fn handle_response( fn handle_response(
&mut self, &mut self,
mut parent_lookup: ParentLookup<T>, parent_lookup: ParentLookup<T>,
cx: &mut SyncNetworkContext<T>, cx: &mut SyncNetworkContext<T>,
result: Result<(), parent_lookup::RequestError>, result: Result<(), parent_lookup::RequestError>,
response_type: ResponseType,
) { ) {
match result { match result {
Err(e) => { Err(e) => {
@@ -1332,7 +1338,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
parent_lookup::RequestError::ChainTooLong => { parent_lookup::RequestError::ChainTooLong => {
self.failed_chains.insert(parent_lookup.chain_hash()); self.failed_chains.insert(parent_lookup.chain_hash());
// This indicates faulty peers. // This indicates faulty peers.
for &peer_id in parent_lookup.used_block_peers() { for &peer_id in parent_lookup.used_peers(response_type) {
cx.report_peer(peer_id, PeerAction::LowToleranceError, e.as_static()) cx.report_peer(peer_id, PeerAction::LowToleranceError, e.as_static())
} }
} }
@@ -1345,7 +1351,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
self.failed_chains.insert(parent_lookup.chain_hash()); self.failed_chains.insert(parent_lookup.chain_hash());
} }
// This indicates faulty peers. // This indicates faulty peers.
for &peer_id in parent_lookup.used_block_peers() { for &peer_id in parent_lookup.used_peers(response_type) {
cx.report_peer(peer_id, PeerAction::LowToleranceError, e.as_static()) cx.report_peer(peer_id, PeerAction::LowToleranceError, e.as_static())
} }
} }

View File

@@ -1,5 +1,5 @@
use super::single_block_lookup::{LookupRequestError, LookupVerifyError, SingleBlockLookup}; use super::single_block_lookup::{LookupRequestError, LookupVerifyError, SingleBlockLookup};
use super::{DownloadedBlocks, PeerShouldHave}; use super::{DownloadedBlocks, PeerShouldHave, ResponseType};
use crate::sync::block_lookups::{single_block_lookup, RootBlockTuple}; use crate::sync::block_lookups::{single_block_lookup, RootBlockTuple};
use crate::sync::{ use crate::sync::{
manager::{Id, SLOT_IMPORT_TOLERANCE}, manager::{Id, SLOT_IMPORT_TOLERANCE},
@@ -358,12 +358,19 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
.add_peer_if_useful(block_root, peer_id, peer_usefulness) .add_peer_if_useful(block_root, peer_id, peer_usefulness)
} }
//TODO(sean) fix this up pub fn used_peers(&self, response_type: ResponseType) -> impl Iterator<Item = &PeerId> + '_ {
pub fn used_block_peers(&self) -> impl Iterator<Item = &PeerId> + '_ { match response_type {
self.current_parent_request ResponseType::Block => self
.current_parent_request
.block_request_state .block_request_state
.used_peers .used_peers
.iter() .iter(),
ResponseType::Blob => self
.current_parent_request
.blob_request_state
.used_peers
.iter(),
}
} }
} }