Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl compression traits for op primitives #13550

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::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};
Expand Down
11 changes: 6 additions & 5 deletions crates/optimism/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,7 +50,7 @@ arbitrary.workspace = true
proptest.workspace = true

[features]
default = ["std"]
default = ["std", "serde"]
Copy link
Collaborator Author

@klkvr klkvr Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed because reth-primitives enables reth-primitives-traits/serde by default, thus reth-optimism-traits does not compile unless serde is enabled :/

once we migrate to alloy block types we should be able to get rid of reth_primitives dependency and this hack

std = [
"reth-primitives-traits/std",
"reth-primitives/std",
Expand All @@ -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",
Expand Down Expand Up @@ -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 = [
Expand All @@ -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"
]
2 changes: 0 additions & 2 deletions crates/optimism/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
37 changes: 20 additions & 17 deletions crates/optimism/primitives/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions crates/storage/db-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,3 +84,4 @@ arbitrary = [
"alloy-consensus/arbitrary",
]
optimism = ["reth-primitives/optimism", "reth-codecs/op"]
op = ["dep:reth-optimism-primitives", "reth-codecs/op"]
8 changes: 8 additions & 0 deletions crates/storage/db-api/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),+) => {
$(
Expand Down
Loading