feat: impl compression traits for op primitives (#13550)

This commit is contained in:
Arsenii Kulikov
2024-12-25 11:58:48 +04:00
committed by GitHub
parent 9542573854
commit 90edbff5eb
6 changed files with 55 additions and 37 deletions

1
Cargo.lock generated
View File

@ -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",

View File

@ -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"
]

View File

@ -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)]

View File

@ -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),

View File

@ -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
@ -81,5 +82,11 @@ 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"]

View File

@ -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),+) => {
$(