Files
nanoreth/crates/interfaces/src/p2p/headers/client.rs
Roman Krasiuk 22dc50e5f6 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>
2022-12-15 10:42:18 +02:00

33 lines
1.2 KiB
Rust

use crate::p2p::{downloader::DownloadClient, error::PeerRequestResult};
use async_trait::async_trait;
pub use reth_eth_wire::BlockHeaders;
use reth_primitives::{BlockHashOrNumber, HeadersDirection, H256, U256};
use std::fmt::Debug;
/// The header request struct to be sent to connected peers, which
/// will proceed to ask them to stream the requested headers to us.
#[derive(Clone, Debug)]
pub struct HeadersRequest {
/// The starting block
pub start: BlockHashOrNumber,
/// The response max size
pub limit: u64,
/// The direction in which headers should be returned.
pub direction: HeadersDirection,
}
/// The block headers downloader client
#[async_trait]
#[auto_impl::auto_impl(&, Arc, Box)]
pub trait HeadersClient: DownloadClient {
/// Sends the header request to the p2p network and returns the header response received from a
/// peer.
async fn get_headers(&self, request: HeadersRequest) -> PeerRequestResult<BlockHeaders>;
}
/// The status updater for updating the status of the p2p node
pub trait StatusUpdater: Send + Sync {
/// Updates the status of the p2p node
fn update_status(&self, height: u64, hash: H256, total_difficulty: U256);
}