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"
|
version = "1.0.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"auto_impl",
|
"auto_impl",
|
||||||
|
"derive_more",
|
||||||
"futures",
|
"futures",
|
||||||
"parking_lot 0.12.3",
|
"parking_lot 0.12.3",
|
||||||
"reth-consensus",
|
"reth-consensus",
|
||||||
@ -7594,7 +7595,6 @@ dependencies = [
|
|||||||
"reth-primitives",
|
"reth-primitives",
|
||||||
"reth-storage-errors",
|
"reth-storage-errors",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -27,8 +27,8 @@ tokio = { workspace = true, features = ["sync"] }
|
|||||||
|
|
||||||
# misc
|
# misc
|
||||||
auto_impl.workspace = true
|
auto_impl.workspace = true
|
||||||
thiserror.workspace = true
|
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
|
derive_more.workspace = true
|
||||||
|
|
||||||
parking_lot = { workspace = true, optional = true }
|
parking_lot = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
|
use derive_more::Display;
|
||||||
use reth_consensus::ConsensusError;
|
use reth_consensus::ConsensusError;
|
||||||
use reth_network_peers::WithPeerId;
|
use reth_network_peers::WithPeerId;
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
BlockHashOrNumber, BlockNumber, GotExpected, GotExpectedBoxed, Header, B256,
|
BlockHashOrNumber, BlockNumber, GotExpected, GotExpectedBoxed, Header, B256,
|
||||||
};
|
};
|
||||||
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
|
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
|
||||||
use thiserror::Error;
|
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
|
|
||||||
use super::headers::client::HeadersRequest;
|
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.
|
/// Error variants that can happen when sending requests to a session.
|
||||||
///
|
///
|
||||||
/// Represents errors encountered when sending requests.
|
/// Represents errors encountered when sending requests.
|
||||||
#[derive(Clone, Debug, Error, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq, Display)]
|
||||||
pub enum RequestError {
|
pub enum RequestError {
|
||||||
/// Closed channel to the peer.
|
/// 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.
|
/// Indicates the channel to the peer is closed.
|
||||||
ChannelClosed,
|
ChannelClosed,
|
||||||
/// Connection to a peer dropped while handling the request.
|
/// 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.
|
/// Represents a dropped connection while handling the request.
|
||||||
ConnectionDropped,
|
ConnectionDropped,
|
||||||
/// Capability message is not supported by the remote peer.
|
/// 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.
|
/// Indicates an unsupported capability message from the remote peer.
|
||||||
UnsupportedCapability,
|
UnsupportedCapability,
|
||||||
/// Request timed out while awaiting response.
|
/// 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.
|
/// Represents a timeout while waiting for a response.
|
||||||
Timeout,
|
Timeout,
|
||||||
/// Received bad response.
|
/// Received bad response.
|
||||||
#[error("received bad response")]
|
#[display(fmt = "received bad response")]
|
||||||
/// Indicates a bad response was received.
|
/// Indicates a bad response was received.
|
||||||
BadResponse,
|
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
|
/// The download result type
|
||||||
pub type DownloadResult<T> = Result<T, DownloadError>;
|
pub type DownloadResult<T> = Result<T, DownloadError>;
|
||||||
|
|
||||||
/// The downloader error type
|
/// The downloader error type
|
||||||
#[derive(Error, Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Display)]
|
||||||
pub enum DownloadError {
|
pub enum DownloadError {
|
||||||
/* ==================== HEADER ERRORS ==================== */
|
/* ==================== HEADER ERRORS ==================== */
|
||||||
/// Header validation failed.
|
/// 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 {
|
HeaderValidation {
|
||||||
/// Hash of header failing validation
|
/// Hash of header failing validation
|
||||||
hash: B256,
|
hash: B256,
|
||||||
/// Number of header failing validation
|
/// Number of header failing validation
|
||||||
number: u64,
|
number: u64,
|
||||||
/// The details of validation failure
|
/// The details of validation failure
|
||||||
#[source]
|
|
||||||
error: Box<ConsensusError>,
|
error: Box<ConsensusError>,
|
||||||
},
|
},
|
||||||
/// Received an invalid tip.
|
/// Received an invalid tip.
|
||||||
#[error("received invalid tip: {0}")]
|
#[display(fmt = "received invalid tip: {_0}")]
|
||||||
InvalidTip(GotExpectedBoxed<B256>),
|
InvalidTip(GotExpectedBoxed<B256>),
|
||||||
/// Received a tip with an invalid tip number.
|
/// Received a tip with an invalid tip number.
|
||||||
#[error("received invalid tip number: {0}")]
|
#[display(fmt = "received invalid tip number: {_0}")]
|
||||||
InvalidTipNumber(GotExpected<u64>),
|
InvalidTipNumber(GotExpected<u64>),
|
||||||
/// Received a response to a request with unexpected start block
|
/// 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>),
|
HeadersResponseStartBlockMismatch(GotExpected<u64>),
|
||||||
/// Received headers with less than expected items.
|
/// 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>),
|
HeadersResponseTooShort(GotExpected<u64>),
|
||||||
|
|
||||||
/* ==================== BODIES ERRORS ==================== */
|
/* ==================== BODIES ERRORS ==================== */
|
||||||
/// Block validation failed
|
/// 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 {
|
BodyValidation {
|
||||||
/// Hash of the block failing validation
|
/// Hash of the block failing validation
|
||||||
hash: B256,
|
hash: B256,
|
||||||
/// Number of the block failing validation
|
/// Number of the block failing validation
|
||||||
number: u64,
|
number: u64,
|
||||||
/// The details of validation failure
|
/// The details of validation failure
|
||||||
#[source]
|
|
||||||
error: Box<ConsensusError>,
|
error: Box<ConsensusError>,
|
||||||
},
|
},
|
||||||
/// Received more bodies than requested.
|
/// Received more bodies than requested.
|
||||||
#[error("received more bodies than requested: {0}")]
|
#[display(fmt = "received more bodies than requested: {_0}")]
|
||||||
TooManyBodies(GotExpected<usize>),
|
TooManyBodies(GotExpected<usize>),
|
||||||
/// Headers missing from the database.
|
/// Headers missing from the database.
|
||||||
#[error("header missing from the database: {block_number}")]
|
#[display(fmt = "header missing from the database: {block_number}")]
|
||||||
MissingHeader {
|
MissingHeader {
|
||||||
/// Missing header block number.
|
/// Missing header block number.
|
||||||
block_number: BlockNumber,
|
block_number: BlockNumber,
|
||||||
},
|
},
|
||||||
/// Body range invalid
|
/// Body range invalid
|
||||||
#[error("requested body range is invalid: {range:?}")]
|
#[display(fmt = "requested body range is invalid: {range:?}")]
|
||||||
InvalidBodyRange {
|
InvalidBodyRange {
|
||||||
/// Invalid block number range.
|
/// Invalid block number range.
|
||||||
range: RangeInclusive<BlockNumber>,
|
range: RangeInclusive<BlockNumber>,
|
||||||
},
|
},
|
||||||
/* ==================== COMMON ERRORS ==================== */
|
/* ==================== COMMON ERRORS ==================== */
|
||||||
/// Timed out while waiting for request id response.
|
/// Timed out while waiting for request id response.
|
||||||
#[error("timed out while waiting for response")]
|
#[display(fmt = "timed out while waiting for response")]
|
||||||
Timeout,
|
Timeout,
|
||||||
/// Received empty response while expecting non empty
|
/// Received empty response while expecting non empty
|
||||||
#[error("received empty response")]
|
#[display(fmt = "received empty response")]
|
||||||
EmptyResponse,
|
EmptyResponse,
|
||||||
/// Error while executing the request.
|
/// Error while executing the request.
|
||||||
#[error(transparent)]
|
RequestError(RequestError),
|
||||||
RequestError(#[from] RequestError),
|
|
||||||
/// Provider error.
|
/// Provider error.
|
||||||
#[error(transparent)]
|
Provider(ProviderError),
|
||||||
Provider(#[from] ProviderError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DatabaseError> for DownloadError {
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@ -1,23 +1,31 @@
|
|||||||
|
use derive_more::Display;
|
||||||
use reth_consensus::ConsensusError;
|
use reth_consensus::ConsensusError;
|
||||||
use reth_primitives::SealedHeader;
|
use reth_primitives::SealedHeader;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
/// Header downloader result
|
/// Header downloader result
|
||||||
pub type HeadersDownloaderResult<T> = Result<T, HeadersDownloaderError>;
|
pub type HeadersDownloaderResult<T> = Result<T, HeadersDownloaderError>;
|
||||||
|
|
||||||
/// Error variants that can happen when sending requests to a session.
|
/// 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 {
|
pub enum HeadersDownloaderError {
|
||||||
/// The downloaded header cannot be attached to the local head,
|
/// The downloaded header cannot be attached to the local head,
|
||||||
/// but is valid otherwise.
|
/// 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 {
|
DetachedHead {
|
||||||
/// The local head we attempted to attach to.
|
/// The local head we attempted to attach to.
|
||||||
local_head: Box<SealedHeader>,
|
local_head: Box<SealedHeader>,
|
||||||
/// The header we attempted to attach.
|
/// The header we attempted to attach.
|
||||||
header: Box<SealedHeader>,
|
header: Box<SealedHeader>,
|
||||||
/// The error that occurred when attempting to attach the header.
|
/// The error that occurred when attempting to attach the header.
|
||||||
#[source]
|
|
||||||
error: Box<ConsensusError>,
|
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