Skip to content

Commit 330f73b

Browse files
authored
refactor: remove #[reth_codec] and #[derive_arbitrary] macros (paradigmxyz#10263)
1 parent 6eae55e commit 330f73b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+240
-206
lines changed

crates/net/eth-wire-types/src/blocks.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use crate::HeadersDirection;
55
use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
6-
use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary};
6+
use reth_codecs_derive::add_arbitrary_tests;
77
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256};
88

99
/// A request for a peer to return block headers starting at the requested block.
@@ -15,9 +15,10 @@ use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256};
1515
///
1616
/// If the [`skip`](#structfield.skip) field is non-zero, the peer must skip that amount of headers
1717
/// in the direction specified by [`reverse`](#structfield.reverse).
18-
#[derive_arbitrary(rlp)]
1918
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RlpEncodable, RlpDecodable)]
2019
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
21+
#[add_arbitrary_tests(rlp)]
2122
pub struct GetBlockHeaders {
2223
/// The block number or hash that the peer should start returning headers from.
2324
pub start_block: BlockHashOrNumber,
@@ -71,9 +72,10 @@ impl From<Vec<Header>> for BlockHeaders {
7172
}
7273

7374
/// A request for a peer to return block bodies for the given block hashes.
74-
#[derive_arbitrary(rlp)]
7575
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
7676
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
77+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
78+
#[add_arbitrary_tests(rlp)]
7779
pub struct GetBlockBodies(
7880
/// The block hashes to request bodies for.
7981
pub Vec<B256>,
@@ -87,9 +89,10 @@ impl From<Vec<B256>> for GetBlockBodies {
8789

8890
/// The response to [`GetBlockBodies`], containing the block bodies that the peer knows about if
8991
/// any were found.
90-
#[derive_arbitrary(rlp, 16)]
9192
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
9293
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
94+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
95+
#[add_arbitrary_tests(rlp, 16)]
9396
pub struct BlockBodies(
9497
/// The requested block bodies, each of which should correspond to a hash in the request.
9598
pub Vec<BlockBody>,

crates/net/eth-wire-types/src/broadcast.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloy_rlp::{
66
};
77

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

2525
/// This informs peers of new blocks that have appeared on the network.
26-
#[derive_arbitrary(rlp)]
2726
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
2827
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
28+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
29+
#[add_arbitrary_tests(rlp)]
2930
pub struct NewBlockHashes(
3031
/// New block hashes and the block number for each blockhash.
3132
/// Clients should request blocks using a [`GetBlockBodies`](crate::GetBlockBodies) message.
@@ -47,9 +48,10 @@ impl NewBlockHashes {
4748
}
4849

4950
/// A block hash _and_ a block number.
50-
#[derive_arbitrary(rlp)]
5151
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default)]
5252
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
53+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
54+
#[add_arbitrary_tests(rlp)]
5355
pub struct BlockHashNumber {
5456
/// The block hash
5557
pub hash: B256,
@@ -73,7 +75,8 @@ impl From<NewBlockHashes> for Vec<BlockHashNumber> {
7375
/// block.
7476
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default)]
7577
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
76-
#[derive_arbitrary(rlp, 25)]
78+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
79+
#[add_arbitrary_tests(rlp, 25)]
7780
pub struct NewBlock {
7881
/// A new block.
7982
pub block: Block,
@@ -83,9 +86,10 @@ pub struct NewBlock {
8386

8487
/// This informs peers of transactions that have appeared on the network and are not yet included
8588
/// in a block.
86-
#[derive_arbitrary(rlp, 10)]
8789
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
8890
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
91+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
92+
#[add_arbitrary_tests(rlp, 10)]
8993
pub struct Transactions(
9094
/// New transactions for the peer to include in its mempool.
9195
pub Vec<TransactionSigned>,
@@ -114,8 +118,9 @@ impl From<Transactions> for Vec<TransactionSigned> {
114118
///
115119
/// The list of transactions is constructed on per-peers basis, but the underlying transaction
116120
/// objects are shared.
117-
#[derive_arbitrary(rlp, 20)]
118121
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)]
122+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
123+
#[add_arbitrary_tests(rlp, 20)]
119124
pub struct SharedTransactions(
120125
/// New transactions for the peer to include in its mempool.
121126
pub Vec<Arc<TransactionSigned>>,
@@ -288,9 +293,10 @@ impl From<NewPooledTransactionHashes68> for NewPooledTransactionHashes {
288293

289294
/// This informs peers of transaction hashes for transactions that have appeared on the network,
290295
/// but have not been included in a block.
291-
#[derive_arbitrary(rlp)]
292296
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
293297
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
298+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
299+
#[add_arbitrary_tests(rlp)]
294300
pub struct NewPooledTransactionHashes66(
295301
/// Transaction hashes for new transactions that have appeared on the network.
296302
/// Clients should request the transactions with the given hashes using a

crates/net/eth-wire-types/src/disconnect_reason.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
33
use alloy_rlp::{Decodable, Encodable, Header};
44
use derive_more::Display;
5-
use reth_codecs_derive::derive_arbitrary;
5+
use reth_codecs_derive::add_arbitrary_tests;
66
use reth_primitives::bytes::{Buf, BufMut};
77
use thiserror::Error;
88

99
/// RLPx disconnect reason.
10-
#[derive_arbitrary(rlp)]
1110
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Display)]
1211
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
13+
#[add_arbitrary_tests(rlp)]
1314
pub enum DisconnectReason {
1415
/// Disconnect requested by the local node or remote peer.
1516
#[default]

crates/net/eth-wire-types/src/header.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use alloy_rlp::{Decodable, Encodable};
44
use bytes::BufMut;
5-
use reth_codecs_derive::derive_arbitrary;
5+
use reth_codecs_derive::add_arbitrary_tests;
66

77
/// Represents the direction for a headers request depending on the `reverse` field of the request.
88
/// > The response must contain a number of block headers, of rising number when reverse is 0,
@@ -14,9 +14,10 @@ use reth_codecs_derive::derive_arbitrary;
1414
/// [`HeadersDirection::Falling`] block numbers for `reverse == 1 == true`
1515
///
1616
/// See also <https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getblockheaders-0x03>
17-
#[derive_arbitrary(rlp)]
1817
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default)]
1918
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
20+
#[add_arbitrary_tests(rlp)]
2021
pub enum HeadersDirection {
2122
/// Falling block number.
2223
Falling,

crates/net/eth-wire-types/src/receipts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
//! Implements the `GetReceipts` and `Receipts` message types.
22
33
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
4-
use reth_codecs_derive::derive_arbitrary;
4+
use reth_codecs_derive::add_arbitrary_tests;
55
use reth_primitives::{ReceiptWithBloom, B256};
66

77
/// A request for transaction receipts from the given block hashes.
8-
#[derive_arbitrary(rlp)]
98
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
109
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
11+
#[add_arbitrary_tests(rlp)]
1112
pub struct GetReceipts(
1213
/// The block hashes to request receipts for.
1314
pub Vec<B256>,
1415
);
1516

1617
/// The response to [`GetReceipts`], containing receipt lists that correspond to each block
1718
/// requested.
18-
#[derive_arbitrary(rlp)]
1919
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
2020
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
22+
#[add_arbitrary_tests(rlp)]
2123
pub struct Receipts(
2224
/// Each receipt hash should correspond to a block hash in the request.
2325
pub Vec<Vec<ReceiptWithBloom>>,

crates/net/eth-wire-types/src/state.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
//! Implements the `GetNodeData` and `NodeData` message types.
22
33
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
4-
use reth_codecs_derive::derive_arbitrary;
4+
use reth_codecs_derive::add_arbitrary_tests;
55
use reth_primitives::{Bytes, B256};
66

77
/// A request for state tree nodes corresponding to the given hashes.
88
/// This message was removed in `eth/67`, only clients running `eth/66` or earlier will respond to
99
/// this message.
10-
#[derive_arbitrary(rlp)]
1110
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
1211
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
13+
#[add_arbitrary_tests(rlp)]
1314
pub struct GetNodeData(pub Vec<B256>);
1415

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

2527
#[cfg(test)]

crates/net/eth-wire-types/src/status.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use alloy_chains::{Chain, NamedChain};
33
use alloy_genesis::Genesis;
44
use alloy_rlp::{RlpDecodable, RlpEncodable};
55
use reth_chainspec::{ChainSpec, MAINNET};
6-
use reth_codecs_derive::derive_arbitrary;
6+
use reth_codecs_derive::add_arbitrary_tests;
77
use reth_primitives::{hex, EthereumHardfork, ForkId, Head, B256, U256};
88
use std::fmt::{Debug, Display};
99

@@ -12,9 +12,10 @@ use std::fmt::{Debug, Display};
1212
///
1313
/// When performing a handshake, the total difficulty is not guaranteed to correspond to the block
1414
/// hash. This information should be treated as untrusted.
15-
#[derive_arbitrary(rlp)]
1615
#[derive(Copy, Clone, PartialEq, Eq, RlpEncodable, RlpDecodable)]
1716
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
18+
#[add_arbitrary_tests(rlp)]
1819
pub struct Status {
1920
/// The current protocol version. For example, peers running `eth/66` would have a version of
2021
/// 66.

crates/net/eth-wire-types/src/transactions.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
33
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
44
use derive_more::{Constructor, Deref, IntoIterator};
5-
use reth_codecs_derive::derive_arbitrary;
5+
use reth_codecs_derive::add_arbitrary_tests;
66
use reth_primitives::{
77
transaction::TransactionConversionError, PooledTransactionsElement, TransactionSigned, B256,
88
};
99

1010
/// A list of transaction hashes that the peer would like transaction bodies for.
11-
#[derive_arbitrary(rlp)]
1211
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)]
1312
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
14+
#[add_arbitrary_tests(rlp)]
1415
pub struct GetPooledTransactions(
1516
/// The transaction hashes to request transaction bodies for.
1617
pub Vec<B256>,

crates/net/eth-wire-types/src/version.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{fmt, str::FromStr};
55
use alloy_rlp::{Decodable, Encodable, Error as RlpError};
66
use bytes::BufMut;
77
use derive_more::Display;
8-
use reth_codecs_derive::derive_arbitrary;
8+
use reth_codecs_derive::add_arbitrary_tests;
99

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

133133
/// RLPx `p2p` protocol version
134-
#[derive_arbitrary(rlp)]
135134
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
136135
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
136+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
137+
#[add_arbitrary_tests(rlp)]
137138
pub enum ProtocolVersion {
138139
/// `p2p` version 4
139140
V4 = 4,

crates/net/eth-wire/src/hello.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Capability, EthVersion, ProtocolVersion};
22
use alloy_rlp::{RlpDecodable, RlpEncodable};
3-
use reth_codecs::derive_arbitrary;
3+
use reth_codecs::add_arbitrary_tests;
44
use reth_network_peers::PeerId;
55
use reth_primitives::constants::RETH_CLIENT_VERSION;
66

@@ -103,9 +103,10 @@ impl HelloMessageWithProtocols {
103103
/// supported RLPx protocol version and capabilities.
104104
///
105105
/// See also <https://github.com/ethereum/devp2p/blob/master/rlpx.md#hello-0x00>
106-
#[derive_arbitrary(rlp)]
107106
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable)]
108107
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
108+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
109+
#[add_arbitrary_tests(rlp)]
109110
pub struct HelloMessage {
110111
/// The version of the `p2p` protocol.
111112
pub protocol_version: ProtocolVersion,

crates/net/eth-wire/src/p2pstream.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
use alloy_rlp::{Decodable, Encodable, Error as RlpError, EMPTY_LIST_CODE};
99
use futures::{Sink, SinkExt, StreamExt};
1010
use pin_project::pin_project;
11-
use reth_codecs::derive_arbitrary;
11+
use reth_codecs::add_arbitrary_tests;
1212
use reth_metrics::metrics::counter;
1313
use reth_primitives::{
1414
bytes::{Buf, BufMut, Bytes, BytesMut},
@@ -642,9 +642,10 @@ where
642642
}
643643

644644
/// This represents only the reserved `p2p` subprotocol messages.
645-
#[derive_arbitrary(rlp)]
646645
#[derive(Debug, Clone, PartialEq, Eq)]
647646
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
647+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
648+
#[add_arbitrary_tests(rlp)]
648649
pub enum P2PMessage {
649650
/// The first packet sent over the connection, and sent once by both sides.
650651
Hello(HelloMessage),

crates/net/eth-wire/tests/fuzz_roundtrip.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ macro_rules! fuzz_type_and_name {
4949
pub mod fuzz_rlp {
5050
use crate::roundtrip_encoding;
5151
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
52-
use reth_codecs::derive_arbitrary;
52+
use reth_codecs::add_arbitrary_tests;
5353
use reth_eth_wire::{
5454
BlockBodies, BlockHeaders, DisconnectReason, GetBlockBodies, GetBlockHeaders, GetNodeData,
5555
GetPooledTransactions, GetReceipts, HelloMessage, NewBlock, NewBlockHashes,
@@ -78,7 +78,6 @@ pub mod fuzz_rlp {
7878

7979
// see message below for why wrapper types are necessary for fuzzing types that do not have a
8080
// Default impl
81-
#[derive_arbitrary(rlp)]
8281
#[derive(
8382
Clone,
8483
Debug,
@@ -89,6 +88,8 @@ pub mod fuzz_rlp {
8988
RlpEncodableWrapper,
9089
RlpDecodableWrapper,
9190
)]
91+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
92+
#[add_arbitrary_tests(rlp)]
9293
struct HelloMessageWrapper(HelloMessage);
9394

9495
impl Default for HelloMessageWrapper {
@@ -120,7 +121,6 @@ pub mod fuzz_rlp {
120121
//
121122
// We just provide a default value here so test-fuzz can auto-generate a corpus file for the
122123
// type.
123-
#[derive_arbitrary(rlp)]
124124
#[derive(
125125
Clone,
126126
Debug,
@@ -131,6 +131,8 @@ pub mod fuzz_rlp {
131131
RlpEncodableWrapper,
132132
RlpDecodableWrapper,
133133
)]
134+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
135+
#[add_arbitrary_tests(rlp)]
134136
struct GetBlockHeadersWrapper(GetBlockHeaders);
135137

136138
impl Default for GetBlockHeadersWrapper {

crates/primitives-traits/src/account.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use alloy_primitives::{keccak256, Bytes, B256, U256};
44
use byteorder::{BigEndian, ReadBytesExt};
55
use bytes::Buf;
66
use derive_more::Deref;
7-
use reth_codecs::{reth_codec, Compact};
7+
use reth_codecs::{add_arbitrary_tests, Compact};
88
use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, JumpTable};
99
use serde::{Deserialize, Serialize};
1010

1111
/// An Ethereum account.
12-
#[reth_codec]
13-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
12+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Serialize, Deserialize, Compact)]
13+
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
14+
#[add_arbitrary_tests(compact)]
1415
pub struct Account {
1516
/// Account nonce.
1617
pub nonce: u64,

0 commit comments

Comments
 (0)