From 586381127f43be48659ea7c211c3328426e98fc6 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 25 Dec 2024 00:48:37 +0400 Subject: [PATCH 1/4] feat: impl compression traits for op primitives --- Cargo.lock | 1 + crates/optimism/node/src/node.rs | 2 +- crates/optimism/primitives/Cargo.toml | 9 +++--- crates/optimism/primitives/src/lib.rs | 2 -- .../primitives/src/transaction/signed.rs | 32 ++++++++++--------- crates/storage/db-api/Cargo.toml | 2 ++ crates/storage/db-api/src/models/mod.rs | 8 +++++ 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8411837417a..1e260caeb89d 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/node/src/node.rs b/crates/optimism/node/src/node.rs index f0db0fae4e22..bdaef8d70c9f 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -9,7 +9,7 @@ use crate::{ use alloy_consensus::Header; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks}; -use reth_db::transaction::{DbTx, DbTxMut}; +use reth_db::{table::{Compress, Decompress}, transaction::{DbTx, DbTxMut}}; use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, NetworkPrimitives, PeersInfo}; use reth_node_api::{AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, TxTy}; diff --git a/crates/optimism/primitives/Cargo.toml b/crates/optimism/primitives/Cargo.toml index 283f04a901b7..16f5417585d1 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 @@ -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..990bd23db141 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::{ @@ -28,8 +28,7 @@ use proptest as _; use reth_primitives::transaction::{ recover_signer, recover_signer_unchecked, TransactionConversionError, }; -use reth_primitives_traits::{FillTxEnv, InMemorySize, SignedTransaction}; -use revm_primitives::{AuthorizationList, OptimismFields, TxEnv}; +use reth_primitives_traits::{InMemorySize, SignedTransaction}; #[cfg(feature = "std")] use std::sync::OnceLock; @@ -119,15 +118,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 +141,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 +155,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 +170,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 +182,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 +196,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 +206,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..27622c931b54 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 @@ -83,3 +84,4 @@ arbitrary = [ "alloy-consensus/arbitrary", ] optimism = ["reth-primitives/optimism", "reth-codecs/op"] +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),+) => { $( From 1b6a552e1e9d90d70dffe76ee3aa7d85075383d2 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 25 Dec 2024 01:08:25 +0400 Subject: [PATCH 2/4] fix --- crates/optimism/node/src/node.rs | 5 ++++- crates/optimism/primitives/Cargo.toml | 2 +- crates/optimism/primitives/src/transaction/signed.rs | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index bdaef8d70c9f..ea03d76e91ee 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -9,7 +9,10 @@ use crate::{ use alloy_consensus::Header; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks}; -use reth_db::{table::{Compress, Decompress}, transaction::{DbTx, DbTxMut}}; +use reth_db::{ + table::{Compress, Decompress}, + transaction::{DbTx, DbTxMut}, +}; use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, NetworkPrimitives, PeersInfo}; use reth_node_api::{AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, TxTy}; diff --git a/crates/optimism/primitives/Cargo.toml b/crates/optimism/primitives/Cargo.toml index 16f5417585d1..55f8eee0b2c6 100644 --- a/crates/optimism/primitives/Cargo.toml +++ b/crates/optimism/primitives/Cargo.toml @@ -50,7 +50,7 @@ arbitrary.workspace = true proptest.workspace = true [features] -default = ["std"] +default = ["std", "serde"] std = [ "reth-primitives-traits/std", "reth-primitives/std", diff --git a/crates/optimism/primitives/src/transaction/signed.rs b/crates/optimism/primitives/src/transaction/signed.rs index 990bd23db141..6f1b7f90e25f 100644 --- a/crates/optimism/primitives/src/transaction/signed.rs +++ b/crates/optimism/primitives/src/transaction/signed.rs @@ -25,10 +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::{InMemorySize, SignedTransaction}; #[cfg(feature = "std")] use std::sync::OnceLock; From 536f0db3d7060a1a486bca69e20810a7932af93e Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 25 Dec 2024 01:11:28 +0400 Subject: [PATCH 3/4] fix --- crates/optimism/node/src/node.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index ea03d76e91ee..f0db0fae4e22 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -9,10 +9,7 @@ use crate::{ use alloy_consensus::Header; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks}; -use reth_db::{ - table::{Compress, Decompress}, - transaction::{DbTx, DbTxMut}, -}; +use reth_db::transaction::{DbTx, DbTxMut}; use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, NetworkPrimitives, PeersInfo}; use reth_node_api::{AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, TxTy}; From 1d4b387dbba219779767ff9f69856d01a33b8bf8 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 25 Dec 2024 01:16:07 +0400 Subject: [PATCH 4/4] fix --- crates/storage/db-api/Cargo.toml | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/storage/db-api/Cargo.toml b/crates/storage/db-api/Cargo.toml index 27622c931b54..0fa030a8cd30 100644 --- a/crates/storage/db-api/Cargo.toml +++ b/crates/storage/db-api/Cargo.toml @@ -70,18 +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", + "reth-optimism-primitives?/optimism" ] -optimism = ["reth-primitives/optimism", "reth-codecs/op"] op = ["dep:reth-optimism-primitives", "reth-codecs/op"]