reth_eth_wire/errors/
eth.rsuse crate::{
errors::P2PStreamError, message::MessageError, version::ParseVersionError, DisconnectReason,
};
use alloy_primitives::B256;
use reth_chainspec::Chain;
use reth_eth_wire_types::EthVersion;
use reth_primitives::{GotExpected, GotExpectedBoxed, ValidationError};
use std::io;
#[derive(thiserror::Error, Debug)]
pub enum EthStreamError {
#[error(transparent)]
P2PStreamError(#[from] P2PStreamError),
#[error(transparent)]
ParseVersionError(#[from] ParseVersionError),
#[error(transparent)]
EthHandshakeError(#[from] EthHandshakeError),
#[error(transparent)]
InvalidMessage(#[from] MessageError),
#[error("message size ({0}) exceeds max length (10MB)")]
MessageTooBig(usize),
#[error("TransactionHashes invalid len of fields: hashes_len={hashes_len} types_len={types_len} sizes_len={sizes_len}")]
TransactionHashesInvalidLenOfFields {
hashes_len: usize,
types_len: usize,
sizes_len: usize,
},
#[error("never received data from remote peer")]
StreamTimeout,
}
impl EthStreamError {
pub const fn as_disconnected(&self) -> Option<DisconnectReason> {
if let Self::P2PStreamError(err) = self {
err.as_disconnected()
} else {
None
}
}
pub const fn as_io(&self) -> Option<&io::Error> {
if let Self::P2PStreamError(P2PStreamError::Io(io)) = self {
return Some(io)
}
None
}
}
impl From<io::Error> for EthStreamError {
fn from(err: io::Error) -> Self {
P2PStreamError::from(err).into()
}
}
#[derive(thiserror::Error, Debug)]
pub enum EthHandshakeError {
#[error("status message can only be recv/sent in handshake")]
StatusNotInHandshake,
#[error("received non-status message when trying to handshake")]
NonStatusMessageInHandshake,
#[error("no response received when sending out handshake")]
NoResponse,
#[error(transparent)]
InvalidFork(#[from] ValidationError),
#[error("mismatched genesis in status message: {0}")]
MismatchedGenesis(GotExpectedBoxed<B256>),
#[error("mismatched protocol version in status message: {0}")]
MismatchedProtocolVersion(GotExpected<EthVersion>),
#[error("mismatched chain in status message: {0}")]
MismatchedChain(GotExpected<Chain>),
#[error("total difficulty bitlen is too large: got {got}, maximum {maximum}")]
TotalDifficultyBitLenTooLarge {
got: usize,
maximum: usize,
},
}