mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Alloy migration (#4737)
Co-authored-by: Alessandro Mazza <121622391+alessandromazza98@users.noreply.github.com> Co-authored-by: Supernovahs.eth <91280922+supernovahs@users.noreply.github.com> Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me>
This commit is contained in:
@ -9,24 +9,20 @@ homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
bytes.workspace = true
|
||||
thiserror.workspace = true
|
||||
serde = { workspace = true, optional = true }
|
||||
|
||||
# reth
|
||||
reth-codecs = { path = "../../storage/codecs" }
|
||||
reth-primitives.workspace = true
|
||||
reth-ecies = { path = "../ecies" }
|
||||
reth-rlp = { workspace = true, features = ["alloc", "derive", "std", "ethereum-types", "smol_str"] }
|
||||
alloy-rlp = { workspace = true, features = ["derive"] }
|
||||
reth-discv4 = { path = "../discv4" }
|
||||
|
||||
# metrics
|
||||
reth-metrics.workspace = true
|
||||
metrics.workspace = true
|
||||
|
||||
# used for Chain and builders
|
||||
ethers-core = { workspace = true, default-features = false }
|
||||
|
||||
bytes.workspace = true
|
||||
thiserror.workspace = true
|
||||
serde = { workspace = true, optional = true }
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
tokio-util = { workspace = true, features = ["io", "codec"] }
|
||||
futures.workspace = true
|
||||
@ -34,7 +30,6 @@ tokio-stream.workspace = true
|
||||
pin-project.workspace = true
|
||||
tracing.workspace = true
|
||||
snap = "1.0.5"
|
||||
smol_str = "0.2"
|
||||
async-trait.workspace = true
|
||||
|
||||
# arbitrary utils
|
||||
@ -49,8 +44,6 @@ ethers-core = { workspace = true, default-features = false }
|
||||
|
||||
test-fuzz = "4"
|
||||
tokio-util = { workspace = true, features = ["io", "codec"] }
|
||||
hex-literal.workspace = true
|
||||
hex = "0.4"
|
||||
rand.workspace = true
|
||||
secp256k1 = { workspace = true, features = ["global-context", "rand-std", "recovery"] }
|
||||
|
||||
@ -60,7 +53,7 @@ proptest-derive.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["serde"]
|
||||
serde = ["dep:serde", "smol_str/serde"]
|
||||
serde = ["dep:serde"]
|
||||
arbitrary = ["reth-primitives/arbitrary", "dep:arbitrary", "dep:proptest", "dep:proptest-derive"]
|
||||
|
||||
[[test]]
|
||||
|
||||
@ -4,23 +4,23 @@ use crate::{
|
||||
capability::Capability, hello::HelloMessage, p2pstream::ProtocolVersion, EthVersion, Status,
|
||||
};
|
||||
use reth_discv4::DEFAULT_DISCOVERY_PORT;
|
||||
use reth_primitives::{Chain, ForkId, PeerId, H256, U256};
|
||||
use reth_primitives::{Chain, ForkId, PeerId, B256, U256};
|
||||
|
||||
/// Builder for [`Status`] messages.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use reth_eth_wire::EthVersion;
|
||||
/// use reth_primitives::{Chain, U256, H256, MAINNET_GENESIS, MAINNET, Hardfork};
|
||||
/// use reth_primitives::{Chain, U256, B256, MAINNET_GENESIS, MAINNET, Hardfork};
|
||||
/// use reth_eth_wire::types::Status;
|
||||
///
|
||||
/// // this is just an example status message!
|
||||
/// let status = Status::builder()
|
||||
/// .version(EthVersion::Eth66.into())
|
||||
/// .chain(Chain::Named(ethers_core::types::Chain::Mainnet))
|
||||
/// .chain(Chain::mainnet())
|
||||
/// .total_difficulty(U256::from(100))
|
||||
/// .blockhash(H256::from(MAINNET_GENESIS))
|
||||
/// .genesis(H256::from(MAINNET_GENESIS))
|
||||
/// .blockhash(B256::from(MAINNET_GENESIS))
|
||||
/// .genesis(B256::from(MAINNET_GENESIS))
|
||||
/// .forkid(Hardfork::Paris.fork_id(&MAINNET).unwrap())
|
||||
/// .build();
|
||||
///
|
||||
@ -28,10 +28,10 @@ use reth_primitives::{Chain, ForkId, PeerId, H256, U256};
|
||||
/// status,
|
||||
/// Status {
|
||||
/// version: EthVersion::Eth66.into(),
|
||||
/// chain: Chain::Named(ethers_core::types::Chain::Mainnet),
|
||||
/// chain: Chain::mainnet(),
|
||||
/// total_difficulty: U256::from(100),
|
||||
/// blockhash: H256::from(MAINNET_GENESIS),
|
||||
/// genesis: H256::from(MAINNET_GENESIS),
|
||||
/// blockhash: B256::from(MAINNET_GENESIS),
|
||||
/// genesis: B256::from(MAINNET_GENESIS),
|
||||
/// forkid: Hardfork::Paris.fork_id(&MAINNET).unwrap(),
|
||||
/// }
|
||||
/// );
|
||||
@ -66,13 +66,13 @@ impl StatusBuilder {
|
||||
}
|
||||
|
||||
/// Sets the block hash.
|
||||
pub fn blockhash(mut self, blockhash: H256) -> Self {
|
||||
pub fn blockhash(mut self, blockhash: B256) -> Self {
|
||||
self.status.blockhash = blockhash;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the genesis hash.
|
||||
pub fn genesis(mut self, genesis: H256) -> Self {
|
||||
pub fn genesis(mut self, genesis: B256) -> Self {
|
||||
self.status.genesis = genesis;
|
||||
self
|
||||
}
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
//! All capability related types
|
||||
|
||||
use crate::{version::ParseVersionError, EthMessage, EthVersion};
|
||||
use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable};
|
||||
use reth_codecs::add_arbitrary_tests;
|
||||
use reth_primitives::bytes::{BufMut, Bytes};
|
||||
use reth_rlp::{Decodable, DecodeError, Encodable, RlpDecodable, RlpEncodable};
|
||||
use smol_str::SmolStr;
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
@ -43,14 +42,14 @@ pub enum CapabilityMessage {
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct Capability {
|
||||
/// The name of the subprotocol
|
||||
pub name: SmolStr,
|
||||
pub name: String,
|
||||
/// The version of the subprotocol
|
||||
pub version: usize,
|
||||
}
|
||||
|
||||
impl Capability {
|
||||
/// Create a new `Capability` with the given name and version.
|
||||
pub fn new(name: SmolStr, version: usize) -> Self {
|
||||
pub fn new(name: String, version: usize) -> Self {
|
||||
Self { name, version }
|
||||
}
|
||||
|
||||
@ -83,7 +82,7 @@ impl fmt::Display for Capability {
|
||||
impl<'a> arbitrary::Arbitrary<'a> for Capability {
|
||||
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
let version = u.int_in_range(0..=32)?; // TODO: What's the max?
|
||||
let name: SmolStr = String::arbitrary(u)?.into(); // TODO: what possible values?
|
||||
let name = String::arbitrary(u)?; // TODO: what possible values?
|
||||
Ok(Self { name, version })
|
||||
}
|
||||
}
|
||||
@ -95,7 +94,7 @@ impl proptest::arbitrary::Arbitrary for Capability {
|
||||
any_with::<String>(args) // TODO: what possible values?
|
||||
.prop_flat_map(move |name| {
|
||||
any_with::<usize>(()) // TODO: What's the max?
|
||||
.prop_map(move |version| Capability { name: name.clone().into(), version })
|
||||
.prop_map(move |version| Capability { name: name.clone(), version })
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
@ -169,7 +168,7 @@ impl Encodable for Capabilities {
|
||||
}
|
||||
|
||||
impl Decodable for Capabilities {
|
||||
fn decode(buf: &mut &[u8]) -> Result<Self, DecodeError> {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
let inner = Vec::<Capability>::decode(buf)?;
|
||||
|
||||
Ok(Self {
|
||||
@ -189,7 +188,7 @@ pub enum SharedCapability {
|
||||
Eth { version: EthVersion, offset: u8 },
|
||||
|
||||
/// An unknown capability.
|
||||
UnknownCapability { name: SmolStr, version: u8, offset: u8 },
|
||||
UnknownCapability { name: String, version: u8, offset: u8 },
|
||||
}
|
||||
|
||||
impl SharedCapability {
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
//! Disconnect
|
||||
|
||||
use bytes::Bytes;
|
||||
use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header};
|
||||
use futures::{Sink, SinkExt};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_ecies::stream::ECIESStream;
|
||||
use reth_primitives::bytes::{Buf, BufMut};
|
||||
use reth_rlp::{Decodable, DecodeError, Encodable, Header};
|
||||
use std::fmt::Display;
|
||||
use thiserror::Error;
|
||||
use tokio::io::AsyncWrite;
|
||||
@ -120,11 +119,11 @@ impl Encodable for DisconnectReason {
|
||||
/// The [`Decodable`] implementation for [`DisconnectReason`] supports either a disconnect reason
|
||||
/// encoded a single byte or a RLP list containing the disconnect reason.
|
||||
impl Decodable for DisconnectReason {
|
||||
fn decode(buf: &mut &[u8]) -> Result<Self, DecodeError> {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
if buf.is_empty() {
|
||||
return Err(DecodeError::InputTooShort)
|
||||
return Err(RlpError::InputTooShort)
|
||||
} else if buf.len() > 2 {
|
||||
return Err(DecodeError::Overflow)
|
||||
return Err(RlpError::Overflow)
|
||||
}
|
||||
|
||||
if buf.len() > 1 {
|
||||
@ -132,7 +131,7 @@ impl Decodable for DisconnectReason {
|
||||
// buf[0] is the first (and only) element of the list.
|
||||
let header = Header::decode(buf)?;
|
||||
if !header.list {
|
||||
return Err(DecodeError::UnexpectedString)
|
||||
return Err(RlpError::UnexpectedString)
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +142,7 @@ impl Decodable for DisconnectReason {
|
||||
Ok(DisconnectReason::DisconnectRequested)
|
||||
} else {
|
||||
DisconnectReason::try_from(u8::decode(buf)?)
|
||||
.map_err(|_| DecodeError::Custom("unknown disconnect reason"))
|
||||
.map_err(|_| RlpError::Custom("unknown disconnect reason"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,7 +177,7 @@ where
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<S> CanDisconnect<Bytes> for ECIESStream<S>
|
||||
impl<S> CanDisconnect<bytes::Bytes> for ECIESStream<S>
|
||||
where
|
||||
S: AsyncWrite + Unpin + Send,
|
||||
{
|
||||
@ -190,8 +189,8 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{p2pstream::P2PMessage, DisconnectReason};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_primitives::hex;
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
|
||||
fn all_reasons() -> Vec<DisconnectReason> {
|
||||
vec![
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
use crate::{
|
||||
errors::P2PStreamError, version::ParseVersionError, DisconnectReason, EthMessageID, EthVersion,
|
||||
};
|
||||
use reth_primitives::{Chain, ValidationError, H256};
|
||||
use reth_primitives::{Chain, ValidationError, B256};
|
||||
use std::io;
|
||||
|
||||
/// Errors when sending/receiving messages
|
||||
@ -50,8 +50,8 @@ impl From<io::Error> for EthStreamError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<reth_rlp::DecodeError> for EthStreamError {
|
||||
fn from(err: reth_rlp::DecodeError) -> Self {
|
||||
impl From<alloy_rlp::Error> for EthStreamError {
|
||||
fn from(err: alloy_rlp::Error) -> Self {
|
||||
P2PStreamError::from(err).into()
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,7 @@ pub enum EthHandshakeError {
|
||||
#[error(transparent)]
|
||||
InvalidFork(#[from] ValidationError),
|
||||
#[error("mismatched genesis in Status message. expected: {expected:?}, got: {got:?}")]
|
||||
MismatchedGenesis { expected: H256, got: H256 },
|
||||
MismatchedGenesis { expected: B256, got: B256 },
|
||||
#[error("mismatched protocol version in Status message. expected: {expected:?}, got: {got:?}")]
|
||||
MismatchedProtocolVersion { expected: u8, got: u8 },
|
||||
#[error("mismatched chain in Status message. expected: {expected:?}, got: {got:?}")]
|
||||
|
||||
@ -12,7 +12,7 @@ pub enum P2PStreamError {
|
||||
#[error(transparent)]
|
||||
Io(#[from] io::Error),
|
||||
#[error(transparent)]
|
||||
Rlp(#[from] reth_rlp::DecodeError),
|
||||
Rlp(#[from] alloy_rlp::Error),
|
||||
#[error(transparent)]
|
||||
Snap(#[from] snap::Error),
|
||||
#[error(transparent)]
|
||||
@ -73,7 +73,7 @@ pub enum P2PHandshakeError {
|
||||
#[error("Disconnected by peer: {0}")]
|
||||
Disconnected(DisconnectReason),
|
||||
#[error("error decoding a message during handshake: {0}")]
|
||||
DecodeError(#[from] reth_rlp::DecodeError),
|
||||
DecodeError(#[from] alloy_rlp::Error),
|
||||
}
|
||||
|
||||
/// An error that can occur when interacting with a pinger.
|
||||
|
||||
@ -4,13 +4,13 @@ use crate::{
|
||||
types::{EthMessage, ProtocolMessage, Status},
|
||||
CanDisconnect, DisconnectReason, EthVersion,
|
||||
};
|
||||
use alloy_rlp::Encodable;
|
||||
use futures::{ready, Sink, SinkExt, StreamExt};
|
||||
use pin_project::pin_project;
|
||||
use reth_primitives::{
|
||||
bytes::{Bytes, BytesMut},
|
||||
ForkFilter,
|
||||
};
|
||||
use reth_rlp::Encodable;
|
||||
use std::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
@ -322,25 +322,24 @@ mod tests {
|
||||
types::{broadcast::BlockHashNumber, EthMessage, EthVersion, Status},
|
||||
EthStream, PassthroughCodec,
|
||||
};
|
||||
use ethers_core::types::Chain;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use reth_discv4::DEFAULT_DISCOVERY_PORT;
|
||||
use reth_ecies::{stream::ECIESStream, util::pk2id};
|
||||
use reth_primitives::{ForkFilter, Head, H256, U256};
|
||||
use reth_primitives::{ForkFilter, Head, NamedChain, B256, U256};
|
||||
use secp256k1::{SecretKey, SECP256K1};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio_util::codec::Decoder;
|
||||
|
||||
#[tokio::test]
|
||||
async fn can_handshake() {
|
||||
let genesis = H256::random();
|
||||
let genesis = B256::random();
|
||||
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
|
||||
|
||||
let status = Status {
|
||||
version: EthVersion::Eth67 as u8,
|
||||
chain: Chain::Mainnet.into(),
|
||||
chain: NamedChain::Mainnet.into(),
|
||||
total_difficulty: U256::ZERO,
|
||||
blockhash: H256::random(),
|
||||
blockhash: B256::random(),
|
||||
genesis,
|
||||
// Pass the current fork id.
|
||||
forkid: fork_filter.current(),
|
||||
@ -380,14 +379,14 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn pass_handshake_on_low_td_bitlen() {
|
||||
let genesis = H256::random();
|
||||
let genesis = B256::random();
|
||||
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
|
||||
|
||||
let status = Status {
|
||||
version: EthVersion::Eth67 as u8,
|
||||
chain: Chain::Mainnet.into(),
|
||||
chain: NamedChain::Mainnet.into(),
|
||||
total_difficulty: U256::from(2).pow(U256::from(100)) - U256::from(1),
|
||||
blockhash: H256::random(),
|
||||
blockhash: B256::random(),
|
||||
genesis,
|
||||
// Pass the current fork id.
|
||||
forkid: fork_filter.current(),
|
||||
@ -427,14 +426,14 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn fail_handshake_on_high_td_bitlen() {
|
||||
let genesis = H256::random();
|
||||
let genesis = B256::random();
|
||||
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
|
||||
|
||||
let status = Status {
|
||||
version: EthVersion::Eth67 as u8,
|
||||
chain: Chain::Mainnet.into(),
|
||||
chain: NamedChain::Mainnet.into(),
|
||||
total_difficulty: U256::from(2).pow(U256::from(100)),
|
||||
blockhash: H256::random(),
|
||||
blockhash: B256::random(),
|
||||
genesis,
|
||||
// Pass the current fork id.
|
||||
forkid: fork_filter.current(),
|
||||
@ -485,8 +484,8 @@ mod tests {
|
||||
let local_addr = listener.local_addr().unwrap();
|
||||
let test_msg = EthMessage::NewBlockHashes(
|
||||
vec![
|
||||
BlockHashNumber { hash: H256::random(), number: 5 },
|
||||
BlockHashNumber { hash: H256::random(), number: 6 },
|
||||
BlockHashNumber { hash: B256::random(), number: 5 },
|
||||
BlockHashNumber { hash: B256::random(), number: 6 },
|
||||
]
|
||||
.into(),
|
||||
);
|
||||
@ -520,8 +519,8 @@ mod tests {
|
||||
let server_key = SecretKey::new(&mut rand::thread_rng());
|
||||
let test_msg = EthMessage::NewBlockHashes(
|
||||
vec![
|
||||
BlockHashNumber { hash: H256::random(), number: 5 },
|
||||
BlockHashNumber { hash: H256::random(), number: 6 },
|
||||
BlockHashNumber { hash: B256::random(), number: 5 },
|
||||
BlockHashNumber { hash: B256::random(), number: 6 },
|
||||
]
|
||||
.into(),
|
||||
);
|
||||
@ -562,20 +561,20 @@ mod tests {
|
||||
let server_key = SecretKey::new(&mut rand::thread_rng());
|
||||
let test_msg = EthMessage::NewBlockHashes(
|
||||
vec![
|
||||
BlockHashNumber { hash: H256::random(), number: 5 },
|
||||
BlockHashNumber { hash: H256::random(), number: 6 },
|
||||
BlockHashNumber { hash: B256::random(), number: 5 },
|
||||
BlockHashNumber { hash: B256::random(), number: 6 },
|
||||
]
|
||||
.into(),
|
||||
);
|
||||
|
||||
let genesis = H256::random();
|
||||
let genesis = B256::random();
|
||||
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
|
||||
|
||||
let status = Status {
|
||||
version: EthVersion::Eth67 as u8,
|
||||
chain: Chain::Mainnet.into(),
|
||||
chain: NamedChain::Mainnet.into(),
|
||||
total_difficulty: U256::ZERO,
|
||||
blockhash: H256::random(),
|
||||
blockhash: B256::random(),
|
||||
genesis,
|
||||
// Pass the current fork id.
|
||||
forkid: fork_filter.current(),
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
use crate::{capability::Capability, EthVersion, ProtocolVersion};
|
||||
use alloy_rlp::{RlpDecodable, RlpEncodable};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_discv4::DEFAULT_DISCOVERY_PORT;
|
||||
use reth_primitives::{constants::RETH_CLIENT_VERSION, PeerId};
|
||||
use reth_rlp::{RlpDecodable, RlpEncodable};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -109,9 +109,9 @@ impl HelloMessageBuilder {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloy_rlp::{Decodable, Encodable, EMPTY_STRING_CODE};
|
||||
use reth_discv4::DEFAULT_DISCOVERY_PORT;
|
||||
use reth_ecies::util::pk2id;
|
||||
use reth_rlp::{Decodable, Encodable, EMPTY_STRING_CODE};
|
||||
use secp256k1::{SecretKey, SECP256K1};
|
||||
|
||||
use crate::{
|
||||
|
||||
@ -6,6 +6,7 @@ use crate::{
|
||||
pinger::{Pinger, PingerEvent},
|
||||
DisconnectReason, HelloMessage,
|
||||
};
|
||||
use alloy_rlp::{Decodable, Encodable, Error as RlpError, EMPTY_LIST_CODE};
|
||||
use futures::{Sink, SinkExt, StreamExt};
|
||||
use pin_project::pin_project;
|
||||
use reth_codecs::derive_arbitrary;
|
||||
@ -14,7 +15,6 @@ use reth_primitives::{
|
||||
bytes::{Buf, BufMut, Bytes, BytesMut},
|
||||
hex,
|
||||
};
|
||||
use reth_rlp::{Decodable, DecodeError, Encodable, EMPTY_LIST_CODE};
|
||||
use std::{
|
||||
collections::{BTreeSet, HashMap, HashSet, VecDeque},
|
||||
io,
|
||||
@ -732,14 +732,14 @@ impl Encodable for P2PMessage {
|
||||
/// The [`Decodable`] implementation for [`P2PMessage::Ping`] and [`P2PMessage::Pong`] expects a
|
||||
/// snappy encoded payload, see [`Encodable`] implementation.
|
||||
impl Decodable for P2PMessage {
|
||||
fn decode(buf: &mut &[u8]) -> Result<Self, DecodeError> {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
/// Removes the snappy prefix from the Ping/Pong buffer
|
||||
fn advance_snappy_ping_pong_payload(buf: &mut &[u8]) -> Result<(), DecodeError> {
|
||||
fn advance_snappy_ping_pong_payload(buf: &mut &[u8]) -> alloy_rlp::Result<()> {
|
||||
if buf.len() < 3 {
|
||||
return Err(DecodeError::InputTooShort)
|
||||
return Err(RlpError::InputTooShort)
|
||||
}
|
||||
if buf[..3] != [0x01, 0x00, EMPTY_LIST_CODE] {
|
||||
return Err(DecodeError::Custom("expected snappy payload"))
|
||||
return Err(RlpError::Custom("expected snappy payload"))
|
||||
}
|
||||
buf.advance(3);
|
||||
Ok(())
|
||||
@ -747,7 +747,7 @@ impl Decodable for P2PMessage {
|
||||
|
||||
let message_id = u8::decode(&mut &buf[..])?;
|
||||
let id = P2PMessageID::try_from(message_id)
|
||||
.or(Err(DecodeError::Custom("unknown p2p message id")))?;
|
||||
.or(Err(RlpError::Custom("unknown p2p message id")))?;
|
||||
buf.advance(1);
|
||||
match id {
|
||||
P2PMessageID::Hello => Ok(P2PMessage::Hello(HelloMessage::decode(buf)?)),
|
||||
@ -828,12 +828,12 @@ impl Encodable for ProtocolVersion {
|
||||
}
|
||||
|
||||
impl Decodable for ProtocolVersion {
|
||||
fn decode(buf: &mut &[u8]) -> Result<Self, DecodeError> {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
let version = u8::decode(buf)?;
|
||||
match version {
|
||||
4 => Ok(ProtocolVersion::V4),
|
||||
5 => Ok(ProtocolVersion::V5),
|
||||
_ => Err(DecodeError::Custom("unknown p2p protocol version")),
|
||||
_ => Err(RlpError::Custom("unknown p2p protocol version")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
//! Implements the `GetBlockHeaders`, `GetBlockBodies`, `BlockHeaders`, and `BlockBodies` message
|
||||
//! types.
|
||||
use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, H256};
|
||||
use reth_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
|
||||
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -57,11 +57,11 @@ impl From<Vec<Header>> for BlockHeaders {
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct GetBlockBodies(
|
||||
/// The block hashes to request bodies for.
|
||||
pub Vec<H256>,
|
||||
pub Vec<B256>,
|
||||
);
|
||||
|
||||
impl From<Vec<H256>> for GetBlockBodies {
|
||||
fn from(hashes: Vec<H256>) -> Self {
|
||||
impl From<Vec<B256>> for GetBlockBodies {
|
||||
fn from(hashes: Vec<B256>) -> Self {
|
||||
GetBlockBodies(hashes)
|
||||
}
|
||||
}
|
||||
@ -93,12 +93,11 @@ mod test {
|
||||
use crate::types::{
|
||||
message::RequestPair, BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders,
|
||||
};
|
||||
use hex_literal::hex;
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_primitives::{
|
||||
BlockHashOrNumber, Header, HeadersDirection, Signature, Transaction, TransactionKind,
|
||||
hex, BlockHashOrNumber, Header, HeadersDirection, Signature, Transaction, TransactionKind,
|
||||
TransactionSigned, TxLegacy, U256,
|
||||
};
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::BlockBody;
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
//! Types for broadcasting new data.
|
||||
use crate::{EthMessage, EthVersion};
|
||||
use bytes::Bytes;
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{Block, TransactionSigned, H256, U128};
|
||||
use reth_rlp::{
|
||||
use alloy_rlp::{
|
||||
Decodable, Encodable, RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper,
|
||||
};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{Block, Bytes, TransactionSigned, B256, U128};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
@ -41,7 +40,7 @@ impl NewBlockHashes {
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct BlockHashNumber {
|
||||
/// The block hash
|
||||
pub hash: H256,
|
||||
pub hash: B256,
|
||||
/// The block number
|
||||
pub number: u64,
|
||||
}
|
||||
@ -137,7 +136,7 @@ impl NewPooledTransactionHashes {
|
||||
}
|
||||
|
||||
/// Returns an iterator over all transaction hashes.
|
||||
pub fn iter_hashes(&self) -> impl Iterator<Item = &H256> + '_ {
|
||||
pub fn iter_hashes(&self) -> impl Iterator<Item = &B256> + '_ {
|
||||
match self {
|
||||
NewPooledTransactionHashes::Eth66(msg) => msg.0.iter(),
|
||||
NewPooledTransactionHashes::Eth68(msg) => msg.hashes.iter(),
|
||||
@ -145,7 +144,7 @@ impl NewPooledTransactionHashes {
|
||||
}
|
||||
|
||||
/// Consumes the type and returns all hashes
|
||||
pub fn into_hashes(self) -> Vec<H256> {
|
||||
pub fn into_hashes(self) -> Vec<B256> {
|
||||
match self {
|
||||
NewPooledTransactionHashes::Eth66(msg) => msg.0,
|
||||
NewPooledTransactionHashes::Eth68(msg) => msg.hashes,
|
||||
@ -153,7 +152,7 @@ impl NewPooledTransactionHashes {
|
||||
}
|
||||
|
||||
/// Returns an iterator over all transaction hashes.
|
||||
pub fn into_iter_hashes(self) -> impl Iterator<Item = H256> {
|
||||
pub fn into_iter_hashes(self) -> impl Iterator<Item = B256> {
|
||||
match self {
|
||||
NewPooledTransactionHashes::Eth66(msg) => msg.0.into_iter(),
|
||||
NewPooledTransactionHashes::Eth68(msg) => msg.hashes.into_iter(),
|
||||
@ -220,11 +219,11 @@ pub struct NewPooledTransactionHashes66(
|
||||
/// Transaction hashes for new transactions that have appeared on the network.
|
||||
/// Clients should request the transactions with the given hashes using a
|
||||
/// [`GetPooledTransactions`](crate::GetPooledTransactions) message.
|
||||
pub Vec<H256>,
|
||||
pub Vec<B256>,
|
||||
);
|
||||
|
||||
impl From<Vec<H256>> for NewPooledTransactionHashes66 {
|
||||
fn from(v: Vec<H256>) -> Self {
|
||||
impl From<Vec<B256>> for NewPooledTransactionHashes66 {
|
||||
fn from(v: Vec<B256>) -> Self {
|
||||
NewPooledTransactionHashes66(v)
|
||||
}
|
||||
}
|
||||
@ -243,8 +242,8 @@ pub struct NewPooledTransactionHashes68 {
|
||||
/// the following way:
|
||||
/// * `[type_0: B_1, type_1: B_1, ...]`
|
||||
///
|
||||
/// This would make it seem like the [`Encodable`](reth_rlp::Encodable) and
|
||||
/// [`Decodable`](reth_rlp::Decodable) implementations should directly use a `Vec<u8>` for
|
||||
/// This would make it seem like the [`Encodable`](alloy_rlp::Encodable) and
|
||||
/// [`Decodable`](alloy_rlp::Decodable) implementations should directly use a `Vec<u8>` for
|
||||
/// encoding and decoding, because it looks like this field should be encoded as a _list_ of
|
||||
/// bytes.
|
||||
///
|
||||
@ -255,14 +254,14 @@ pub struct NewPooledTransactionHashes68 {
|
||||
/// **not** a RLP list.
|
||||
///
|
||||
/// Because of this, we do not directly use the `Vec<u8>` when encoding and decoding, and
|
||||
/// instead use the [`Encodable`](reth_rlp::Encodable) and [`Decodable`](reth_rlp::Decodable)
|
||||
/// instead use the [`Encodable`](alloy_rlp::Encodable) and [`Decodable`](alloy_rlp::Decodable)
|
||||
/// implementations for `&[u8]` instead, which encodes into a RLP string, and expects an RLP
|
||||
/// string when decoding.
|
||||
pub types: Vec<u8>,
|
||||
/// Transaction sizes for new transactions that have appeared on the network.
|
||||
pub sizes: Vec<usize>,
|
||||
/// Transaction hashes for new transactions that have appeared on the network.
|
||||
pub hashes: Vec<H256>,
|
||||
pub hashes: Vec<B256>,
|
||||
}
|
||||
|
||||
impl Encodable for NewPooledTransactionHashes68 {
|
||||
@ -271,7 +270,7 @@ impl Encodable for NewPooledTransactionHashes68 {
|
||||
struct EncodableNewPooledTransactionHashes68<'a> {
|
||||
types: &'a [u8],
|
||||
sizes: &'a Vec<usize>,
|
||||
hashes: &'a Vec<H256>,
|
||||
hashes: &'a Vec<B256>,
|
||||
}
|
||||
|
||||
let encodable = EncodableNewPooledTransactionHashes68 {
|
||||
@ -287,7 +286,7 @@ impl Encodable for NewPooledTransactionHashes68 {
|
||||
struct EncodableNewPooledTransactionHashes68<'a> {
|
||||
types: &'a [u8],
|
||||
sizes: &'a Vec<usize>,
|
||||
hashes: &'a Vec<H256>,
|
||||
hashes: &'a Vec<B256>,
|
||||
}
|
||||
|
||||
let encodable = EncodableNewPooledTransactionHashes68 {
|
||||
@ -301,12 +300,12 @@ impl Encodable for NewPooledTransactionHashes68 {
|
||||
}
|
||||
|
||||
impl Decodable for NewPooledTransactionHashes68 {
|
||||
fn decode(buf: &mut &[u8]) -> Result<Self, reth_rlp::DecodeError> {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
#[derive(RlpDecodable)]
|
||||
struct EncodableNewPooledTransactionHashes68 {
|
||||
types: Bytes,
|
||||
sizes: Vec<usize>,
|
||||
hashes: Vec<H256>,
|
||||
hashes: Vec<B256>,
|
||||
}
|
||||
|
||||
let encodable = EncodableNewPooledTransactionHashes68::decode(buf)?;
|
||||
@ -316,13 +315,11 @@ impl Decodable for NewPooledTransactionHashes68 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
||||
use bytes::BytesMut;
|
||||
use hex_literal::hex;
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
|
||||
use super::*;
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use bytes::BytesMut;
|
||||
use reth_primitives::hex;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Takes as input a struct / encoded hex message pair, ensuring that we encode to the exact hex
|
||||
/// message, and decode to the exact struct.
|
||||
@ -341,12 +338,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_return_latest_block() {
|
||||
let mut blocks = NewBlockHashes(vec![BlockHashNumber { hash: H256::random(), number: 0 }]);
|
||||
let mut blocks = NewBlockHashes(vec![BlockHashNumber { hash: B256::random(), number: 0 }]);
|
||||
let latest = blocks.latest().unwrap();
|
||||
assert_eq!(latest.number, 0);
|
||||
|
||||
blocks.0.push(BlockHashNumber { hash: H256::random(), number: 100 });
|
||||
blocks.0.push(BlockHashNumber { hash: H256::random(), number: 2 });
|
||||
blocks.0.push(BlockHashNumber { hash: B256::random(), number: 100 });
|
||||
blocks.0.push(BlockHashNumber { hash: B256::random(), number: 2 });
|
||||
let latest = blocks.latest().unwrap();
|
||||
assert_eq!(latest.number, 100);
|
||||
}
|
||||
@ -362,7 +359,7 @@ mod tests {
|
||||
NewPooledTransactionHashes68 {
|
||||
types: vec![0x00],
|
||||
sizes: vec![0x00],
|
||||
hashes: vec![H256::from_str(
|
||||
hashes: vec![B256::from_str(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
||||
.unwrap()],
|
||||
@ -374,11 +371,11 @@ mod tests {
|
||||
types: vec![0x00, 0x00],
|
||||
sizes: vec![0x00, 0x00],
|
||||
hashes: vec![
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
||||
.unwrap(),
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -390,7 +387,7 @@ mod tests {
|
||||
NewPooledTransactionHashes68 {
|
||||
types: vec![0x02],
|
||||
sizes: vec![0xb6],
|
||||
hashes: vec![H256::from_str(
|
||||
hashes: vec![B256::from_str(
|
||||
"0xfecbed04c7b88d8e7221a0a3f5dc33f220212347fc167459ea5cc9c3eb4c1124",
|
||||
)
|
||||
.unwrap()],
|
||||
@ -402,11 +399,11 @@ mod tests {
|
||||
types: vec![0xff, 0xff],
|
||||
sizes: vec![0xffffffff, 0xffffffff],
|
||||
hashes: vec![
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
)
|
||||
.unwrap(),
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -419,11 +416,11 @@ mod tests {
|
||||
types: vec![0xff, 0xff],
|
||||
sizes: vec![0xffffffff, 0xffffffff],
|
||||
hashes: vec![
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0xbeefcafebeefcafebeefcafebeefcafebeefcafebeefcafebeefcafebeefcafe",
|
||||
)
|
||||
.unwrap(),
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0xbeefcafebeefcafebeefcafebeefcafebeefcafebeefcafebeefcafebeefcafe",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -436,11 +433,11 @@ mod tests {
|
||||
types: vec![0x10, 0x10],
|
||||
sizes: vec![0xdeadc0de, 0xdeadc0de],
|
||||
hashes: vec![
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0x3b9aca00f0671c9a2a1b817a0a78d3fe0c0f776cccb2a8c3c1b412a4f4e4d4e2",
|
||||
)
|
||||
.unwrap(),
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0x3b9aca00f0671c9a2a1b817a0a78d3fe0c0f776cccb2a8c3c1b412a4f4e4d4e2",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -453,11 +450,11 @@ mod tests {
|
||||
types: vec![0x6f, 0x6f],
|
||||
sizes: vec![0x7fffffff, 0x7fffffff],
|
||||
hashes: vec![
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000002",
|
||||
)
|
||||
.unwrap(),
|
||||
H256::from_str(
|
||||
B256::from_str(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000002",
|
||||
)
|
||||
.unwrap(),
|
||||
|
||||
@ -5,8 +5,8 @@ use super::{
|
||||
NewPooledTransactionHashes68, NodeData, PooledTransactions, Receipts, Status, Transactions,
|
||||
};
|
||||
use crate::{errors::EthStreamError, EthVersion, SharedTransactions};
|
||||
use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
|
||||
use reth_primitives::bytes::{Buf, BufMut};
|
||||
use reth_rlp::{length_of_length, Decodable, Encodable, Header};
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
@ -325,8 +325,8 @@ impl Encodable for EthMessageID {
|
||||
}
|
||||
|
||||
impl Decodable for EthMessageID {
|
||||
fn decode(buf: &mut &[u8]) -> Result<Self, reth_rlp::DecodeError> {
|
||||
let id = buf.first().ok_or(reth_rlp::DecodeError::InputTooShort)?;
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
let id = buf.first().ok_or(alloy_rlp::Error::InputTooShort)?;
|
||||
let id = match id {
|
||||
0x00 => EthMessageID::Status,
|
||||
0x01 => EthMessageID::NewBlockHashes,
|
||||
@ -343,7 +343,7 @@ impl Decodable for EthMessageID {
|
||||
0x0e => EthMessageID::NodeData,
|
||||
0x0f => EthMessageID::GetReceipts,
|
||||
0x10 => EthMessageID::Receipts,
|
||||
_ => return Err(reth_rlp::DecodeError::Custom("Invalid message ID")),
|
||||
_ => return Err(alloy_rlp::Error::Custom("Invalid message ID")),
|
||||
};
|
||||
buf.advance(1);
|
||||
Ok(id)
|
||||
@ -393,7 +393,7 @@ impl<T> Encodable for RequestPair<T>
|
||||
where
|
||||
T: Encodable,
|
||||
{
|
||||
fn encode(&self, out: &mut dyn reth_rlp::BufMut) {
|
||||
fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
|
||||
let header =
|
||||
Header { list: true, payload_length: self.request_id.length() + self.message.length() };
|
||||
|
||||
@ -416,7 +416,7 @@ impl<T> Decodable for RequestPair<T>
|
||||
where
|
||||
T: Decodable,
|
||||
{
|
||||
fn decode(buf: &mut &[u8]) -> Result<Self, reth_rlp::DecodeError> {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
let _header = Header::decode(buf)?;
|
||||
Ok(Self { request_id: u64::decode(buf)?, message: T::decode(buf)? })
|
||||
}
|
||||
@ -428,8 +428,8 @@ mod test {
|
||||
errors::EthStreamError, types::message::RequestPair, EthMessage, EthMessageID, GetNodeData,
|
||||
NodeData, ProtocolMessage,
|
||||
};
|
||||
use hex_literal::hex;
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_primitives::hex;
|
||||
|
||||
fn encode<T: Encodable>(value: T) -> Vec<u8> {
|
||||
let mut buf = vec![];
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Implements the `GetReceipts` and `Receipts` message types.
|
||||
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{ReceiptWithBloom, H256};
|
||||
use reth_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use reth_primitives::{ReceiptWithBloom, B256};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct GetReceipts(
|
||||
/// The block hashes to request receipts for.
|
||||
pub Vec<H256>,
|
||||
pub Vec<B256>,
|
||||
);
|
||||
|
||||
/// The response to [`GetReceipts`], containing receipt lists that correspond to each block
|
||||
@ -37,9 +37,8 @@ mod test {
|
||||
types::{message::RequestPair, GetReceipts},
|
||||
Receipts,
|
||||
};
|
||||
use hex_literal::hex;
|
||||
use reth_primitives::{Log, Receipt, ReceiptWithBloom, TxType};
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_primitives::{hex, Log, Receipt, ReceiptWithBloom, TxType};
|
||||
|
||||
#[test]
|
||||
fn roundtrip_eip1559() {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Implements the `GetNodeData` and `NodeData` message types.
|
||||
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{Bytes, H256};
|
||||
use reth_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use reth_primitives::{Bytes, B256};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive_arbitrary(rlp)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct GetNodeData(pub Vec<H256>);
|
||||
pub struct GetNodeData(pub Vec<B256>);
|
||||
|
||||
/// The response to [`GetNodeData`], containing the state tree nodes or contract bytecode
|
||||
/// corresponding to the requested hashes.
|
||||
@ -26,10 +26,10 @@ pub struct NodeData(pub Vec<Bytes>);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use hex_literal::hex;
|
||||
use reth_primitives::hex;
|
||||
|
||||
use crate::{message::RequestPair, GetNodeData, NodeData};
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
|
||||
#[test]
|
||||
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
use crate::{EthVersion, StatusBuilder};
|
||||
|
||||
use alloy_rlp::{RlpDecodable, RlpEncodable};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{
|
||||
hex, Chain, ChainSpec, ForkId, Genesis, Hardfork, Head, H256, MAINNET, U256,
|
||||
hex, Chain, ChainSpec, ForkId, Genesis, Hardfork, Head, NamedChain, B256, MAINNET, U256,
|
||||
};
|
||||
use reth_rlp::{RlpDecodable, RlpEncodable};
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
@ -31,10 +30,10 @@ pub struct Status {
|
||||
pub total_difficulty: U256,
|
||||
|
||||
/// The highest difficulty block hash the peer has seen
|
||||
pub blockhash: H256,
|
||||
pub blockhash: B256,
|
||||
|
||||
/// The genesis hash of the peer's chain.
|
||||
pub genesis: H256,
|
||||
pub genesis: B256,
|
||||
|
||||
/// The fork identifier, a [CRC32
|
||||
/// checksum](https://en.wikipedia.org/wiki/Cyclic_redundancy_check#CRC-32_algorithm) for
|
||||
@ -134,7 +133,7 @@ impl Default for Status {
|
||||
let mainnet_genesis = MAINNET.genesis_hash();
|
||||
Status {
|
||||
version: EthVersion::Eth68 as u8,
|
||||
chain: Chain::Named(ethers_core::types::Chain::Mainnet),
|
||||
chain: Chain::Named(NamedChain::Mainnet),
|
||||
total_difficulty: U256::from(17_179_869_184u64),
|
||||
blockhash: mainnet_genesis,
|
||||
genesis: mainnet_genesis,
|
||||
@ -148,13 +147,12 @@ impl Default for Status {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::types::{EthVersion, Status};
|
||||
use ethers_core::types::Chain as NamedChain;
|
||||
use hex_literal::hex;
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use rand::Rng;
|
||||
use reth_primitives::{
|
||||
Chain, ChainSpec, ForkCondition, ForkHash, ForkId, Genesis, Hardfork, Head, H256, U256,
|
||||
hex, Chain, ChainSpec, ForkCondition, ForkHash, ForkId, Genesis, Hardfork, Head,
|
||||
NamedChain, B256, U256,
|
||||
};
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
@ -164,11 +162,11 @@ mod tests {
|
||||
version: EthVersion::Eth67 as u8,
|
||||
chain: Chain::Named(NamedChain::Mainnet),
|
||||
total_difficulty: U256::from(36206751599115524359527u128),
|
||||
blockhash: H256::from_str(
|
||||
blockhash: B256::from_str(
|
||||
"feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d",
|
||||
)
|
||||
.unwrap(),
|
||||
genesis: H256::from_str(
|
||||
genesis: B256::from_str(
|
||||
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -187,11 +185,11 @@ mod tests {
|
||||
version: EthVersion::Eth67 as u8,
|
||||
chain: Chain::Named(NamedChain::Mainnet),
|
||||
total_difficulty: U256::from(36206751599115524359527u128),
|
||||
blockhash: H256::from_str(
|
||||
blockhash: B256::from_str(
|
||||
"feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d",
|
||||
)
|
||||
.unwrap(),
|
||||
genesis: H256::from_str(
|
||||
genesis: B256::from_str(
|
||||
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -208,11 +206,11 @@ mod tests {
|
||||
version: EthVersion::Eth66 as u8,
|
||||
chain: Chain::Named(NamedChain::BinanceSmartChain),
|
||||
total_difficulty: U256::from(37851386u64),
|
||||
blockhash: H256::from_str(
|
||||
blockhash: B256::from_str(
|
||||
"f8514c4680ef27700751b08f37645309ce65a449616a3ea966bf39dd935bb27b",
|
||||
)
|
||||
.unwrap(),
|
||||
genesis: H256::from_str(
|
||||
genesis: B256::from_str(
|
||||
"0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -231,11 +229,11 @@ mod tests {
|
||||
version: EthVersion::Eth66 as u8,
|
||||
chain: Chain::Named(NamedChain::BinanceSmartChain),
|
||||
total_difficulty: U256::from(37851386u64),
|
||||
blockhash: H256::from_str(
|
||||
blockhash: B256::from_str(
|
||||
"f8514c4680ef27700751b08f37645309ce65a449616a3ea966bf39dd935bb27b",
|
||||
)
|
||||
.unwrap(),
|
||||
genesis: H256::from_str(
|
||||
genesis: B256::from_str(
|
||||
"0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -255,11 +253,11 @@ mod tests {
|
||||
"0x000000000000000000000000006d68fcffffffffffffffffffffffffdeab81b8",
|
||||
)
|
||||
.unwrap(),
|
||||
blockhash: H256::from_str(
|
||||
blockhash: B256::from_str(
|
||||
"523e8163a6d620a4cc152c547a05f28a03fec91a2a615194cb86df9731372c0c",
|
||||
)
|
||||
.unwrap(),
|
||||
genesis: H256::from_str(
|
||||
genesis: B256::from_str(
|
||||
"6499dccdc7c7def3ebb1ce4c6ee27ec6bd02aee570625ca391919faf77ef27bd",
|
||||
)
|
||||
.unwrap(),
|
||||
@ -271,8 +269,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn init_custom_status_fields() {
|
||||
let head_hash = H256::random();
|
||||
let mut rng = rand::thread_rng();
|
||||
let head_hash = rng.gen();
|
||||
let total_difficulty = U256::from(rng.gen::<u64>());
|
||||
|
||||
// create a genesis that has a random part, so we can check that the hash is preserved
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Implements the `GetPooledTransactions` and `PooledTransactions` message types.
|
||||
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{PooledTransactionsElement, TransactionSigned, H256};
|
||||
use reth_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use reth_primitives::{PooledTransactionsElement, TransactionSigned, B256};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -12,12 +12,12 @@ use serde::{Deserialize, Serialize};
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct GetPooledTransactions(
|
||||
/// The transaction hashes to request transaction bodies for.
|
||||
pub Vec<H256>,
|
||||
pub Vec<B256>,
|
||||
);
|
||||
|
||||
impl<T> From<Vec<T>> for GetPooledTransactions
|
||||
where
|
||||
T: Into<H256>,
|
||||
T: Into<B256>,
|
||||
{
|
||||
fn from(hashes: Vec<T>) -> Self {
|
||||
GetPooledTransactions(hashes.into_iter().map(|h| h.into()).collect())
|
||||
@ -48,11 +48,10 @@ impl From<Vec<TransactionSigned>> for PooledTransactions {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{message::RequestPair, GetPooledTransactions, PooledTransactions};
|
||||
use hex_literal::hex;
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_primitives::{
|
||||
hex, Signature, Transaction, TransactionKind, TransactionSigned, TxEip1559, TxLegacy, U256,
|
||||
};
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
//! Round-trip encoding fuzzing for the `eth-wire` crate.
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use serde::Serialize;
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// Creates a fuzz test for a type that should be [`Encodable`](reth_rlp::Encodable) and
|
||||
/// [`Decodable`](reth_rlp::Decodable).
|
||||
/// Creates a fuzz test for a type that should be [`Encodable`](alloy_rlp::Encodable) and
|
||||
/// [`Decodable`](alloy_rlp::Decodable).
|
||||
///
|
||||
/// The test will create a random instance of the type, encode it, and then decode it.
|
||||
fn roundtrip_encoding<T>(thing: T)
|
||||
@ -48,6 +48,7 @@ macro_rules! fuzz_type_and_name {
|
||||
#[cfg(any(test, feature = "bench"))]
|
||||
pub mod fuzz_rlp {
|
||||
use crate::roundtrip_encoding;
|
||||
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_eth_wire::{
|
||||
BlockBodies, BlockHeaders, DisconnectReason, GetBlockBodies, GetBlockHeaders, GetNodeData,
|
||||
@ -56,7 +57,6 @@ pub mod fuzz_rlp {
|
||||
PooledTransactions, Receipts, Status, Transactions,
|
||||
};
|
||||
use reth_primitives::{BlockHashOrNumber, TransactionSigned};
|
||||
use reth_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use test_fuzz::test_fuzz;
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Decoding tests for [`NewBlock`]
|
||||
use alloy_rlp::Decodable;
|
||||
use reth_eth_wire::NewBlock;
|
||||
use reth_primitives::hex;
|
||||
use reth_rlp::Decodable;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
#[test]
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Decoding tests for [`NewPooledTransactions`]
|
||||
use alloy_rlp::Decodable;
|
||||
use reth_eth_wire::NewPooledTransactionHashes66;
|
||||
use reth_primitives::hex;
|
||||
use reth_rlp::Decodable;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
#[test]
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Decoding tests for [`PooledTransactions`]
|
||||
use alloy_rlp::Decodable;
|
||||
use reth_eth_wire::PooledTransactions;
|
||||
use reth_primitives::{hex, Bytes, PooledTransactionsElement};
|
||||
use reth_rlp::Decodable;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user