diff --git a/crates/net/eth-wire-types/src/blocks.rs b/crates/net/eth-wire-types/src/blocks.rs index 536ef7a751..f6a8b020d3 100644 --- a/crates/net/eth-wire-types/src/blocks.rs +++ b/crates/net/eth-wire-types/src/blocks.rs @@ -1,17 +1,11 @@ //! Implements the `GetBlockHeaders`, `GetBlockBodies`, `BlockHeaders`, and `BlockBodies` message //! types. +use crate::HeadersDirection; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary}; -#[cfg(any(test, feature = "arbitrary"))] -use reth_primitives::generate_valid_header; use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -use crate::HeadersDirection; - /// A request for a peer to return block headers starting at the requested block. /// The peer must return at most [`limit`](#structfield.limit) headers. /// If the [`reverse`](#structfield.reverse) field is `true`, the headers will be returned starting @@ -23,7 +17,7 @@ use crate::HeadersDirection; /// in the direction specified by [`reverse`](#structfield.reverse). #[derive_arbitrary(rlp)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RlpEncodable, RlpDecodable)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GetBlockHeaders { /// The block number or hash that the peer should start returning headers from. pub start_block: BlockHashOrNumber, @@ -43,7 +37,7 @@ pub struct GetBlockHeaders { /// The response to [`GetBlockHeaders`], containing headers if any headers were found. #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[add_arbitrary_tests(rlp, 10)] pub struct BlockHeaders( /// The requested headers. @@ -57,7 +51,7 @@ impl<'a> arbitrary::Arbitrary<'a> for BlockHeaders { let mut headers = Vec::with_capacity(headers_count); for _ in 0..headers_count { - headers.push(generate_valid_header( + headers.push(reth_primitives::generate_valid_header( u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, @@ -79,7 +73,7 @@ impl From> for BlockHeaders { /// A request for a peer to return block bodies for the given block hashes. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GetBlockBodies( /// The block hashes to request bodies for. pub Vec, @@ -95,7 +89,7 @@ impl From> for GetBlockBodies { /// any were found. #[derive_arbitrary(rlp, 16)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BlockBodies( /// The requested block bodies, each of which should correspond to a hash in the request. pub Vec, diff --git a/crates/net/eth-wire-types/src/broadcast.rs b/crates/net/eth-wire-types/src/broadcast.rs index 1b5a3b4115..6b4d57a0b5 100644 --- a/crates/net/eth-wire-types/src/broadcast.rs +++ b/crates/net/eth-wire-types/src/broadcast.rs @@ -22,13 +22,10 @@ use proptest::{collection::vec, prelude::*}; #[cfg(feature = "arbitrary")] use proptest_arbitrary_interop::arb; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - /// This informs peers of new blocks that have appeared on the network. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct NewBlockHashes( /// New block hashes and the block number for each blockhash. /// Clients should request blocks using a [`GetBlockBodies`](crate::GetBlockBodies) message. @@ -52,7 +49,7 @@ impl NewBlockHashes { /// A block hash _and_ a block number. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BlockHashNumber { /// The block hash pub hash: B256, @@ -75,7 +72,7 @@ impl From for Vec { /// A new block with the current total difficulty, which includes the difficulty of the returned /// block. #[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive_arbitrary(rlp, 25)] pub struct NewBlock { /// A new block. @@ -88,7 +85,7 @@ pub struct NewBlock { /// in a block. #[derive_arbitrary(rlp, 10)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Transactions( /// New transactions for the peer to include in its mempool. pub Vec, @@ -293,7 +290,7 @@ impl From for NewPooledTransactionHashes { /// but have not been included in a block. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 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 @@ -310,7 +307,7 @@ impl From> for NewPooledTransactionHashes66 { /// Same as [`NewPooledTransactionHashes66`] but extends that that beside the transaction hashes, /// the node sends the transaction types and their sizes (as defined in EIP-2718) as well. #[derive(Clone, Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct NewPooledTransactionHashes68 { /// Transaction types for new transactions that have appeared on the network. /// diff --git a/crates/net/eth-wire-types/src/message.rs b/crates/net/eth-wire-types/src/message.rs index cbd5ca5361..920f48b894 100644 --- a/crates/net/eth-wire-types/src/message.rs +++ b/crates/net/eth-wire-types/src/message.rs @@ -15,8 +15,6 @@ use crate::{EthVersion, SharedTransactions}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use reth_primitives::bytes::{Buf, BufMut}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; use std::{fmt::Debug, sync::Arc}; /// [`MAX_MESSAGE_SIZE`] is the maximum cap on the size of a protocol message. @@ -36,7 +34,7 @@ pub enum MessageError { /// An `eth` protocol message, containing a message ID and payload. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ProtocolMessage { /// The unique identifier representing the type of the Ethereum message. pub message_type: EthMessageID, @@ -182,7 +180,7 @@ impl From for ProtocolBroadcastMessage { /// it, `NewPooledTransactionHashes` is renamed as [`NewPooledTransactionHashes66`] and /// [`NewPooledTransactionHashes68`] is defined. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum EthMessage { /// Represents a Status message required for the protocol handshake. Status(Status), @@ -333,7 +331,7 @@ impl Encodable for EthBroadcastMessage { /// Represents message IDs for eth protocol messages. #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum EthMessageID { /// Status message. Status = 0x00, @@ -437,7 +435,7 @@ impl TryFrom for EthMessageID { /// This can represent either a request or a response, since both include a message payload and /// request id. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct RequestPair { /// id for the contained request or response message pub request_id: u64, diff --git a/crates/net/eth-wire-types/src/receipts.rs b/crates/net/eth-wire-types/src/receipts.rs index 4816f85548..cbe74f9642 100644 --- a/crates/net/eth-wire-types/src/receipts.rs +++ b/crates/net/eth-wire-types/src/receipts.rs @@ -4,13 +4,10 @@ use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs_derive::derive_arbitrary; use reth_primitives::{ReceiptWithBloom, B256}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - /// A request for transaction receipts from the given block hashes. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GetReceipts( /// The block hashes to request receipts for. pub Vec, @@ -20,7 +17,7 @@ pub struct GetReceipts( /// requested. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Receipts( /// Each receipt hash should correspond to a block hash in the request. pub Vec>, diff --git a/crates/net/eth-wire-types/src/state.rs b/crates/net/eth-wire-types/src/state.rs index 5f3dc83395..aa1e064d08 100644 --- a/crates/net/eth-wire-types/src/state.rs +++ b/crates/net/eth-wire-types/src/state.rs @@ -4,15 +4,12 @@ use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs_derive::derive_arbitrary; use reth_primitives::{Bytes, B256}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - /// A request for state tree nodes corresponding to the given hashes. /// This message was removed in `eth/67`, only clients running `eth/66` or earlier will respond to /// this message. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GetNodeData(pub Vec); /// The response to [`GetNodeData`], containing the state tree nodes or contract bytecode @@ -22,7 +19,7 @@ pub struct GetNodeData(pub Vec); /// This message was removed in `eth/67`. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct NodeData(pub Vec); #[cfg(test)] diff --git a/crates/net/eth-wire-types/src/status.rs b/crates/net/eth-wire-types/src/status.rs index 85d09dcd59..8d46269006 100644 --- a/crates/net/eth-wire-types/src/status.rs +++ b/crates/net/eth-wire-types/src/status.rs @@ -5,8 +5,6 @@ use alloy_rlp::{RlpDecodable, RlpEncodable}; use reth_chainspec::{ChainSpec, MAINNET}; use reth_codecs_derive::derive_arbitrary; use reth_primitives::{hex, EthereumHardfork, ForkId, Head, B256, U256}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Display}; /// The status message is used in the eth protocol handshake to ensure that peers are on the same @@ -16,7 +14,7 @@ use std::fmt::{Debug, Display}; /// hash. This information should be treated as untrusted. #[derive_arbitrary(rlp)] #[derive(Copy, Clone, PartialEq, Eq, RlpEncodable, RlpDecodable)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Status { /// The current protocol version. For example, peers running `eth/66` would have a version of /// 66. diff --git a/crates/net/eth-wire-types/src/transactions.rs b/crates/net/eth-wire-types/src/transactions.rs index d0a42d49be..a5bf40b798 100644 --- a/crates/net/eth-wire-types/src/transactions.rs +++ b/crates/net/eth-wire-types/src/transactions.rs @@ -7,13 +7,10 @@ use reth_primitives::{ transaction::TransactionConversionError, PooledTransactionsElement, TransactionSigned, B256, }; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - /// A list of transaction hashes that the peer would like transaction bodies for. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GetPooledTransactions( /// The transaction hashes to request transaction bodies for. pub Vec, @@ -48,7 +45,7 @@ where Deref, Constructor, )] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PooledTransactions( /// The transaction bodies, each of which should correspond to a requested hash. pub Vec,