diff --git a/Cargo.lock b/Cargo.lock index b32dac9ad8..5924e37bb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8998,19 +8998,13 @@ version = "1.3.9" dependencies = [ "alloy-consensus", "alloy-eips", - "alloy-evm", - "alloy-network", "alloy-primitives 1.0.0", "alloy-rlp", - "alloy-rpc-types-eth", - "alloy-serde", "arbitrary", "bincode 1.3.3", "bytes", - "derive_more", "modular-bitfield", "op-alloy-consensus", - "op-revm", "proptest", "proptest-arbitrary-interop", "rand 0.8.5", @@ -9018,7 +9012,6 @@ dependencies = [ "reth-codecs", "reth-primitives-traits", "reth-zstd-compressors", - "revm-context", "rstest", "secp256k1", "serde", diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 09c05cd4de..3ac88f9336 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -23,9 +23,9 @@ impl OpExecutorProvider { mod tests { use super::*; use crate::OpChainSpec; - use alloy_consensus::{Block, BlockBody, Header, TxEip1559}; + use alloy_consensus::{Block, BlockBody, Header, SignableTransaction, TxEip1559}; use alloy_primitives::{b256, Address, Signature, StorageKey, StorageValue, U256}; - use op_alloy_consensus::{OpTypedTransaction, TxDeposit}; + use op_alloy_consensus::TxDeposit; use op_revm::constants::L1_BLOCK_CONTRACT; use reth_chainspec::MIN_TRANSACTION_GAS; use reth_evm::execute::{BasicBlockExecutorProvider, BlockExecutorProvider, Executor}; @@ -90,26 +90,23 @@ mod tests { let chain_spec = Arc::new(OpChainSpecBuilder::base_mainnet().regolith_activated().build()); - let tx = OpTransactionSigned::new_unhashed( - OpTypedTransaction::Eip1559(TxEip1559 { - chain_id: chain_spec.chain.id(), - nonce: 0, - gas_limit: MIN_TRANSACTION_GAS, - to: addr.into(), - ..Default::default() - }), - Signature::test_signature(), - ); + let tx: OpTransactionSigned = TxEip1559 { + chain_id: chain_spec.chain.id(), + nonce: 0, + gas_limit: MIN_TRANSACTION_GAS, + to: addr.into(), + ..Default::default() + } + .into_signed(Signature::test_signature()) + .into(); - let tx_deposit = OpTransactionSigned::new_unhashed( - OpTypedTransaction::Deposit(op_alloy_consensus::TxDeposit { - from: addr, - to: addr.into(), - gas_limit: MIN_TRANSACTION_GAS, - ..Default::default() - }), - Signature::test_signature(), - ); + let tx_deposit: OpTransactionSigned = TxDeposit { + from: addr, + to: addr.into(), + gas_limit: MIN_TRANSACTION_GAS, + ..Default::default() + } + .into(); let provider = executor_provider(chain_spec); let mut executor = provider.executor(StateProviderDatabase::new(&db)); @@ -166,26 +163,23 @@ mod tests { let chain_spec = Arc::new(OpChainSpecBuilder::base_mainnet().canyon_activated().build()); - let tx = OpTransactionSigned::new_unhashed( - OpTypedTransaction::Eip1559(TxEip1559 { - chain_id: chain_spec.chain.id(), - nonce: 0, - gas_limit: MIN_TRANSACTION_GAS, - to: addr.into(), - ..Default::default() - }), - Signature::test_signature(), - ); + let tx: OpTransactionSigned = TxEip1559 { + chain_id: chain_spec.chain.id(), + nonce: 0, + gas_limit: MIN_TRANSACTION_GAS, + to: addr.into(), + ..Default::default() + } + .into_signed(Signature::test_signature()) + .into(); - let tx_deposit = OpTransactionSigned::new_unhashed( - OpTypedTransaction::Deposit(op_alloy_consensus::TxDeposit { - from: addr, - to: addr.into(), - gas_limit: MIN_TRANSACTION_GAS, - ..Default::default() - }), - TxDeposit::signature(), - ); + let tx_deposit: OpTransactionSigned = TxDeposit { + from: addr, + to: addr.into(), + gas_limit: MIN_TRANSACTION_GAS, + ..Default::default() + } + .into(); let provider = executor_provider(chain_spec); let mut executor = provider.executor(StateProviderDatabase::new(&db)); diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index ee23a82e97..78bd12d12a 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -215,7 +215,7 @@ where reth_optimism_primitives::OpBlock { header: header.inner, body: reth_optimism_primitives::OpBlockBody { - transactions: transactions.into_transactions().map(Into::into).collect(), + transactions: transactions.into_transactions().collect(), ..Default::default() }, } diff --git a/crates/optimism/node/tests/it/priority.rs b/crates/optimism/node/tests/it/priority.rs index 3fea88b196..5bc03144d8 100644 --- a/crates/optimism/node/tests/it/priority.rs +++ b/crates/optimism/node/tests/it/priority.rs @@ -1,10 +1,9 @@ //! Node builder test that customizes priority of transactions in the block. -use alloy_consensus::{transaction::Recovered, SignableTransaction, TxEip1559}; +use alloy_consensus::{transaction::Recovered, SignableTransaction, Transaction, TxEip1559}; use alloy_genesis::Genesis; use alloy_network::TxSignerSync; use alloy_primitives::{Address, ChainId, TxKind}; -use op_alloy_consensus::OpTypedTransaction; use reth_chainspec::EthChainSpec; use reth_db::test_utils::create_test_rw_db_with_path; use reth_e2e_test_utils::{ @@ -192,10 +191,10 @@ async fn test_custom_block_priority_config() { // Check that last transaction in the block looks like a transfer to a random address. let end_of_block_tx = block_payload.body().transactions.last().unwrap(); - let OpTypedTransaction::Eip1559(end_of_block_tx) = end_of_block_tx.transaction() else { + let Some(tx) = end_of_block_tx.as_eip1559() else { panic!("expected EIP-1559 transaction"); }; - assert_eq!(end_of_block_tx.nonce, 1); - assert_eq!(end_of_block_tx.gas_limit, 21_000); - assert!(end_of_block_tx.input.is_empty()); + assert_eq!(tx.tx().nonce(), 1); + assert_eq!(tx.tx().gas_limit(), 21_000); + assert!(tx.tx().input().is_empty()); } diff --git a/crates/optimism/primitives/Cargo.toml b/crates/optimism/primitives/Cargo.toml index 7850547e74..77136bd6dc 100644 --- a/crates/optimism/primitives/Cargo.toml +++ b/crates/optimism/primitives/Cargo.toml @@ -18,20 +18,12 @@ reth-codecs = { workspace = true, optional = true, features = ["op"] } reth-zstd-compressors = { workspace = true, optional = true } # ethereum -alloy-evm.workspace = true alloy-primitives.workspace = true alloy-consensus.workspace = true alloy-rlp.workspace = true -alloy-eips = { workspace = true, features = ["k256"] } -revm-context.workspace = true -op-revm.workspace = true -secp256k1 = { workspace = true, optional = true } # op op-alloy-consensus.workspace = true -alloy-rpc-types-eth = { workspace = true, optional = true } -alloy-network = { workspace = true, optional = true } -alloy-serde = { workspace = true, optional = true } # codec bytes = { workspace = true, optional = true } @@ -39,54 +31,45 @@ modular-bitfield = { workspace = true, optional = true } serde = { workspace = true, optional = true } serde_with = { workspace = true, optional = true } -# misc -derive_more = { workspace = true, features = ["deref", "from", "into", "constructor"] } -rand_08 = { workspace = true, optional = true } - # test arbitrary = { workspace = true, features = ["derive"], optional = true } -proptest = { workspace = true, optional = true } [dev-dependencies] -arbitrary.workspace = true -proptest-arbitrary-interop.workspace = true -proptest.workspace = true -rand.workspace = true -rand_08.workspace = true reth-codecs = { workspace = true, features = ["test-utils", "op"] } +alloy-eips.workspace = true + +rand.workspace = true +arbitrary.workspace = true rstest.workspace = true -secp256k1 = { workspace = true, features = ["rand"] } serde_json.workspace = true bincode.workspace = true +proptest-arbitrary-interop.workspace = true +proptest.workspace = true +rand_08.workspace = true +secp256k1 = { workspace = true, features = ["rand"] } + [features] default = ["std"] std = [ "reth-primitives-traits/std", "reth-codecs?/std", "alloy-consensus/std", - "alloy-eips/std", "alloy-primitives/std", "serde?/std", "bytes?/std", - "derive_more/std", - "secp256k1?/std", "alloy-rlp/std", "reth-zstd-compressors?/std", "op-alloy-consensus/std", - "op-revm/std", - "alloy-rpc-types-eth?/std", - "alloy-serde?/std", - "revm-context/std", "serde_json/std", - "alloy-evm/std", "serde_with?/std", + "alloy-eips/std", + "secp256k1/std", ] -alloy-compat = ["dep:alloy-network", "dep:alloy-serde", "dep:alloy-rpc-types-eth", "op-alloy-consensus/alloy-compat"] +alloy-compat = ["op-alloy-consensus/alloy-compat"] reth-codec = [ "dep:reth-codecs", "std", - "dep:proptest", "reth-primitives-traits/reth-codec", "reth-codecs?/op", "dep:bytes", @@ -98,37 +81,29 @@ serde = [ "reth-primitives-traits/serde", "alloy-primitives/serde", "alloy-consensus/serde", - "alloy-eips/serde", "bytes?/serde", "reth-codecs?/serde", "op-alloy-consensus/serde", - "rand_08?/serde", - "secp256k1?/serde", - "op-revm/serde", - "alloy-rpc-types-eth?/serde", - "revm-context/serde", + "alloy-eips/serde", "rand/serde", + "rand_08/serde", + "secp256k1/serde", ] serde-bincode-compat = [ "serde", "serde_with", "alloy-consensus/serde-bincode-compat", - "alloy-eips/serde-bincode-compat", "op-alloy-consensus/serde-bincode-compat", "reth-primitives-traits/serde-bincode-compat", + "alloy-eips/serde-bincode-compat", ] arbitrary = [ "std", "dep:arbitrary", - "dep:secp256k1", - "secp256k1?/rand", "reth-primitives-traits/arbitrary", "reth-codecs?/arbitrary", "op-alloy-consensus/arbitrary", "alloy-consensus/arbitrary", - "alloy-eips/arbitrary", "alloy-primitives/arbitrary", - "rand_08", - "alloy-rpc-types-eth?/arbitrary", - "alloy-serde?/arbitrary", + "alloy-eips/arbitrary", ] diff --git a/crates/optimism/primitives/src/alloy_compat.rs b/crates/optimism/primitives/src/alloy_compat.rs deleted file mode 100644 index 70f310c9d5..0000000000 --- a/crates/optimism/primitives/src/alloy_compat.rs +++ /dev/null @@ -1,91 +0,0 @@ -//! Common conversions from alloy types. - -use crate::OpTransactionSigned; -use alloy_consensus::TxEnvelope; -use alloy_network::{AnyRpcTransaction, AnyTxEnvelope}; -use alloy_rpc_types_eth::{ConversionError, Transaction as AlloyRpcTransaction}; -use alloy_serde::WithOtherFields; -use op_alloy_consensus::{OpTypedTransaction, TxDeposit}; - -impl TryFrom for OpTransactionSigned { - type Error = ConversionError; - - fn try_from(tx: AnyRpcTransaction) -> Result { - let WithOtherFields { inner: AlloyRpcTransaction { inner, .. }, other: _ } = tx.0; - let from = inner.signer(); - - let (transaction, signature, hash) = match inner.into_inner() { - AnyTxEnvelope::Ethereum(TxEnvelope::Legacy(tx)) => { - let (tx, signature, hash) = tx.into_parts(); - (OpTypedTransaction::Legacy(tx), signature, hash) - } - AnyTxEnvelope::Ethereum(TxEnvelope::Eip2930(tx)) => { - let (tx, signature, hash) = tx.into_parts(); - (OpTypedTransaction::Eip2930(tx), signature, hash) - } - AnyTxEnvelope::Ethereum(TxEnvelope::Eip1559(tx)) => { - let (tx, signature, hash) = tx.into_parts(); - (OpTypedTransaction::Eip1559(tx), signature, hash) - } - AnyTxEnvelope::Ethereum(TxEnvelope::Eip7702(tx)) => { - let (tx, signature, hash) = tx.into_parts(); - (OpTypedTransaction::Eip7702(tx), signature, hash) - } - AnyTxEnvelope::Unknown(mut tx) => { - // Re-insert `from` field which was consumed by outer `Transaction`. - // Ref hack in op-alloy - tx.inner - .fields - .insert_value("from".to_string(), from) - .map_err(|err| ConversionError::Custom(err.to_string()))?; - let hash = tx.hash; - (OpTypedTransaction::Deposit(tx.try_into()?), TxDeposit::signature(), hash) - } - _ => return Err(ConversionError::Custom("unknown transaction type".to_string())), - }; - - Ok(Self::new(transaction, signature, hash)) - } -} - -impl From> for OpTransactionSigned -where - Self: From, -{ - fn from(value: AlloyRpcTransaction) -> Self { - value.inner.into_inner().into() - } -} - -#[cfg(test)] -mod tests { - use alloy_network::AnyRpcTransaction; - - use crate::OpTransactionSigned; - - #[test] - fn test_tx_deposit() { - let json = r#"{ - "hash": "0x3f44a72b1faf70be7295183f1f30cfb51ede92d7c44441ca80c9437a6a22e5a5", - "type": "0x7e", - "depositReceiptVersion": "0x1", - "gas": "0x77f2e", - "gasPrice": "0x0", - "input": "0xd764ad0b000100000000000000000000000000000000000000000000000000000005dacf0000000000000000000000003154cf16ccdb4c6d922629664174b904d80f2c3500000000000000000000000042000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001c6bf526340000000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c41635f5fd000000000000000000000000212241ad6a6a0a7553c4290f7bc517c1041df0be000000000000000000000000d153f571d0a5a07133114bfe623d4d71e03ea5d70000000000000000000000000000000000000000000000000001c6bf5263400000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000018307837333735373036353732363237323639363436373635000000000000000000000000000000000000000000000000000000000000000000000000", - "mint": "0x1c6bf52634000", - "nonce": "0x5dacf", - "r": "0x0", - "s": "0x0", - "sourceHash": "0x26eb0df3ebdb8eb11892a336b798948ec846c28200862a67aa32cfd57ca7da4f", - "to": "0x4200000000000000000000000000000000000007", - "v": "0x0", - "value": "0x1c6bf52634000", - "blockHash": "0x0d7f8b9def6f5d3ba2cbeee2e31e730da81e2c474fa8c3c9e8d0e6b96e37d182", - "blockNumber": "0x1966297", - "transactionIndex": "0x1", - "from": "0x977f82a600a1414e583f7f13623f1ac5d58b1c0b" - }"#; - let tx: AnyRpcTransaction = serde_json::from_str(json).unwrap(); - OpTransactionSigned::try_from(tx).unwrap(); - } -} diff --git a/crates/optimism/primitives/src/lib.rs b/crates/optimism/primitives/src/lib.rs index dd367f9fa0..8a447ffc2f 100644 --- a/crates/optimism/primitives/src/lib.rs +++ b/crates/optimism/primitives/src/lib.rs @@ -8,19 +8,16 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(feature = "std"), no_std)] - +#![allow(unused)] extern crate alloc; -#[cfg(feature = "alloy-compat")] -mod alloy_compat; - pub mod bedrock; pub mod predeploys; pub use predeploys::ADDRESS_L2_TO_L1_MESSAGE_PASSER; pub mod transaction; -pub use transaction::{signed::OpTransactionSigned, tx_type::OpTxType}; +pub use transaction::*; mod receipt; pub use receipt::{DepositReceipt, OpReceipt}; @@ -47,7 +44,6 @@ impl reth_primitives_traits::NodePrimitives for OpPrimitives { /// Bincode-compatible serde implementations. #[cfg(feature = "serde-bincode-compat")] pub mod serde_bincode_compat { - pub use super::{ - receipt::serde_bincode_compat::*, transaction::signed::serde_bincode_compat::*, - }; + pub use super::receipt::serde_bincode_compat::*; + pub use op_alloy_consensus::serde_bincode_compat::*; } diff --git a/crates/optimism/primitives/src/transaction/mod.rs b/crates/optimism/primitives/src/transaction/mod.rs index 0d048d056d..9ccc0808f8 100644 --- a/crates/optimism/primitives/src/transaction/mod.rs +++ b/crates/optimism/primitives/src/transaction/mod.rs @@ -1,7 +1,15 @@ //! Optimism transaction types -pub mod signed; -pub mod tx_type; +mod tx_type; + +/// Kept for concistency tests +#[cfg(test)] +mod signed; + +pub use op_alloy_consensus::OpTxType; + +/// Signed transaction. +pub type OpTransactionSigned = op_alloy_consensus::OpTxEnvelope; /// A trait that represents an optimism transaction, mainly used to indicate whether or not the /// transaction is a deposit transaction. diff --git a/crates/optimism/primitives/src/transaction/signed.rs b/crates/optimism/primitives/src/transaction/signed.rs index 1933041d2f..c8b697209a 100644 --- a/crates/optimism/primitives/src/transaction/signed.rs +++ b/crates/optimism/primitives/src/transaction/signed.rs @@ -1,4 +1,5 @@ -//! A signed Optimism transaction. +//! This file contains the legacy reth `OpTransactionSigned` type that has been replaced with +//! op-alloy's OpTransactionSigned To test for consistency this is kept use crate::transaction::OpTransaction; use alloc::vec::Vec; @@ -12,7 +13,6 @@ use alloy_eips::{ eip2930::AccessList, eip7702::SignedAuthorization, }; -use alloy_evm::{FromRecoveredTx, FromTxWithEncoded}; use alloy_primitives::{keccak256, Address, Bytes, Signature, TxHash, TxKind, Uint, B256}; use alloy_rlp::Header; use core::{ @@ -20,23 +20,19 @@ use core::{ mem, ops::Deref, }; -use derive_more::{AsRef, Deref}; use op_alloy_consensus::{OpPooledTransaction, OpTxEnvelope, OpTypedTransaction, TxDeposit}; -use op_revm::transaction::deposit::DepositTransactionParts; #[cfg(any(test, feature = "reth-codec"))] -use proptest as _; use reth_primitives_traits::{ crypto::secp256k1::{recover_signer, recover_signer_unchecked}, sync::OnceLock, transaction::{error::TransactionConversionError, signed::RecoveryError}, InMemorySize, SignedTransaction, }; -use revm_context::TxEnv; /// Signed transaction. #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(rlp))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone, Eq, AsRef, Deref)] +#[derive(Debug, Clone, Eq)] pub struct OpTransactionSigned { /// Transaction hash #[cfg_attr(feature = "serde", serde(skip))] @@ -44,11 +40,16 @@ pub struct OpTransactionSigned { /// The transaction signature values signature: Signature, /// Raw transaction info - #[deref] - #[as_ref] transaction: OpTypedTransaction, } +impl Deref for OpTransactionSigned { + type Target = OpTypedTransaction; + fn deref(&self) -> &Self::Target { + &self.transaction + } +} + impl OpTransactionSigned { /// Creates a new signed transaction from the given transaction, signature and hash. pub fn new(transaction: OpTypedTransaction, signature: Signature, hash: B256) -> Self { @@ -168,6 +169,13 @@ impl From for OpTransactionSigned { } } +impl From> for OpTransactionSigned { + fn from(value: Sealed) -> Self { + let (tx, hash) = value.into_parts(); + Self::new(OpTypedTransaction::Deposit(tx), TxDeposit::signature(), hash) + } +} + impl From for OpTxEnvelope { fn from(value: OpTransactionSigned) -> Self { let (tx, signature, hash) = value.into_parts(); @@ -181,177 +189,6 @@ impl From for OpTxEnvelope { } } -impl From for Signed { - fn from(value: OpTransactionSigned) -> Self { - let (tx, sig, hash) = value.into_parts(); - Self::new_unchecked(tx, sig, hash) - } -} - -impl From> for OpTransactionSigned { - fn from(value: Sealed) -> Self { - let (tx, hash) = value.into_parts(); - Self::new(OpTypedTransaction::Deposit(tx), TxDeposit::signature(), hash) - } -} - -impl OpTransaction for OpTransactionSigned { - fn is_deposit(&self) -> bool { - self.is_deposit() - } -} - -impl FromRecoveredTx for op_revm::OpTransaction { - fn from_recovered_tx(tx: &OpTransactionSigned, sender: Address) -> Self { - let envelope = tx.encoded_2718(); - - let base = match &tx.transaction { - OpTypedTransaction::Legacy(tx) => TxEnv { - gas_limit: tx.gas_limit, - gas_price: tx.gas_price, - gas_priority_fee: None, - kind: tx.to, - value: tx.value, - data: tx.input.clone(), - chain_id: tx.chain_id, - nonce: tx.nonce, - access_list: Default::default(), - blob_hashes: Default::default(), - max_fee_per_blob_gas: Default::default(), - authorization_list: Default::default(), - tx_type: 0, - caller: sender, - }, - OpTypedTransaction::Eip2930(tx) => TxEnv { - gas_limit: tx.gas_limit, - gas_price: tx.gas_price, - gas_priority_fee: None, - kind: tx.to, - value: tx.value, - data: tx.input.clone(), - chain_id: Some(tx.chain_id), - nonce: tx.nonce, - access_list: tx.access_list.clone(), - blob_hashes: Default::default(), - max_fee_per_blob_gas: Default::default(), - authorization_list: Default::default(), - tx_type: 1, - caller: sender, - }, - OpTypedTransaction::Eip1559(tx) => TxEnv { - gas_limit: tx.gas_limit, - gas_price: tx.max_fee_per_gas, - gas_priority_fee: Some(tx.max_priority_fee_per_gas), - kind: tx.to, - value: tx.value, - data: tx.input.clone(), - chain_id: Some(tx.chain_id), - nonce: tx.nonce, - access_list: tx.access_list.clone(), - blob_hashes: Default::default(), - max_fee_per_blob_gas: Default::default(), - authorization_list: Default::default(), - tx_type: 2, - caller: sender, - }, - OpTypedTransaction::Eip7702(tx) => TxEnv { - gas_limit: tx.gas_limit, - gas_price: tx.max_fee_per_gas, - gas_priority_fee: Some(tx.max_priority_fee_per_gas), - kind: TxKind::Call(tx.to), - value: tx.value, - data: tx.input.clone(), - chain_id: Some(tx.chain_id), - nonce: tx.nonce, - access_list: tx.access_list.clone(), - blob_hashes: Default::default(), - max_fee_per_blob_gas: Default::default(), - authorization_list: tx.authorization_list.clone(), - tx_type: 4, - caller: sender, - }, - OpTypedTransaction::Deposit(tx) => TxEnv { - gas_limit: tx.gas_limit, - gas_price: 0, - kind: tx.to, - value: tx.value, - data: tx.input.clone(), - chain_id: None, - nonce: 0, - access_list: Default::default(), - blob_hashes: Default::default(), - max_fee_per_blob_gas: Default::default(), - authorization_list: Default::default(), - gas_priority_fee: Default::default(), - tx_type: 126, - caller: sender, - }, - }; - - Self { - base, - enveloped_tx: Some(envelope.into()), - deposit: if let OpTypedTransaction::Deposit(tx) = &tx.transaction { - DepositTransactionParts { - is_system_transaction: tx.is_system_transaction, - source_hash: tx.source_hash, - // For consistency with op-geth, we always return `0x0` for mint if it is - // missing This is because op-geth does not distinguish - // between null and 0, because this value is decoded from RLP where null is - // represented as 0 - mint: Some(tx.mint.unwrap_or_default()), - } - } else { - Default::default() - }, - } - } -} - -impl FromTxWithEncoded for op_revm::OpTransaction { - fn from_encoded_tx(tx: &OpTransactionSigned, caller: Address, encoded: Bytes) -> Self { - let base = match &tx.transaction { - OpTypedTransaction::Legacy(tx) => TxEnv::from_recovered_tx(tx, caller), - OpTypedTransaction::Eip1559(tx) => TxEnv::from_recovered_tx(tx, caller), - OpTypedTransaction::Eip2930(tx) => TxEnv::from_recovered_tx(tx, caller), - OpTypedTransaction::Eip7702(tx) => TxEnv::from_recovered_tx(tx, caller), - OpTypedTransaction::Deposit(tx) => { - let TxDeposit { - to, - value, - gas_limit, - input, - source_hash: _, - from: _, - mint: _, - is_system_transaction: _, - } = tx; - TxEnv { - tx_type: tx.ty(), - caller, - gas_limit: *gas_limit, - kind: *to, - value: *value, - data: input.clone(), - ..Default::default() - } - } - }; - - let deposit = if let OpTypedTransaction::Deposit(tx) = &tx.transaction { - DepositTransactionParts { - source_hash: tx.source_hash, - mint: tx.mint, - is_system_transaction: tx.is_system_transaction, - } - } else { - Default::default() - }; - - Self { base, enveloped_tx: Some(encoded), deposit } - } -} - impl InMemorySize for OpTransactionSigned { #[inline] fn size(&self) -> usize { @@ -664,7 +501,7 @@ impl<'a> arbitrary::Arbitrary<'a> for OpTransactionSigned { } } - let signature = if is_deposit(&transaction) { TxDeposit::signature() } else { signature }; + let signature = if transaction.is_deposit() { TxDeposit::signature() } else { signature }; Ok(Self::new_unhashed(transaction, signature)) } @@ -681,134 +518,6 @@ fn signature_hash(tx: &OpTypedTransaction) -> B256 { } } -/// Returns `true` if transaction is deposit transaction. -pub const fn is_deposit(tx: &OpTypedTransaction) -> bool { - matches!(tx, OpTypedTransaction::Deposit(_)) -} - -impl From for OpTransactionSigned { - fn from(value: OpPooledTransaction) -> Self { - match value { - OpPooledTransaction::Legacy(tx) => tx.into(), - OpPooledTransaction::Eip2930(tx) => tx.into(), - OpPooledTransaction::Eip1559(tx) => tx.into(), - OpPooledTransaction::Eip7702(tx) => tx.into(), - } - } -} - -impl TryFrom for OpPooledTransaction { - type Error = TransactionConversionError; - - fn try_from(value: OpTransactionSigned) -> Result { - let hash = *value.tx_hash(); - let OpTransactionSigned { hash: _, signature, transaction } = value; - - match transaction { - OpTypedTransaction::Legacy(tx) => { - Ok(Self::Legacy(Signed::new_unchecked(tx, signature, hash))) - } - OpTypedTransaction::Eip2930(tx) => { - Ok(Self::Eip2930(Signed::new_unchecked(tx, signature, hash))) - } - OpTypedTransaction::Eip1559(tx) => { - Ok(Self::Eip1559(Signed::new_unchecked(tx, signature, hash))) - } - OpTypedTransaction::Eip7702(tx) => { - Ok(Self::Eip7702(Signed::new_unchecked(tx, signature, hash))) - } - OpTypedTransaction::Deposit(_) => Err(TransactionConversionError::UnsupportedForP2P), - } - } -} - -/// Bincode-compatible transaction type serde implementations. -#[cfg(feature = "serde-bincode-compat")] -pub mod serde_bincode_compat { - use alloy_consensus::transaction::serde_bincode_compat::{ - TxEip1559, TxEip2930, TxEip7702, TxLegacy, - }; - use alloy_primitives::{Signature, TxHash}; - use reth_primitives_traits::{serde_bincode_compat::SerdeBincodeCompat, SignedTransaction}; - use serde::{Deserialize, Serialize}; - - /// Bincode-compatible [`super::OpTypedTransaction`] serde implementation. - #[derive(Debug, Serialize, Deserialize)] - enum OpTypedTransaction<'a> { - Legacy(TxLegacy<'a>), - Eip2930(TxEip2930<'a>), - Eip1559(TxEip1559<'a>), - Eip7702(TxEip7702<'a>), - Deposit(op_alloy_consensus::serde_bincode_compat::TxDeposit<'a>), - } - - impl<'a> From<&'a super::OpTypedTransaction> for OpTypedTransaction<'a> { - fn from(value: &'a super::OpTypedTransaction) -> Self { - match value { - super::OpTypedTransaction::Legacy(tx) => Self::Legacy(TxLegacy::from(tx)), - super::OpTypedTransaction::Eip2930(tx) => Self::Eip2930(TxEip2930::from(tx)), - super::OpTypedTransaction::Eip1559(tx) => Self::Eip1559(TxEip1559::from(tx)), - super::OpTypedTransaction::Eip7702(tx) => Self::Eip7702(TxEip7702::from(tx)), - super::OpTypedTransaction::Deposit(tx) => { - Self::Deposit(op_alloy_consensus::serde_bincode_compat::TxDeposit::from(tx)) - } - } - } - } - - impl<'a> From> for super::OpTypedTransaction { - fn from(value: OpTypedTransaction<'a>) -> Self { - match value { - OpTypedTransaction::Legacy(tx) => Self::Legacy(tx.into()), - OpTypedTransaction::Eip2930(tx) => Self::Eip2930(tx.into()), - OpTypedTransaction::Eip1559(tx) => Self::Eip1559(tx.into()), - OpTypedTransaction::Eip7702(tx) => Self::Eip7702(tx.into()), - OpTypedTransaction::Deposit(tx) => Self::Deposit(tx.into()), - } - } - } - - /// Bincode-compatible [`super::OpTransactionSigned`] serde implementation. - #[derive(Debug, Serialize, Deserialize)] - pub struct OpTransactionSigned<'a> { - hash: TxHash, - signature: Signature, - transaction: OpTypedTransaction<'a>, - } - - impl<'a> From<&'a super::OpTransactionSigned> for OpTransactionSigned<'a> { - fn from(value: &'a super::OpTransactionSigned) -> Self { - Self { - hash: *value.tx_hash(), - signature: value.signature, - transaction: OpTypedTransaction::from(&value.transaction), - } - } - } - - impl<'a> From> for super::OpTransactionSigned { - fn from(value: OpTransactionSigned<'a>) -> Self { - Self { - hash: value.hash.into(), - signature: value.signature, - transaction: value.transaction.into(), - } - } - } - - impl SerdeBincodeCompat for super::OpTransactionSigned { - type BincodeRepr<'a> = OpTransactionSigned<'a>; - - fn as_repr(&self) -> Self::BincodeRepr<'_> { - self.into() - } - - fn from_repr(repr: Self::BincodeRepr<'_>) -> Self { - repr.into() - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/optimism/primitives/src/transaction/tx_type.rs b/crates/optimism/primitives/src/transaction/tx_type.rs index 8be5f3a3d5..deaaebc068 100644 --- a/crates/optimism/primitives/src/transaction/tx_type.rs +++ b/crates/optimism/primitives/src/transaction/tx_type.rs @@ -1,12 +1,9 @@ //! Optimism transaction type. -pub use op_alloy_consensus::OpTxType; - #[cfg(test)] mod tests { - use super::*; use alloy_consensus::constants::EIP7702_TX_TYPE_ID; - use op_alloy_consensus::DEPOSIT_TX_TYPE_ID; + use op_alloy_consensus::{OpTxType, DEPOSIT_TX_TYPE_ID}; use reth_codecs::{txtype::*, Compact}; use rstest::rstest; diff --git a/crates/optimism/rpc/src/eth/block.rs b/crates/optimism/rpc/src/eth/block.rs index c1a6f56d6d..7a87ea4d53 100644 --- a/crates/optimism/rpc/src/eth/block.rs +++ b/crates/optimism/rpc/src/eth/block.rs @@ -7,7 +7,6 @@ use reth_chainspec::ChainSpecProvider; use reth_node_api::BlockBody; use reth_optimism_chainspec::OpChainSpec; use reth_optimism_primitives::{OpReceipt, OpTransactionSigned}; -use reth_primitives_traits::SignedTransaction; use reth_rpc_eth_api::{ helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking}, types::RpcTypes, @@ -50,7 +49,7 @@ where .enumerate() .map(|(idx, (tx, receipt))| -> Result<_, _> { let meta = TransactionMeta { - tx_hash: *tx.tx_hash(), + tx_hash: tx.tx_hash(), index: idx as u64, block_hash, block_number, diff --git a/crates/optimism/rpc/src/eth/transaction.rs b/crates/optimism/rpc/src/eth/transaction.rs index 0cc7f4f46a..f46e142df4 100644 --- a/crates/optimism/rpc/src/eth/transaction.rs +++ b/crates/optimism/rpc/src/eth/transaction.rs @@ -1,6 +1,6 @@ //! Loads and formats OP transaction RPC response. -use alloy_consensus::{transaction::Recovered, Transaction as _}; +use alloy_consensus::{transaction::Recovered, SignableTransaction, Transaction as _}; use alloy_primitives::{Bytes, Sealable, Sealed, Signature, B256}; use alloy_rpc_types_eth::TransactionInfo; use op_alloy_consensus::OpTxEnvelope; @@ -145,7 +145,7 @@ where // Create an empty signature for the transaction. let signature = Signature::new(Default::default(), Default::default(), false); - Ok(OpTransactionSigned::new_unhashed(tx, signature)) + Ok(tx.into_signed(signature).into()) } fn otterscan_api_truncate_input(tx: &mut Self::Transaction) { diff --git a/crates/optimism/txpool/src/transaction.rs b/crates/optimism/txpool/src/transaction.rs index 59b1d5dc38..825c91f9e3 100644 --- a/crates/optimism/txpool/src/transaction.rs +++ b/crates/optimism/txpool/src/transaction.rs @@ -284,8 +284,8 @@ mod tests { use crate::{OpPooledTransaction, OpTransactionValidator}; use alloy_consensus::transaction::Recovered; use alloy_eips::eip2718::Encodable2718; - use alloy_primitives::{Signature, TxKind, U256}; - use op_alloy_consensus::{OpTypedTransaction, TxDeposit}; + use alloy_primitives::{TxKind, U256}; + use op_alloy_consensus::TxDeposit; use reth_optimism_chainspec::OP_MAINNET; use reth_optimism_primitives::OpTransactionSigned; use reth_provider::test_utils::MockEthProvider; @@ -304,7 +304,7 @@ mod tests { let origin = TransactionOrigin::External; let signer = Default::default(); - let deposit_tx = OpTypedTransaction::Deposit(TxDeposit { + let deposit_tx = TxDeposit { source_hash: Default::default(), from: signer, to: TxKind::Create, @@ -313,9 +313,8 @@ mod tests { gas_limit: 0, is_system_transaction: false, input: Default::default(), - }); - let signature = Signature::test_signature(); - let signed_tx = OpTransactionSigned::new_unhashed(deposit_tx, signature); + }; + let signed_tx: OpTransactionSigned = deposit_tx.into(); let signed_recovered = Recovered::new_unchecked(signed_tx, signer); let len = signed_recovered.encode_2718_len(); let pooled_tx: OpPooledTransaction = OpPooledTransaction::new(signed_recovered, len); diff --git a/examples/custom-node/src/primitives/tx.rs b/examples/custom-node/src/primitives/tx.rs index b63c792331..e9118fc753 100644 --- a/examples/custom-node/src/primitives/tx.rs +++ b/examples/custom-node/src/primitives/tx.rs @@ -8,7 +8,7 @@ use reth_ethereum::primitives::{ SignedTransaction, }; use reth_op::{ - serde_bincode_compat::OpTransactionSigned as BincodeCompatOpTransactionSigned, + serde_bincode_compat::transaction::OpTxEnvelope as BincodeCompatOpTransactionSigned, OpTransactionSigned, }; use revm_primitives::{Address, Bytes}; @@ -94,7 +94,7 @@ impl Transaction for CustomTransaction { impl SignedTransaction for CustomTransaction { fn tx_hash(&self) -> &TxHash { - self.inner.tx_hash() + self.inner.hash() } fn recover_signer(&self) -> Result {