From 06bfce2d5ca420551b92a19600608920967af120 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 16 Jul 2024 19:02:36 +0200 Subject: [PATCH] chore: more reth-codec cfgs (#9547) --- crates/primitives/Cargo.toml | 7 ++++--- crates/primitives/src/block.rs | 7 +++---- crates/primitives/src/transaction/eip1559.rs | 2 ++ crates/primitives/src/transaction/eip2930.rs | 2 ++ crates/primitives/src/transaction/eip4844.rs | 5 ++++- crates/primitives/src/transaction/eip7702.rs | 9 +++++++-- crates/primitives/src/transaction/legacy.rs | 6 ++++-- crates/primitives/src/transaction/pooled.rs | 3 +-- crates/primitives/src/transaction/signature.rs | 2 +- 9 files changed, 28 insertions(+), 15 deletions(-) diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 53aaeffb81..b56fc3ee7b 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -40,7 +40,7 @@ c-kzg = { workspace = true, features = ["serde"], optional = true } # misc bytes.workspace = true derive_more.workspace = true -modular-bitfield.workspace = true +modular-bitfield = { workspace = true, optional = true } once_cell.workspace = true rayon.workspace = true serde.workspace = true @@ -73,6 +73,7 @@ serde_json.workspace = true test-fuzz.workspace = true toml.workspace = true triehash = "0.8" +modular-bitfield.workspace = true sucds = "0.8.1" @@ -86,7 +87,8 @@ secp256k1.workspace = true [features] default = ["c-kzg", "alloy-compat", "std", "reth-codec"] -reth-codec = ["dep:reth-codecs", "dep:zstd"] +std = ["thiserror-no-std/std"] +reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield"] asm-keccak = ["alloy-primitives/asm-keccak"] arbitrary = [ "reth-primitives-traits/arbitrary", @@ -107,7 +109,6 @@ optimism = [ "revm-primitives/optimism", ] alloy-compat = ["reth-primitives-traits/alloy-compat", "dep:alloy-rpc-types"] -std = ["thiserror-no-std/std"] test-utils = ["reth-primitives-traits/test-utils"] [[bench]] diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 345b301666..f646449209 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -9,7 +9,6 @@ use alloy_rlp::{RlpDecodable, RlpEncodable}; use derive_more::{Deref, DerefMut}; #[cfg(any(test, feature = "arbitrary"))] use proptest::prelude::prop_compose; -use reth_codecs::{add_arbitrary_tests, derive_arbitrary}; #[cfg(any(test, feature = "arbitrary"))] pub use reth_primitives_traits::test_utils::{generate_valid_header, valid_header_strategy}; use reth_primitives_traits::Requests; @@ -31,7 +30,7 @@ prop_compose! { /// Ethereum full block. /// /// Withdrawals can be optionally included at the end of the RLP encoded message. -#[add_arbitrary_tests(rlp, 25)] +#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(rlp, 25))] #[derive( Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Deref, RlpEncodable, RlpDecodable, )] @@ -263,7 +262,7 @@ impl BlockWithSenders { /// Sealed Ethereum full block. /// /// Withdrawals can be optionally included at the end of the RLP encoded message. -#[derive_arbitrary(rlp 32)] +#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::derive_arbitrary(rlp 32))] #[derive( Debug, Clone, @@ -539,7 +538,7 @@ impl SealedBlockWithSenders { /// A response to `GetBlockBodies`, containing bodies if any bodies were found. /// /// Withdrawals can be optionally included at the end of the RLP encoded message. -#[add_arbitrary_tests(rlp, 10)] +#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(rlp, 10))] #[derive( Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, RlpEncodable, RlpDecodable, )] diff --git a/crates/primitives/src/transaction/eip1559.rs b/crates/primitives/src/transaction/eip1559.rs index 218d71d7d5..1b1fdd2481 100644 --- a/crates/primitives/src/transaction/eip1559.rs +++ b/crates/primitives/src/transaction/eip1559.rs @@ -2,6 +2,8 @@ use super::access_list::AccessList; use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; + +#[cfg(any(test, feature = "reth-codec"))] use reth_codecs::Compact; #[cfg(not(feature = "std"))] diff --git a/crates/primitives/src/transaction/eip2930.rs b/crates/primitives/src/transaction/eip2930.rs index d745082557..dc97002942 100644 --- a/crates/primitives/src/transaction/eip2930.rs +++ b/crates/primitives/src/transaction/eip2930.rs @@ -2,6 +2,8 @@ use super::access_list::AccessList; use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; + +#[cfg(any(test, feature = "reth-codec"))] use reth_codecs::Compact; #[cfg(not(feature = "std"))] diff --git a/crates/primitives/src/transaction/eip4844.rs b/crates/primitives/src/transaction/eip4844.rs index 1c9bebd123..a92c8dc928 100644 --- a/crates/primitives/src/transaction/eip4844.rs +++ b/crates/primitives/src/transaction/eip4844.rs @@ -5,7 +5,10 @@ use crate::{ }; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; -use reth_codecs::{Compact, CompactPlaceholder}; +use reth_codecs::Compact; + +/// To be used with `Option` to place or replace one bit on the bitflag struct. +pub(crate) type CompactPlaceholder = (); #[cfg(feature = "c-kzg")] use crate::kzg::KzgSettings; diff --git a/crates/primitives/src/transaction/eip7702.rs b/crates/primitives/src/transaction/eip7702.rs index 5d53e1dfe8..07f2c2e6b9 100644 --- a/crates/primitives/src/transaction/eip7702.rs +++ b/crates/primitives/src/transaction/eip7702.rs @@ -4,15 +4,20 @@ use crate::{ }; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; -use reth_codecs::{reth_codec, Compact}; #[cfg(not(feature = "std"))] use alloc::vec::Vec; +#[cfg(any(test, feature = "reth-codec"))] +use reth_codecs::Compact; + /// [EIP-7702 Set Code Transaction](https://eips.ethereum.org/EIPS/eip-7702) /// /// Set EOA account code for one transaction -#[reth_codec(no_arbitrary, add_arbitrary_tests)] +#[cfg_attr( + any(test, feature = "reth-codec"), + reth_codecs::reth_codec(no_arbitrary, add_arbitrary_tests) +)] #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct TxEip7702 { /// Added as EIP-155: Simple replay attack protection diff --git a/crates/primitives/src/transaction/legacy.rs b/crates/primitives/src/transaction/legacy.rs index 0751b0d3b8..997ba2ccd1 100644 --- a/crates/primitives/src/transaction/legacy.rs +++ b/crates/primitives/src/transaction/legacy.rs @@ -1,13 +1,15 @@ use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Encodable, Header}; use core::mem; -use reth_codecs::{reth_codec, Compact}; + +#[cfg(any(test, feature = "reth-codec"))] +use reth_codecs::Compact; #[cfg(not(feature = "std"))] use alloc::vec::Vec; /// Legacy transaction. -#[cfg_attr(any(test, feature = "reth-codec"), reth_codec)] +#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] pub struct TxLegacy { /// Added as EIP-155: Simple replay attack protection diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index 7114f131ce..ff6284d375 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -10,7 +10,6 @@ use crate::{ use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header, EMPTY_LIST_CODE}; use bytes::Buf; use derive_more::{AsRef, Deref}; -use reth_codecs::add_arbitrary_tests; use serde::{Deserialize, Serialize}; #[cfg(not(feature = "std"))] @@ -18,7 +17,7 @@ use alloc::vec::Vec; /// A response to `GetPooledTransactions`. This can include either a blob transaction, or a /// non-4844 signed transaction. -#[add_arbitrary_tests] +#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests)] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum PooledTransactionsElement { /// A legacy transaction diff --git a/crates/primitives/src/transaction/signature.rs b/crates/primitives/src/transaction/signature.rs index 73b755a139..7050d6c312 100644 --- a/crates/primitives/src/transaction/signature.rs +++ b/crates/primitives/src/transaction/signature.rs @@ -1,7 +1,6 @@ use crate::{transaction::util::secp256k1, Address, B256, U256}; use alloy_primitives::Bytes; use alloy_rlp::{Decodable, Encodable, Error as RlpError}; -use bytes::Buf; use serde::{Deserialize, Serialize}; #[cfg(test)] @@ -54,6 +53,7 @@ impl reth_codecs::Compact for Signature { } fn from_compact(mut buf: &[u8], identifier: usize) -> (Self, &[u8]) { + use bytes::Buf; assert!(buf.len() >= 64); let r = U256::from_le_slice(&buf[0..32]); let s = U256::from_le_slice(&buf[32..64]);