Skip to content

Commit

Permalink
impl Encodable2718, Decodable2718 for TransactionSigned (#11218)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Sep 30, 2024
1 parent 24b6341 commit 42afcbd
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 315 deletions.
58 changes: 34 additions & 24 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ reth-engine-util.workspace = true
reth-prune.workspace = true

# crypto
alloy-eips.workspace = true
alloy-rlp.workspace = true
alloy-rpc-types = { workspace = true, features = ["engine"] }
alloy-consensus.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Command for debugging block building.
use alloy_consensus::TxEip4844;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rlp::Decodable;
use alloy_rpc_types::engine::{BlobsBundleV1, PayloadAttributes};
Expand Down Expand Up @@ -200,7 +201,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {

encoded_length
}
_ => transaction.length_without_header(),
_ => transaction.encode_2718_len(),
};

debug!(target: "reth::cli", ?transaction, "Adding transaction to the pool");
Expand Down
2 changes: 2 additions & 0 deletions crates/optimism/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ thiserror.workspace = true
tracing.workspace = true

[dev-dependencies]
alloy-eips.workspace = true

reth-revm = { workspace = true, features = ["test-utils"] }
reth-optimism-chainspec.workspace = true
alloy-genesis.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/optimism/evm/src/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ where

#[cfg(test)]
mod tests {
use alloy_eips::eip2718::Decodable2718;
use reth_optimism_chainspec::OP_MAINNET;
use reth_optimism_forks::OptimismHardforks;
use reth_primitives::{BlockBody, TransactionSigned};
Expand All @@ -311,7 +312,7 @@ mod tests {
use reth_primitives::{Header, TransactionSigned};

let bytes = Bytes::from_static(&hex!("7ef9015aa044bae9d41b8380d781187b426c6fe43df5fb2fb57bd4466ef6a701e1f01e015694deaddeaddeaddeaddeaddeaddeaddeaddead000194420000000000000000000000000000000000001580808408f0d18001b90104015d8eb900000000000000000000000000000000000000000000000000000000008057650000000000000000000000000000000000000000000000000000000063d96d10000000000000000000000000000000000000000000000000000000000009f35273d89754a1e0387b89520d989d3be9c37c1f32495a88faf1ea05c61121ab0d1900000000000000000000000000000000000000000000000000000000000000010000000000000000000000002d679b567db6187c0c8323fa982cfb88b74dbcc7000000000000000000000000000000000000000000000000000000000000083400000000000000000000000000000000000000000000000000000000000f4240"));
let l1_info_tx = TransactionSigned::decode_enveloped(&mut bytes.as_ref()).unwrap();
let l1_info_tx = TransactionSigned::decode_2718(&mut bytes.as_ref()).unwrap();
let mock_block = Block {
header: Header::default(),
body: BlockBody { transactions: vec![l1_info_tx], ..Default::default() },
Expand Down Expand Up @@ -339,7 +340,7 @@ mod tests {
// https://optimistic.etherscan.io/getRawTx?tx=0x88501da5d5ca990347c2193be90a07037af1e3820bb40774c8154871c7669150
const TX: [u8; 251] = hex!("7ef8f8a0a539eb753df3b13b7e386e147d45822b67cb908c9ddc5618e3dbaa22ed00850b94deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc50000000000000000000000006605a89f00000000012a10d90000000000000000000000000000000000000000000000000000000af39ac3270000000000000000000000000000000000000000000000000000000d5ea528d24e582fa68786f080069bdbfe06a43f8e67bfd31b8e4d8a8837ba41da9a82a54a0000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985");

let tx = TransactionSigned::decode_enveloped(&mut TX.as_slice()).unwrap();
let tx = TransactionSigned::decode_2718(&mut TX.as_slice()).unwrap();
let block = Block {
body: BlockBody { transactions: vec![tx], ..Default::default() },
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ reth-optimism-consensus.workspace = true
reth-optimism-forks.workspace = true

# ethereum
alloy-eips.workspace = true
alloy-primitives.workspace = true
op-alloy-rpc-types-engine.workspace = true
alloy-rpc-types-engine.workspace = true
Expand Down
6 changes: 4 additions & 2 deletions crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! OP transaction pool types
use alloy_eips::eip2718::Encodable2718;
use parking_lot::RwLock;
use reth_chainspec::ChainSpec;
use reth_optimism_evm::RethL1BlockInfo;
Expand Down Expand Up @@ -139,7 +140,7 @@ where
let l1_block_info = self.block_info.l1_block_info.read().clone();

let mut encoded = Vec::with_capacity(valid_tx.transaction().encoded_length());
valid_tx.transaction().clone().into_consensus().encode_enveloped(&mut encoded);
valid_tx.transaction().clone().into_consensus().encode_2718(&mut encoded);

let cost_addition = match l1_block_info.l1_tx_data_fee(
&self.chain_spec(),
Expand Down Expand Up @@ -229,6 +230,7 @@ pub struct OpL1BlockInfo {
#[cfg(test)]
mod tests {
use crate::txpool::OpTransactionValidator;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{TxKind, U256};
use reth::primitives::Signature;
use reth_chainspec::MAINNET;
Expand Down Expand Up @@ -266,7 +268,7 @@ mod tests {
let signed_tx = TransactionSigned::from_transaction_and_signature(deposit_tx, signature);
let signed_recovered =
TransactionSignedEcRecovered::from_signed_transaction(signed_tx, signer);
let len = signed_recovered.length_without_header();
let len = signed_recovered.encode_2718_len();
let pooled_tx = EthPooledTransaction::new(signed_recovered, len);
let outcome = validator.validate_one(origin, pooled_tx);

Expand Down
1 change: 1 addition & 0 deletions crates/optimism/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ reth-optimism-forks.workspace = true

# ethereum
revm.workspace = true
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
op-alloy-rpc-types-engine.workspace = true
Expand Down
12 changes: 10 additions & 2 deletions crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Optimism builder support
use alloy_eips::eip2718::Decodable2718;
use alloy_primitives::{Address, B256, U256};
use alloy_rlp::Encodable;
use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId};
Expand Down Expand Up @@ -53,8 +54,15 @@ impl PayloadBuilderAttributes for OptimismPayloadBuilderAttributes {
.unwrap_or_default()
.into_iter()
.map(|data| {
TransactionSigned::decode_enveloped(&mut data.as_ref())
.map(|tx| WithEncoded::new(data, tx))
let mut buf = data.as_ref();
let tx =
TransactionSigned::decode_2718(&mut buf).map_err(alloy_rlp::Error::from)?;

if !buf.is_empty() {
return Err(alloy_rlp::Error::UnexpectedLength);
}

Ok(WithEncoded::new(data, tx))
})
.collect::<Result<_, _>>()?;

Expand Down
1 change: 1 addition & 0 deletions crates/optimism/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ reth-optimism-evm.workspace = true
reth-optimism-forks.workspace = true

# ethereum
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-rpc-types.workspace = true
Expand Down
11 changes: 6 additions & 5 deletions crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Loads and formats OP receipt RPC response.
use alloy_eips::eip2718::Encodable2718;
use alloy_rpc_types::{AnyReceiptEnvelope, Log, TransactionReceipt};
use op_alloy_consensus::{OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope};
use op_alloy_rpc_types::{
Expand Down Expand Up @@ -119,7 +120,7 @@ impl OpReceiptFieldsBuilder {
tx: &TransactionSigned,
l1_block_info: revm::L1BlockInfo,
) -> Result<Self, OpEthApiError> {
let raw_tx = tx.envelope_encoded();
let raw_tx = tx.encoded_2718();
let timestamp = self.l1_block_timestamp;

self.l1_fee = Some(
Expand Down Expand Up @@ -300,6 +301,7 @@ impl OpReceiptBuilder {
#[cfg(test)]
mod test {
use alloy_primitives::hex;
use op_alloy_network::eip2718::Decodable2718;
use reth_optimism_chainspec::OP_MAINNET;
use reth_primitives::{Block, BlockBody};

Expand Down Expand Up @@ -341,14 +343,13 @@ mod test {
#[test]
fn op_receipt_fields_from_block_and_tx() {
// rig
let tx_0 = TransactionSigned::decode_enveloped(
let tx_0 = TransactionSigned::decode_2718(
&mut TX_SET_L1_BLOCK_OP_MAINNET_BLOCK_124665056.as_slice(),
)
.unwrap();

let tx_1 =
TransactionSigned::decode_enveloped(&mut TX_1_OP_MAINNET_BLOCK_124665056.as_slice())
.unwrap();
let tx_1 = TransactionSigned::decode_2718(&mut TX_1_OP_MAINNET_BLOCK_124665056.as_slice())
.unwrap();

let block = Block {
body: BlockBody { transactions: [tx_0, tx_1.clone()].to_vec(), ..Default::default() },
Expand Down
Loading

0 comments on commit 42afcbd

Please sign in to comment.