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

perf(op-receipts): reuse l1_block_info for multiple receipts #13781

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions crates/optimism/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
let excess_blob_gas = block.excess_blob_gas();
let timestamp = block.timestamp();

let l1_block_info =
let mut l1_block_info =
reth_optimism_evm::extract_l1_info(block.body()).map_err(OpEthApiError::from)?;

return block
Expand All @@ -60,13 +60,18 @@ where
timestamp,
};

// We must clear this cache as different L2 transactions can have different
// L1 costs. A potential improvement here is to only clear the cache if the
// new transaction input has changed, since otherwise the L1 cost wouldn't.
l1_block_info.clear_tx_l1_cost();
Comment on lines +63 to +66
Copy link
Collaborator

Choose a reason for hiding this comment

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

-.-
I knew that introducing this behaviour would end causing problems somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a dangerous but manageable one 🙏.


Ok(OpReceiptBuilder::new(
&self.inner.eth_api.provider().chain_spec(),
tx,
meta,
receipt,
&receipts,
l1_block_info.clone(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main motivation as L1BlockInfo is 312 bytes and this clone can scale to 100k+ transactions/block for high-performance chains.

&mut l1_block_info,
)?
.build())
})
Expand Down
16 changes: 8 additions & 8 deletions crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
meta.block_hash.into(),
)))?;

let l1_block_info =
let mut l1_block_info =
reth_optimism_evm::extract_l1_info(block.body()).map_err(OpEthApiError::from)?;

Ok(OpReceiptBuilder::new(
Expand All @@ -49,7 +49,7 @@ where
meta,
&receipt,
&receipts,
l1_block_info,
&mut l1_block_info,
)?
.build())
}
Expand Down Expand Up @@ -107,7 +107,7 @@ impl OpReceiptFieldsBuilder {
mut self,
chain_spec: &OpChainSpec,
tx: &OpTransactionSigned,
mut l1_block_info: revm::L1BlockInfo,
l1_block_info: &mut revm::L1BlockInfo,
) -> Result<Self, OpEthApiError> {
let raw_tx = tx.encoded_2718();
let timestamp = self.block_timestamp;
Expand Down Expand Up @@ -199,7 +199,7 @@ impl OpReceiptBuilder {
meta: TransactionMeta,
receipt: &OpReceipt,
all_receipts: &[OpReceipt],
l1_block_info: revm::L1BlockInfo,
l1_block_info: &mut revm::L1BlockInfo,
) -> Result<Self, OpEthApiError> {
let timestamp = meta.timestamp;
let core_receipt =
Expand Down Expand Up @@ -298,14 +298,14 @@ mod test {
..Default::default()
};

let l1_block_info =
let mut l1_block_info =
reth_optimism_evm::extract_l1_info(&block.body).expect("should extract l1 info");

// test
assert!(OP_MAINNET.is_fjord_active_at_timestamp(BLOCK_124665056_TIMESTAMP));

let receipt_meta = OpReceiptFieldsBuilder::new(BLOCK_124665056_TIMESTAMP)
.l1_block_info(&OP_MAINNET, &tx_1, l1_block_info)
.l1_block_info(&OP_MAINNET, &tx_1, &mut l1_block_info)
.expect("should parse revm l1 info")
.build();

Expand Down Expand Up @@ -363,15 +363,15 @@ mod test {
body: BlockBody { transactions: vec![tx_0], ..Default::default() },
..Default::default()
};
let l1_block_info =
let mut l1_block_info =
reth_optimism_evm::extract_l1_info(&block.body).expect("should extract l1 info");

// https://basescan.org/tx/0xf9420cbaf66a2dda75a015488d37262cbfd4abd0aad7bb2be8a63e14b1fa7a94
let tx = hex!("02f86c8221058034839a4ae283021528942f16386bb37709016023232523ff6d9daf444be380841249c58bc080a001b927eda2af9b00b52a57be0885e0303c39dd2831732e14051c2336470fd468a0681bf120baf562915841a48601c2b54a6742511e535cf8f71c95115af7ff63bd");
let tx_1 = OpTransactionSigned::decode_2718(&mut &tx[..]).unwrap();

let receipt_meta = OpReceiptFieldsBuilder::new(1730216981)
.l1_block_info(&BASE_MAINNET, &tx_1, l1_block_info)
.l1_block_info(&BASE_MAINNET, &tx_1, &mut l1_block_info)
.expect("should parse revm l1 info")
.build();

Expand Down
Loading