Skip to content

Commit

Permalink
feat: impl compression traits for op primitives (#13550)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Dec 25, 2024
1 parent 9542573 commit 90edbff
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 37 deletions.
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.

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"]
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
33 changes: 20 additions & 13 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 @@ -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"]
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

0 comments on commit 90edbff

Please sign in to comment.