feat(sync): download peer penalization (#427)

* feat(sync): download peer penalization

* peer penalization

* add tracing on penalization

* add trace on request

* rename consensus back

* clippy

* fix tests

* nit: download result

* nit: fix comment

* rename penalize() to report_bad_message() and move DownloadError

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Roman Krasiuk
2022-12-15 10:42:18 +02:00
committed by GitHub
parent f2707d32b5
commit 22dc50e5f6
19 changed files with 406 additions and 282 deletions

View File

@@ -1,4 +1,6 @@
use crate::p2p::{bodies::client::BodiesClient, error::PeerRequestResult};
use crate::p2p::{
bodies::client::BodiesClient, downloader::DownloadClient, error::PeerRequestResult,
};
use async_trait::async_trait;
use reth_eth_wire::BlockBody;
use reth_primitives::H256;
@@ -16,6 +18,12 @@ impl<F> Debug for TestBodiesClient<F> {
}
}
impl<F: Sync + Send> DownloadClient for TestBodiesClient<F> {
fn report_bad_message(&self, _peer_id: reth_primitives::PeerId) {
// noop
}
}
#[async_trait]
impl<F> BodiesClient for TestBodiesClient<F>
where

View File

@@ -2,12 +2,11 @@
use crate::{
consensus::{self, Consensus},
p2p::{
downloader::{DownloadStream, Downloader},
error::{PeerRequestResult, RequestError},
downloader::{DownloadClient, DownloadStream, Downloader},
error::{DownloadError, DownloadResult, PeerRequestResult, RequestError},
headers::{
client::{HeadersClient, HeadersRequest, StatusUpdater},
downloader::HeaderDownloader,
error::DownloadError,
},
},
};
@@ -72,7 +71,7 @@ impl HeaderDownloader for TestHeaderDownloader {
&self,
_head: SealedHeader,
_forkchoice: ForkchoiceState,
) -> DownloadStream<SealedHeader> {
) -> DownloadStream<'_, SealedHeader> {
Box::pin(self.create_download())
}
}
@@ -104,7 +103,7 @@ impl TestDownload {
}
impl Stream for TestDownload {
type Item = Result<SealedHeader, DownloadError>;
type Item = DownloadResult<SealedHeader>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
@@ -168,6 +167,12 @@ impl TestHeadersClient {
}
}
impl DownloadClient for TestHeadersClient {
fn report_bad_message(&self, _peer_id: PeerId) {
// noop
}
}
#[async_trait::async_trait]
impl HeadersClient for TestHeadersClient {
async fn get_headers(&self, request: HeadersRequest) -> PeerRequestResult<BlockHeaders> {