mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: Consensus trait error type (#13655)
This commit is contained in:
@ -5,7 +5,7 @@ use alloy_primitives::BlockNumber;
|
||||
use futures::Stream;
|
||||
use futures_util::StreamExt;
|
||||
use reth_config::BodiesConfig;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_consensus::{Consensus, ConsensusError};
|
||||
use reth_network_p2p::{
|
||||
bodies::{
|
||||
client::BodiesClient,
|
||||
@ -39,7 +39,7 @@ pub struct BodiesDownloader<B: BodiesClient, Provider: HeaderProvider> {
|
||||
/// The bodies client
|
||||
client: Arc<B>,
|
||||
/// The consensus client
|
||||
consensus: Arc<dyn Consensus<Provider::Header, B::Body>>,
|
||||
consensus: Arc<dyn Consensus<Provider::Header, B::Body, Error = ConsensusError>>,
|
||||
/// The database handle
|
||||
provider: Provider,
|
||||
/// The maximum number of non-empty blocks per one request
|
||||
@ -579,7 +579,7 @@ impl BodiesDownloaderBuilder {
|
||||
pub fn build<B, Provider>(
|
||||
self,
|
||||
client: B,
|
||||
consensus: Arc<dyn Consensus<Provider::Header, B::Body>>,
|
||||
consensus: Arc<dyn Consensus<Provider::Header, B::Body, Error = ConsensusError>>,
|
||||
provider: Provider,
|
||||
) -> BodiesDownloader<B, Provider>
|
||||
where
|
||||
|
||||
@ -4,7 +4,7 @@ use alloy_consensus::BlockHeader;
|
||||
use alloy_primitives::BlockNumber;
|
||||
use futures::{stream::FuturesUnordered, Stream};
|
||||
use futures_util::StreamExt;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_consensus::{Consensus, ConsensusError};
|
||||
use reth_network_p2p::{
|
||||
bodies::{client::BodiesClient, response::BlockResponse},
|
||||
error::DownloadResult,
|
||||
@ -59,7 +59,7 @@ where
|
||||
pub(crate) fn push_new_request(
|
||||
&mut self,
|
||||
client: Arc<B>,
|
||||
consensus: Arc<dyn Consensus<H, B::Body>>,
|
||||
consensus: Arc<dyn Consensus<H, B::Body, Error = ConsensusError>>,
|
||||
request: Vec<SealedHeader<H>>,
|
||||
) {
|
||||
// Set last max requested block number
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::metrics::{BodyDownloaderMetrics, ResponseMetrics};
|
||||
use alloy_consensus::BlockHeader;
|
||||
use alloy_primitives::B256;
|
||||
use futures::{Future, FutureExt};
|
||||
use reth_consensus::Consensus;
|
||||
use reth_consensus::{Consensus, ConsensusError};
|
||||
use reth_network_p2p::{
|
||||
bodies::{client::BodiesClient, response::BlockResponse},
|
||||
error::{DownloadError, DownloadResult},
|
||||
@ -40,7 +40,7 @@ use std::{
|
||||
/// and eventually disconnected.
|
||||
pub(crate) struct BodiesRequestFuture<H, B: BodiesClient> {
|
||||
client: Arc<B>,
|
||||
consensus: Arc<dyn Consensus<H, B::Body>>,
|
||||
consensus: Arc<dyn Consensus<H, B::Body, Error = ConsensusError>>,
|
||||
metrics: BodyDownloaderMetrics,
|
||||
/// Metrics for individual responses. This can be used to observe how the size (in bytes) of
|
||||
/// responses change while bodies are being downloaded.
|
||||
@ -62,7 +62,7 @@ where
|
||||
/// Returns an empty future. Use [`BodiesRequestFuture::with_headers`] to set the request.
|
||||
pub(crate) fn new(
|
||||
client: Arc<B>,
|
||||
consensus: Arc<dyn Consensus<H, B::Body>>,
|
||||
consensus: Arc<dyn Consensus<H, B::Body, Error = ConsensusError>>,
|
||||
metrics: BodyDownloaderMetrics,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
||||
@ -43,7 +43,7 @@ impl<H: Send + Sync + Unpin + 'static, B: Send + Sync + Unpin + 'static> TaskDow
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use reth_consensus::Consensus;
|
||||
/// use reth_consensus::{Consensus, ConsensusError};
|
||||
/// use reth_downloaders::bodies::{bodies::BodiesDownloaderBuilder, task::TaskDownloader};
|
||||
/// use reth_network_p2p::bodies::client::BodiesClient;
|
||||
/// use reth_primitives_traits::InMemorySize;
|
||||
@ -55,7 +55,7 @@ impl<H: Send + Sync + Unpin + 'static, B: Send + Sync + Unpin + 'static> TaskDow
|
||||
/// Provider: HeaderProvider<Header = alloy_consensus::Header> + Unpin + 'static,
|
||||
/// >(
|
||||
/// client: Arc<B>,
|
||||
/// consensus: Arc<dyn Consensus<Provider::Header, B::Body>>,
|
||||
/// consensus: Arc<dyn Consensus<Provider::Header, B::Body, Error = ConsensusError>>,
|
||||
/// provider: Provider,
|
||||
/// ) {
|
||||
/// let downloader = BodiesDownloaderBuilder::default().build(client, consensus, provider);
|
||||
|
||||
@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
use alloy_consensus::BlockHeader;
|
||||
use alloy_primitives::{Sealable, B256};
|
||||
use reth_consensus::Consensus;
|
||||
use reth_consensus::{Consensus, ConsensusError};
|
||||
use reth_eth_wire_types::HeadersDirection;
|
||||
use reth_network_peers::WithPeerId;
|
||||
use reth_primitives::{SealedBlock, SealedHeader};
|
||||
@ -30,7 +30,7 @@ where
|
||||
Client: BlockClient,
|
||||
{
|
||||
client: Client,
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body>>,
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body, Error = ConsensusError>>,
|
||||
}
|
||||
|
||||
impl<Client> FullBlockClient<Client>
|
||||
@ -40,7 +40,7 @@ where
|
||||
/// Creates a new instance of `FullBlockClient`.
|
||||
pub fn new(
|
||||
client: Client,
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body>>,
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body, Error = ConsensusError>>,
|
||||
) -> Self {
|
||||
Self { client, consensus }
|
||||
}
|
||||
@ -118,7 +118,7 @@ where
|
||||
Client: BlockClient,
|
||||
{
|
||||
client: Client,
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body>>,
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body, Error = ConsensusError>>,
|
||||
hash: B256,
|
||||
request: FullBlockRequest<Client>,
|
||||
header: Option<SealedHeader<Client::Header>>,
|
||||
@ -330,7 +330,7 @@ where
|
||||
/// The client used to fetch headers and bodies.
|
||||
client: Client,
|
||||
/// The consensus instance used to validate the blocks.
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body>>,
|
||||
consensus: Arc<dyn Consensus<Client::Header, Client::Body, Error = ConsensusError>>,
|
||||
/// The block hash to start fetching from (inclusive).
|
||||
start_hash: B256,
|
||||
/// How many blocks to fetch: `len([start_hash, ..]) == count`
|
||||
|
||||
@ -12,7 +12,7 @@ use crate::{
|
||||
};
|
||||
use alloy_consensus::Header;
|
||||
use futures::{Future, FutureExt, Stream, StreamExt};
|
||||
use reth_consensus::{test_utils::TestConsensus, Consensus};
|
||||
use reth_consensus::{test_utils::TestConsensus, Consensus, ConsensusError};
|
||||
use reth_eth_wire_types::HeadersDirection;
|
||||
use reth_network_peers::{PeerId, WithPeerId};
|
||||
use reth_primitives::SealedHeader;
|
||||
@ -147,7 +147,11 @@ impl Stream for TestDownload {
|
||||
|
||||
let empty: SealedHeader = SealedHeader::default();
|
||||
if let Err(error) =
|
||||
<dyn Consensus<_>>::validate_header_against_parent(&this.consensus, &empty, &empty)
|
||||
<dyn Consensus<_, Error = ConsensusError>>::validate_header_against_parent(
|
||||
&this.consensus,
|
||||
&empty,
|
||||
&empty,
|
||||
)
|
||||
{
|
||||
this.done = true;
|
||||
return Poll::Ready(Some(Err(DownloadError::HeaderValidation {
|
||||
|
||||
Reference in New Issue
Block a user