diff --git a/Cargo.lock b/Cargo.lock index af55d40ccfde..d9262f2136d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7051,6 +7051,7 @@ dependencies = [ "rand 0.8.5", "reth-codecs", "reth-db-models", + "reth-optimism-primitives", "reth-primitives", "reth-primitives-traits", "reth-prune-types", diff --git a/crates/optimism/primitives/Cargo.toml b/crates/optimism/primitives/Cargo.toml index 283f04a901b7..55f8eee0b2c6 100644 --- a/crates/optimism/primitives/Cargo.toml +++ b/crates/optimism/primitives/Cargo.toml @@ -23,7 +23,7 @@ alloy-primitives.workspace = true alloy-consensus.workspace = true alloy-rlp.workspace = true alloy-eips.workspace = true -revm-primitives.workspace = true +revm-primitives = { workspace = true, optional = true } secp256k1 = { workspace = true, optional = true } # op @@ -50,7 +50,7 @@ arbitrary.workspace = true proptest.workspace = true [features] -default = ["std"] +default = ["std", "serde"] std = [ "reth-primitives-traits/std", "reth-primitives/std", @@ -61,7 +61,7 @@ std = [ "serde?/std", "bytes?/std", "derive_more/std", - "revm-primitives/std", + "revm-primitives?/std", "secp256k1?/std", "alloy-rlp/std", "reth-zstd-compressors?/std", @@ -91,7 +91,7 @@ serde = [ "reth-codecs?/serde", "op-alloy-consensus/serde", "rand?/serde", - "revm-primitives/serde", + "revm-primitives?/serde", "secp256k1?/serde", ] serde-bincode-compat = [ @@ -111,10 +111,11 @@ arbitrary = [ "alloy-consensus/arbitrary", "alloy-eips/arbitrary", "alloy-primitives/arbitrary", - "revm-primitives/arbitrary", + "revm-primitives?/arbitrary", "rand", ] optimism = [ + "dep:revm-primitives", "revm-primitives/optimism", "reth-primitives/optimism" ] diff --git a/crates/optimism/primitives/src/lib.rs b/crates/optimism/primitives/src/lib.rs index b2b9e60e544f..cb955b9cf080 100644 --- a/crates/optimism/primitives/src/lib.rs +++ b/crates/optimism/primitives/src/lib.rs @@ -6,8 +6,6 @@ issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -// The `optimism` feature must be enabled to use this crate. -#![cfg(feature = "optimism")] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(feature = "std"), no_std)] diff --git a/crates/optimism/primitives/src/transaction/signed.rs b/crates/optimism/primitives/src/transaction/signed.rs index 3b28165c81c0..6f1b7f90e25f 100644 --- a/crates/optimism/primitives/src/transaction/signed.rs +++ b/crates/optimism/primitives/src/transaction/signed.rs @@ -12,7 +12,7 @@ use alloy_eips::{ eip7702::SignedAuthorization, }; use alloy_primitives::{ - keccak256, Address, Bytes, PrimitiveSignature as Signature, TxHash, TxKind, Uint, B256, U256, + keccak256, Address, Bytes, PrimitiveSignature as Signature, TxHash, TxKind, Uint, B256, }; use alloy_rlp::Header; use core::{ @@ -25,11 +25,11 @@ use once_cell::sync::OnceCell as OnceLock; use op_alloy_consensus::{OpPooledTransaction, OpTypedTransaction, TxDeposit}; #[cfg(any(test, feature = "reth-codec"))] use proptest as _; -use reth_primitives::transaction::{ - recover_signer, recover_signer_unchecked, TransactionConversionError, +use reth_primitives_traits::{ + crypto::secp256k1::{recover_signer, recover_signer_unchecked}, + transaction::error::TransactionConversionError, + InMemorySize, SignedTransaction, }; -use reth_primitives_traits::{FillTxEnv, InMemorySize, SignedTransaction}; -use revm_primitives::{AuthorizationList, OptimismFields, TxEnv}; #[cfg(feature = "std")] use std::sync::OnceLock; @@ -119,15 +119,16 @@ impl SignedTransaction for OpTransactionSigned { } } -impl FillTxEnv for OpTransactionSigned { - fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address) { +#[cfg(feature = "optimism")] +impl reth_primitives_traits::FillTxEnv for OpTransactionSigned { + fn fill_tx_env(&self, tx_env: &mut revm_primitives::TxEnv, sender: Address) { let envelope = self.encoded_2718(); tx_env.caller = sender; match &self.transaction { OpTypedTransaction::Legacy(tx) => { tx_env.gas_limit = tx.gas_limit; - tx_env.gas_price = U256::from(tx.gas_price); + tx_env.gas_price = alloy_primitives::U256::from(tx.gas_price); tx_env.gas_priority_fee = None; tx_env.transact_to = tx.to; tx_env.value = tx.value; @@ -141,7 +142,7 @@ impl FillTxEnv for OpTransactionSigned { } OpTypedTransaction::Eip2930(tx) => { tx_env.gas_limit = tx.gas_limit; - tx_env.gas_price = U256::from(tx.gas_price); + tx_env.gas_price = alloy_primitives::U256::from(tx.gas_price); tx_env.gas_priority_fee = None; tx_env.transact_to = tx.to; tx_env.value = tx.value; @@ -155,8 +156,9 @@ impl FillTxEnv for OpTransactionSigned { } OpTypedTransaction::Eip1559(tx) => { tx_env.gas_limit = tx.gas_limit; - tx_env.gas_price = U256::from(tx.max_fee_per_gas); - tx_env.gas_priority_fee = Some(U256::from(tx.max_priority_fee_per_gas)); + tx_env.gas_price = alloy_primitives::U256::from(tx.max_fee_per_gas); + tx_env.gas_priority_fee = + Some(alloy_primitives::U256::from(tx.max_priority_fee_per_gas)); tx_env.transact_to = tx.to; tx_env.value = tx.value; tx_env.data = tx.input.clone(); @@ -169,8 +171,9 @@ impl FillTxEnv for OpTransactionSigned { } OpTypedTransaction::Eip7702(tx) => { tx_env.gas_limit = tx.gas_limit; - tx_env.gas_price = U256::from(tx.max_fee_per_gas); - tx_env.gas_priority_fee = Some(U256::from(tx.max_priority_fee_per_gas)); + tx_env.gas_price = alloy_primitives::U256::from(tx.max_fee_per_gas); + tx_env.gas_priority_fee = + Some(alloy_primitives::U256::from(tx.max_priority_fee_per_gas)); tx_env.transact_to = tx.to.into(); tx_env.value = tx.value; tx_env.data = tx.input.clone(); @@ -180,12 +183,12 @@ impl FillTxEnv for OpTransactionSigned { tx_env.blob_hashes.clear(); tx_env.max_fee_per_blob_gas.take(); tx_env.authorization_list = - Some(AuthorizationList::Signed(tx.authorization_list.clone())); + Some(revm_primitives::AuthorizationList::Signed(tx.authorization_list.clone())); } OpTypedTransaction::Deposit(tx) => { tx_env.access_list.clear(); tx_env.gas_limit = tx.gas_limit; - tx_env.gas_price = U256::ZERO; + tx_env.gas_price = alloy_primitives::U256::ZERO; tx_env.gas_priority_fee = None; tx_env.transact_to = tx.to; tx_env.value = tx.value; @@ -194,7 +197,7 @@ impl FillTxEnv for OpTransactionSigned { tx_env.nonce = None; tx_env.authorization_list = None; - tx_env.optimism = OptimismFields { + tx_env.optimism = revm_primitives::OptimismFields { source_hash: Some(tx.source_hash), mint: tx.mint, is_system_transaction: Some(tx.is_system_transaction), @@ -204,7 +207,7 @@ impl FillTxEnv for OpTransactionSigned { } } - tx_env.optimism = OptimismFields { + tx_env.optimism = revm_primitives::OptimismFields { source_hash: None, mint: None, is_system_transaction: Some(false), diff --git a/crates/storage/db-api/Cargo.toml b/crates/storage/db-api/Cargo.toml index c8d748b96f5f..0fa030a8cd30 100644 --- a/crates/storage/db-api/Cargo.toml +++ b/crates/storage/db-api/Cargo.toml @@ -15,6 +15,7 @@ workspace = true # reth reth-codecs.workspace = true reth-db-models.workspace = true +reth-optimism-primitives = { workspace = true, optional = true } reth-primitives = { workspace = true, features = ["reth-codec"] } reth-primitives-traits = { workspace = true, features = ["serde", "reth-codec"] } reth-prune-types.workspace = true @@ -69,17 +70,23 @@ test-utils = [ "reth-stages-types/test-utils", ] arbitrary = [ - "reth-primitives/arbitrary", - "reth-db-models/arbitrary", - "dep:arbitrary", - "dep:proptest", - "reth-primitives-traits/arbitrary", - "reth-trie-common/arbitrary", - "alloy-primitives/arbitrary", - "parity-scale-codec/arbitrary", - "reth-codecs/arbitrary", - "reth-prune-types/arbitrary", - "reth-stages-types/arbitrary", - "alloy-consensus/arbitrary", + "reth-primitives/arbitrary", + "reth-db-models/arbitrary", + "dep:arbitrary", + "dep:proptest", + "reth-primitives-traits/arbitrary", + "reth-trie-common/arbitrary", + "alloy-primitives/arbitrary", + "parity-scale-codec/arbitrary", + "reth-codecs/arbitrary", + "reth-prune-types/arbitrary", + "reth-stages-types/arbitrary", + "alloy-consensus/arbitrary", + "reth-optimism-primitives?/arbitrary" ] -optimism = ["reth-primitives/optimism", "reth-codecs/op"] +optimism = [ + "reth-primitives/optimism", + "reth-codecs/op", + "reth-optimism-primitives?/optimism" +] +op = ["dep:reth-optimism-primitives", "reth-codecs/op"] diff --git a/crates/storage/db-api/src/models/mod.rs b/crates/storage/db-api/src/models/mod.rs index 7ded84e17208..e818a1a478d0 100644 --- a/crates/storage/db-api/src/models/mod.rs +++ b/crates/storage/db-api/src/models/mod.rs @@ -235,6 +235,14 @@ impl_compression_for_compact!( GenesisAccount ); +#[cfg(feature = "op")] +mod op { + use super::*; + use reth_optimism_primitives::{OpReceipt, OpTransactionSigned}; + + impl_compression_for_compact!(OpTransactionSigned, OpReceipt); +} + macro_rules! impl_compression_fixed_compact { ($($name:tt),+) => { $(