Skip to content

Commit

Permalink
chore: more reth-codec cfgs (paradigmxyz#9547)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 16, 2024
1 parent 458251f commit 06bfce2
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 15 deletions.
7 changes: 4 additions & 3 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand All @@ -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",
Expand All @@ -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]]
Expand Down
7 changes: 3 additions & 4 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)]
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
5 changes: 4 additions & 1 deletion crates/primitives/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompactPlaceholder>` to place or replace one bit on the bitflag struct.
pub(crate) type CompactPlaceholder = ();

#[cfg(feature = "c-kzg")]
use crate::kzg::KzgSettings;
Expand Down
9 changes: 7 additions & 2 deletions crates/primitives/src/transaction/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions crates/primitives/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ 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"))]
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
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/signature.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 06bfce2

Please sign in to comment.