mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf(op-receipts): reuse l1_block_info for multiple receipts (#13781)
This commit is contained in:
@ -40,7 +40,7 @@ where
|
|||||||
let excess_blob_gas = block.excess_blob_gas();
|
let excess_blob_gas = block.excess_blob_gas();
|
||||||
let timestamp = block.timestamp();
|
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)?;
|
reth_optimism_evm::extract_l1_info(block.body()).map_err(OpEthApiError::from)?;
|
||||||
|
|
||||||
return block
|
return block
|
||||||
@ -60,13 +60,18 @@ where
|
|||||||
timestamp,
|
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();
|
||||||
|
|
||||||
Ok(OpReceiptBuilder::new(
|
Ok(OpReceiptBuilder::new(
|
||||||
&self.inner.eth_api.provider().chain_spec(),
|
&self.inner.eth_api.provider().chain_spec(),
|
||||||
tx,
|
tx,
|
||||||
meta,
|
meta,
|
||||||
receipt,
|
receipt,
|
||||||
&receipts,
|
&receipts,
|
||||||
l1_block_info.clone(),
|
&mut l1_block_info,
|
||||||
)?
|
)?
|
||||||
.build())
|
.build())
|
||||||
})
|
})
|
||||||
|
|||||||
@ -40,7 +40,7 @@ where
|
|||||||
meta.block_hash.into(),
|
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)?;
|
reth_optimism_evm::extract_l1_info(block.body()).map_err(OpEthApiError::from)?;
|
||||||
|
|
||||||
Ok(OpReceiptBuilder::new(
|
Ok(OpReceiptBuilder::new(
|
||||||
@ -49,7 +49,7 @@ where
|
|||||||
meta,
|
meta,
|
||||||
&receipt,
|
&receipt,
|
||||||
&receipts,
|
&receipts,
|
||||||
l1_block_info,
|
&mut l1_block_info,
|
||||||
)?
|
)?
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ impl OpReceiptFieldsBuilder {
|
|||||||
mut self,
|
mut self,
|
||||||
chain_spec: &OpChainSpec,
|
chain_spec: &OpChainSpec,
|
||||||
tx: &OpTransactionSigned,
|
tx: &OpTransactionSigned,
|
||||||
mut l1_block_info: revm::L1BlockInfo,
|
l1_block_info: &mut revm::L1BlockInfo,
|
||||||
) -> Result<Self, OpEthApiError> {
|
) -> Result<Self, OpEthApiError> {
|
||||||
let raw_tx = tx.encoded_2718();
|
let raw_tx = tx.encoded_2718();
|
||||||
let timestamp = self.block_timestamp;
|
let timestamp = self.block_timestamp;
|
||||||
@ -199,7 +199,7 @@ impl OpReceiptBuilder {
|
|||||||
meta: TransactionMeta,
|
meta: TransactionMeta,
|
||||||
receipt: &OpReceipt,
|
receipt: &OpReceipt,
|
||||||
all_receipts: &[OpReceipt],
|
all_receipts: &[OpReceipt],
|
||||||
l1_block_info: revm::L1BlockInfo,
|
l1_block_info: &mut revm::L1BlockInfo,
|
||||||
) -> Result<Self, OpEthApiError> {
|
) -> Result<Self, OpEthApiError> {
|
||||||
let timestamp = meta.timestamp;
|
let timestamp = meta.timestamp;
|
||||||
let core_receipt =
|
let core_receipt =
|
||||||
@ -298,14 +298,14 @@ mod test {
|
|||||||
..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");
|
reth_optimism_evm::extract_l1_info(&block.body).expect("should extract l1 info");
|
||||||
|
|
||||||
// test
|
// test
|
||||||
assert!(OP_MAINNET.is_fjord_active_at_timestamp(BLOCK_124665056_TIMESTAMP));
|
assert!(OP_MAINNET.is_fjord_active_at_timestamp(BLOCK_124665056_TIMESTAMP));
|
||||||
|
|
||||||
let receipt_meta = OpReceiptFieldsBuilder::new(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")
|
.expect("should parse revm l1 info")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ mod test {
|
|||||||
body: BlockBody { transactions: vec![tx_0], ..Default::default() },
|
body: BlockBody { transactions: vec![tx_0], ..Default::default() },
|
||||||
..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");
|
reth_optimism_evm::extract_l1_info(&block.body).expect("should extract l1 info");
|
||||||
|
|
||||||
// https://basescan.org/tx/0xf9420cbaf66a2dda75a015488d37262cbfd4abd0aad7bb2be8a63e14b1fa7a94
|
// https://basescan.org/tx/0xf9420cbaf66a2dda75a015488d37262cbfd4abd0aad7bb2be8a63e14b1fa7a94
|
||||||
@ -371,7 +371,7 @@ mod test {
|
|||||||
let tx_1 = OpTransactionSigned::decode_2718(&mut &tx[..]).unwrap();
|
let tx_1 = OpTransactionSigned::decode_2718(&mut &tx[..]).unwrap();
|
||||||
|
|
||||||
let receipt_meta = OpReceiptFieldsBuilder::new(1730216981)
|
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")
|
.expect("should parse revm l1 info")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user