mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix(network, p2p): Wasm compilation (#10278)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -7586,6 +7586,7 @@ name = "reth-network-p2p"
|
||||
version = "1.0.5"
|
||||
dependencies = [
|
||||
"auto_impl",
|
||||
"derive_more",
|
||||
"futures",
|
||||
"parking_lot 0.12.3",
|
||||
"reth-consensus",
|
||||
@ -7594,7 +7595,6 @@ dependencies = [
|
||||
"reth-primitives",
|
||||
"reth-storage-errors",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
@ -27,8 +27,8 @@ tokio = { workspace = true, features = ["sync"] }
|
||||
|
||||
# misc
|
||||
auto_impl.workspace = true
|
||||
thiserror.workspace = true
|
||||
tracing.workspace = true
|
||||
derive_more.workspace = true
|
||||
|
||||
parking_lot = { workspace = true, optional = true }
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use derive_more::Display;
|
||||
use reth_consensus::ConsensusError;
|
||||
use reth_network_peers::WithPeerId;
|
||||
use reth_primitives::{
|
||||
BlockHashOrNumber, BlockNumber, GotExpected, GotExpectedBoxed, Header, B256,
|
||||
};
|
||||
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
|
||||
use thiserror::Error;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
|
||||
use super::headers::client::HeadersRequest;
|
||||
@ -78,26 +78,26 @@ impl EthResponseValidator for RequestResult<Vec<Header>> {
|
||||
/// Error variants that can happen when sending requests to a session.
|
||||
///
|
||||
/// Represents errors encountered when sending requests.
|
||||
#[derive(Clone, Debug, Error, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Display)]
|
||||
pub enum RequestError {
|
||||
/// Closed channel to the peer.
|
||||
#[error("closed channel to the peer")]
|
||||
#[display(fmt = "closed channel to the peer")]
|
||||
/// Indicates the channel to the peer is closed.
|
||||
ChannelClosed,
|
||||
/// Connection to a peer dropped while handling the request.
|
||||
#[error("connection to a peer dropped while handling the request")]
|
||||
#[display(fmt = "connection to a peer dropped while handling the request")]
|
||||
/// Represents a dropped connection while handling the request.
|
||||
ConnectionDropped,
|
||||
/// Capability message is not supported by the remote peer.
|
||||
#[error("capability message is not supported by remote peer")]
|
||||
#[display(fmt = "capability message is not supported by remote peer")]
|
||||
/// Indicates an unsupported capability message from the remote peer.
|
||||
UnsupportedCapability,
|
||||
/// Request timed out while awaiting response.
|
||||
#[error("request timed out while awaiting response")]
|
||||
#[display(fmt = "request timed out while awaiting response")]
|
||||
/// Represents a timeout while waiting for a response.
|
||||
Timeout,
|
||||
/// Received bad response.
|
||||
#[error("received bad response")]
|
||||
#[display(fmt = "received bad response")]
|
||||
/// Indicates a bad response was received.
|
||||
BadResponse,
|
||||
}
|
||||
@ -128,77 +128,76 @@ impl From<oneshot::error::RecvError> for RequestError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for RequestError {}
|
||||
|
||||
/// The download result type
|
||||
pub type DownloadResult<T> = Result<T, DownloadError>;
|
||||
|
||||
/// The downloader error type
|
||||
#[derive(Error, Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Display)]
|
||||
pub enum DownloadError {
|
||||
/* ==================== HEADER ERRORS ==================== */
|
||||
/// Header validation failed.
|
||||
#[error("failed to validate header {hash}, block number {number}: {error}")]
|
||||
#[display(fmt = "failed to validate header {hash}, block number {number}: {error}")]
|
||||
HeaderValidation {
|
||||
/// Hash of header failing validation
|
||||
hash: B256,
|
||||
/// Number of header failing validation
|
||||
number: u64,
|
||||
/// The details of validation failure
|
||||
#[source]
|
||||
error: Box<ConsensusError>,
|
||||
},
|
||||
/// Received an invalid tip.
|
||||
#[error("received invalid tip: {0}")]
|
||||
#[display(fmt = "received invalid tip: {_0}")]
|
||||
InvalidTip(GotExpectedBoxed<B256>),
|
||||
/// Received a tip with an invalid tip number.
|
||||
#[error("received invalid tip number: {0}")]
|
||||
#[display(fmt = "received invalid tip number: {_0}")]
|
||||
InvalidTipNumber(GotExpected<u64>),
|
||||
/// Received a response to a request with unexpected start block
|
||||
#[error("headers response starts at unexpected block: {0}")]
|
||||
#[display(fmt = "headers response starts at unexpected block: {_0}")]
|
||||
HeadersResponseStartBlockMismatch(GotExpected<u64>),
|
||||
/// Received headers with less than expected items.
|
||||
#[error("received less headers than expected: {0}")]
|
||||
#[display(fmt = "received less headers than expected: {_0}")]
|
||||
HeadersResponseTooShort(GotExpected<u64>),
|
||||
|
||||
/* ==================== BODIES ERRORS ==================== */
|
||||
/// Block validation failed
|
||||
#[error("failed to validate body for header {hash}, block number {number}: {error}")]
|
||||
#[display(fmt = "failed to validate body for header {hash}, block number {number}: {error}")]
|
||||
BodyValidation {
|
||||
/// Hash of the block failing validation
|
||||
hash: B256,
|
||||
/// Number of the block failing validation
|
||||
number: u64,
|
||||
/// The details of validation failure
|
||||
#[source]
|
||||
error: Box<ConsensusError>,
|
||||
},
|
||||
/// Received more bodies than requested.
|
||||
#[error("received more bodies than requested: {0}")]
|
||||
#[display(fmt = "received more bodies than requested: {_0}")]
|
||||
TooManyBodies(GotExpected<usize>),
|
||||
/// Headers missing from the database.
|
||||
#[error("header missing from the database: {block_number}")]
|
||||
#[display(fmt = "header missing from the database: {block_number}")]
|
||||
MissingHeader {
|
||||
/// Missing header block number.
|
||||
block_number: BlockNumber,
|
||||
},
|
||||
/// Body range invalid
|
||||
#[error("requested body range is invalid: {range:?}")]
|
||||
#[display(fmt = "requested body range is invalid: {range:?}")]
|
||||
InvalidBodyRange {
|
||||
/// Invalid block number range.
|
||||
range: RangeInclusive<BlockNumber>,
|
||||
},
|
||||
/* ==================== COMMON ERRORS ==================== */
|
||||
/// Timed out while waiting for request id response.
|
||||
#[error("timed out while waiting for response")]
|
||||
#[display(fmt = "timed out while waiting for response")]
|
||||
Timeout,
|
||||
/// Received empty response while expecting non empty
|
||||
#[error("received empty response")]
|
||||
#[display(fmt = "received empty response")]
|
||||
EmptyResponse,
|
||||
/// Error while executing the request.
|
||||
#[error(transparent)]
|
||||
RequestError(#[from] RequestError),
|
||||
RequestError(RequestError),
|
||||
/// Provider error.
|
||||
#[error(transparent)]
|
||||
Provider(#[from] ProviderError),
|
||||
Provider(ProviderError),
|
||||
}
|
||||
|
||||
impl From<DatabaseError> for DownloadError {
|
||||
@ -207,6 +206,32 @@ impl From<DatabaseError> for DownloadError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RequestError> for DownloadError {
|
||||
fn from(error: RequestError) -> Self {
|
||||
Self::RequestError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProviderError> for DownloadError {
|
||||
fn from(error: ProviderError) -> Self {
|
||||
Self::Provider(error)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for DownloadError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::HeaderValidation { error, .. } | Self::BodyValidation { error, .. } => {
|
||||
std::error::Error::source(error)
|
||||
}
|
||||
Self::RequestError(error) => std::error::Error::source(error),
|
||||
Self::Provider(error) => std::error::Error::source(error),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@ -1,23 +1,31 @@
|
||||
use derive_more::Display;
|
||||
use reth_consensus::ConsensusError;
|
||||
use reth_primitives::SealedHeader;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Header downloader result
|
||||
pub type HeadersDownloaderResult<T> = Result<T, HeadersDownloaderError>;
|
||||
|
||||
/// Error variants that can happen when sending requests to a session.
|
||||
#[derive(Debug, Error, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Display)]
|
||||
pub enum HeadersDownloaderError {
|
||||
/// The downloaded header cannot be attached to the local head,
|
||||
/// but is valid otherwise.
|
||||
#[error("valid downloaded header cannot be attached to the local head: {error}")]
|
||||
#[display(fmt = "valid downloaded header cannot be attached to the local head: {error}")]
|
||||
DetachedHead {
|
||||
/// The local head we attempted to attach to.
|
||||
local_head: Box<SealedHeader>,
|
||||
/// The header we attempted to attach.
|
||||
header: Box<SealedHeader>,
|
||||
/// The error that occurred when attempting to attach the header.
|
||||
#[source]
|
||||
error: Box<ConsensusError>,
|
||||
},
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for HeadersDownloaderError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::DetachedHead { error, .. } => Some(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user