Skip to content

Commit

Permalink
chore: remove cfg'ed use serde (#9352)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 6, 2024
1 parent 3b976bc commit 7579f91
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 45 deletions.
18 changes: 6 additions & 12 deletions crates/net/eth-wire-types/src/blocks.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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()?,
Expand All @@ -79,7 +73,7 @@ impl From<Vec<Header>> 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<B256>,
Expand All @@ -95,7 +89,7 @@ impl From<Vec<B256>> 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<BlockBody>,
Expand Down
15 changes: 6 additions & 9 deletions crates/net/eth-wire-types/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -75,7 +72,7 @@ impl From<NewBlockHashes> for Vec<BlockHashNumber> {
/// 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.
Expand All @@ -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<TransactionSigned>,
Expand Down Expand Up @@ -293,7 +290,7 @@ impl From<NewPooledTransactionHashes68> 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
Expand All @@ -310,7 +307,7 @@ impl From<Vec<B256>> 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.
///
Expand Down
10 changes: 4 additions & 6 deletions crates/net/eth-wire-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -182,7 +180,7 @@ impl From<EthBroadcastMessage> 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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -437,7 +435,7 @@ impl TryFrom<usize> 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<T> {
/// id for the contained request or response message
pub request_id: u64,
Expand Down
7 changes: 2 additions & 5 deletions crates/net/eth-wire-types/src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B256>,
Expand All @@ -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<Vec<ReceiptWithBloom>>,
Expand Down
7 changes: 2 additions & 5 deletions crates/net/eth-wire-types/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B256>);

/// The response to [`GetNodeData`], containing the state tree nodes or contract bytecode
Expand All @@ -22,7 +19,7 @@ pub struct GetNodeData(pub Vec<B256>);
/// 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<Bytes>);

#[cfg(test)]
Expand Down
4 changes: 1 addition & 3 deletions crates/net/eth-wire-types/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions crates/net/eth-wire-types/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B256>,
Expand Down Expand Up @@ -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<PooledTransactionsElement>,
Expand Down

0 comments on commit 7579f91

Please sign in to comment.