Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove #[reth_codec] and #[derive_arbitrary] macros #10263

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/net/eth-wire-types/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::HeadersDirection;
use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary};
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256};

/// A request for a peer to return block headers starting at the requested block.
Expand All @@ -15,9 +15,10 @@ use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256};
///
/// If the [`skip`](#structfield.skip) field is non-zero, the peer must skip that amount of headers
/// 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(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct GetBlockHeaders {
/// The block number or hash that the peer should start returning headers from.
pub start_block: BlockHashOrNumber,
Expand Down Expand Up @@ -71,9 +72,10 @@ 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(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct GetBlockBodies(
/// The block hashes to request bodies for.
pub Vec<B256>,
Expand All @@ -87,9 +89,10 @@ impl From<Vec<B256>> for GetBlockBodies {

/// The response to [`GetBlockBodies`], containing the block bodies that the peer knows about if
/// any were found.
#[derive_arbitrary(rlp, 16)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp, 16)]
pub struct BlockBodies(
/// The requested block bodies, each of which should correspond to a hash in the request.
pub Vec<BlockBody>,
Expand Down
20 changes: 13 additions & 7 deletions crates/net/eth-wire-types/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloy_rlp::{
};

use derive_more::{Constructor, Deref, DerefMut, From, IntoIterator};
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::{
Block, Bytes, PooledTransactionsElement, TransactionSigned, TxHash, B256, U128,
};
Expand All @@ -23,9 +23,10 @@ use proptest::{collection::vec, prelude::*};
use proptest_arbitrary_interop::arb;

/// 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(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
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 @@ -47,9 +48,10 @@ 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(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct BlockHashNumber {
/// The block hash
pub hash: B256,
Expand All @@ -73,7 +75,8 @@ impl From<NewBlockHashes> for Vec<BlockHashNumber> {
/// block.
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive_arbitrary(rlp, 25)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp, 25)]
pub struct NewBlock {
/// A new block.
pub block: Block,
Expand All @@ -83,9 +86,10 @@ pub struct NewBlock {

/// This informs peers of transactions that have appeared on the network and are not yet included
/// in a block.
#[derive_arbitrary(rlp, 10)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp, 10)]
pub struct Transactions(
/// New transactions for the peer to include in its mempool.
pub Vec<TransactionSigned>,
Expand Down Expand Up @@ -114,8 +118,9 @@ impl From<Transactions> for Vec<TransactionSigned> {
///
/// The list of transactions is constructed on per-peers basis, but the underlying transaction
/// objects are shared.
#[derive_arbitrary(rlp, 20)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp, 20)]
pub struct SharedTransactions(
/// New transactions for the peer to include in its mempool.
pub Vec<Arc<TransactionSigned>>,
Expand Down Expand Up @@ -288,9 +293,10 @@ impl From<NewPooledTransactionHashes68> for NewPooledTransactionHashes {

/// This informs peers of transaction hashes for transactions that have appeared on the network,
/// but have not been included in a block.
#[derive_arbitrary(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
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 Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire-types/src/disconnect_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

use alloy_rlp::{Decodable, Encodable, Header};
use derive_more::Display;
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::bytes::{Buf, BufMut};
use thiserror::Error;

/// RLPx disconnect reason.
#[derive_arbitrary(rlp)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Display)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub enum DisconnectReason {
/// Disconnect requested by the local node or remote peer.
#[default]
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire-types/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloy_rlp::{Decodable, Encodable};
use bytes::BufMut;
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;

/// Represents the direction for a headers request depending on the `reverse` field of the request.
/// > The response must contain a number of block headers, of rising number when reverse is 0,
Expand All @@ -14,9 +14,10 @@ use reth_codecs_derive::derive_arbitrary;
/// [`HeadersDirection::Falling`] block numbers for `reverse == 1 == true`
///
/// See also <https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getblockheaders-0x03>
#[derive_arbitrary(rlp)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub enum HeadersDirection {
/// Falling block number.
Falling,
Expand Down
8 changes: 5 additions & 3 deletions crates/net/eth-wire-types/src/receipts.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
//! Implements the `GetReceipts` and `Receipts` message types.

use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::{ReceiptWithBloom, B256};

/// 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(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct GetReceipts(
/// The block hashes to request receipts for.
pub Vec<B256>,
);

/// The response to [`GetReceipts`], containing receipt lists that correspond to each block
/// requested.
#[derive_arbitrary(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct Receipts(
/// Each receipt hash should correspond to a block hash in the request.
pub Vec<Vec<ReceiptWithBloom>>,
Expand Down
8 changes: 5 additions & 3 deletions crates/net/eth-wire-types/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
//! Implements the `GetNodeData` and `NodeData` message types.

use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::{Bytes, B256};

/// 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(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct GetNodeData(pub Vec<B256>);

/// The response to [`GetNodeData`], containing the state tree nodes or contract bytecode
/// corresponding to the requested hashes.
///
/// Not all nodes are guaranteed to be returned by the peer.
/// This message was removed in `eth/67`.
#[derive_arbitrary(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct NodeData(pub Vec<Bytes>);

#[cfg(test)]
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire-types/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloy_chains::{Chain, NamedChain};
use alloy_genesis::Genesis;
use alloy_rlp::{RlpDecodable, RlpEncodable};
use reth_chainspec::{ChainSpec, MAINNET};
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::{hex, EthereumHardfork, ForkId, Head, B256, U256};
use std::fmt::{Debug, Display};

Expand All @@ -12,9 +12,10 @@ use std::fmt::{Debug, Display};
///
/// When performing a handshake, the total difficulty is not guaranteed to correspond to the block
/// hash. This information should be treated as untrusted.
#[derive_arbitrary(rlp)]
#[derive(Copy, Clone, PartialEq, Eq, RlpEncodable, RlpDecodable)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct Status {
/// The current protocol version. For example, peers running `eth/66` would have a version of
/// 66.
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire-types/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
use derive_more::{Constructor, Deref, IntoIterator};
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::{
transaction::TransactionConversionError, PooledTransactionsElement, TransactionSigned, B256,
};

/// 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(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct GetPooledTransactions(
/// The transaction hashes to request transaction bodies for.
pub Vec<B256>,
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire-types/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{fmt, str::FromStr};
use alloy_rlp::{Decodable, Encodable, Error as RlpError};
use bytes::BufMut;
use derive_more::Display;
use reth_codecs_derive::derive_arbitrary;
use reth_codecs_derive::add_arbitrary_tests;

/// Error thrown when failed to parse a valid [`EthVersion`].
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
Expand Down Expand Up @@ -131,9 +131,10 @@ impl From<EthVersion> for &'static str {
}

/// RLPx `p2p` protocol version
#[derive_arbitrary(rlp)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub enum ProtocolVersion {
/// `p2p` version 4
V4 = 4,
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire/src/hello.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Capability, EthVersion, ProtocolVersion};
use alloy_rlp::{RlpDecodable, RlpEncodable};
use reth_codecs::derive_arbitrary;
use reth_codecs::add_arbitrary_tests;
use reth_network_peers::PeerId;
use reth_primitives::constants::RETH_CLIENT_VERSION;

Expand Down Expand Up @@ -103,9 +103,10 @@ impl HelloMessageWithProtocols {
/// supported RLPx protocol version and capabilities.
///
/// See also <https://github.com/ethereum/devp2p/blob/master/rlpx.md#hello-0x00>
#[derive_arbitrary(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct HelloMessage {
/// The version of the `p2p` protocol.
pub protocol_version: ProtocolVersion,
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire/src/p2pstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
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;
use reth_codecs::add_arbitrary_tests;
use reth_metrics::metrics::counter;
use reth_primitives::{
bytes::{Buf, BufMut, Bytes, BytesMut},
Expand Down Expand Up @@ -642,9 +642,10 @@ where
}

/// This represents only the reserved `p2p` subprotocol messages.
#[derive_arbitrary(rlp)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub enum P2PMessage {
/// The first packet sent over the connection, and sent once by both sides.
Hello(HelloMessage),
Expand Down
8 changes: 5 additions & 3 deletions crates/net/eth-wire/tests/fuzz_roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ macro_rules! fuzz_type_and_name {
pub mod fuzz_rlp {
use crate::roundtrip_encoding;
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
use reth_codecs::derive_arbitrary;
use reth_codecs::add_arbitrary_tests;
use reth_eth_wire::{
BlockBodies, BlockHeaders, DisconnectReason, GetBlockBodies, GetBlockHeaders, GetNodeData,
GetPooledTransactions, GetReceipts, HelloMessage, NewBlock, NewBlockHashes,
Expand Down Expand Up @@ -78,7 +78,6 @@ pub mod fuzz_rlp {

// see message below for why wrapper types are necessary for fuzzing types that do not have a
// Default impl
#[derive_arbitrary(rlp)]
#[derive(
Clone,
Debug,
Expand All @@ -89,6 +88,8 @@ pub mod fuzz_rlp {
RlpEncodableWrapper,
RlpDecodableWrapper,
)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
struct HelloMessageWrapper(HelloMessage);

impl Default for HelloMessageWrapper {
Expand Down Expand Up @@ -120,7 +121,6 @@ pub mod fuzz_rlp {
//
// We just provide a default value here so test-fuzz can auto-generate a corpus file for the
// type.
#[derive_arbitrary(rlp)]
#[derive(
Clone,
Debug,
Expand All @@ -131,6 +131,8 @@ pub mod fuzz_rlp {
RlpEncodableWrapper,
RlpDecodableWrapper,
)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
struct GetBlockHeadersWrapper(GetBlockHeaders);

impl Default for GetBlockHeadersWrapper {
Expand Down
7 changes: 4 additions & 3 deletions crates/primitives-traits/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use alloy_primitives::{keccak256, Bytes, B256, U256};
use byteorder::{BigEndian, ReadBytesExt};
use bytes::Buf;
use derive_more::Deref;
use reth_codecs::{reth_codec, Compact};
use reth_codecs::{add_arbitrary_tests, Compact};
use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, JumpTable};
use serde::{Deserialize, Serialize};

/// An Ethereum account.
#[reth_codec]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Serialize, Deserialize, Compact)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(compact)]
pub struct Account {
/// Account nonce.
pub nonce: u64,
Expand Down
Loading
Loading