Skip to content

Commit 0262ece

Browse files
authored
feat: remove receipts and balances from metadata (#300)
The metadata field used to contain receipts and changed account balances as a performance optimization to be able to serve RPC requests without actually executing the block, but we still need to execute the block in most cases anyway. This removes the receipts and changed_account_balances fields from the response. These are generated during flashblock execution instead. This still preserves skipping execution of transactions that were executed in previous flashblocks as long as we have the receipt and state from the previous execution. In either the cached or executed path, cumulative_gas and next_log_index are updated. The tests also needed to be fixed since they relied on the receipts for logs and the changed balances. Now, since the transactions are actually executed, we need to actually emit logs from the contracts when executed and send balance to the address rather than relying on changed_account_balances.
1 parent 6e1eb76 commit 0262ece

File tree

11 files changed

+464
-467
lines changed

11 files changed

+464
-467
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ alloy-rpc-types-eth = "1.0.41"
116116
alloy-rpc-types-engine = "1.0.41"
117117

118118
# op-alloy
119+
alloy-op-evm = { version = "0.23.3", default-features = false }
119120
op-alloy-network = "0.22.0"
120121
op-alloy-rpc-types = "0.22.0"
121122
op-alloy-consensus = "0.22.0"

crates/flashblocks/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ alloy-provider.workspace = true
3232
alloy-rpc-types.workspace = true
3333
alloy-consensus.workspace = true
3434
alloy-primitives.workspace = true
35+
alloy-op-evm.workspace = true
3536
alloy-rpc-types-eth.workspace = true
3637
alloy-rpc-types-engine.workspace = true
3738

crates/flashblocks/benches/pending_state.rs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ use std::{
55
time::{Duration, Instant},
66
};
77

8-
use alloy_consensus::Receipt;
98
use alloy_eips::{BlockHashOrNumber, Encodable2718};
10-
use alloy_primitives::{Address, B256, BlockNumber, Bytes, U256, b256, bytes, hex::FromHex};
9+
use alloy_primitives::{Address, B256, BlockNumber, Bytes, U256, bytes, hex::FromHex};
1110
use alloy_rpc_types_engine::PayloadId;
1211
use base_flashtypes::{
1312
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, Flashblock, Metadata,
1413
};
1514
use base_reth_flashblocks::{FlashblocksAPI, FlashblocksReceiver, FlashblocksState};
1615
use base_reth_test_utils::{LocalNodeProvider, TestAccounts, TestHarness};
1716
use criterion::{BatchSize, Criterion, Throughput, criterion_group, criterion_main};
18-
use op_alloy_consensus::OpDepositReceipt;
1917
use reth::{
2018
chainspec::{ChainSpecProvider, EthChainSpec},
2119
providers::BlockReader,
2220
transaction_pool::test_utils::TransactionBuilder,
2321
};
24-
use reth_optimism_primitives::{OpBlock, OpReceipt, OpTransactionSigned};
22+
use reth_optimism_primitives::{OpBlock, OpTransactionSigned};
2523
use reth_primitives_traits::{Block as BlockT, RecoveredBlock};
2624
use tokio::{runtime::Runtime, time::sleep};
2725
use tracing_subscriber::{EnvFilter, filter::LevelFilter};
@@ -33,8 +31,6 @@ const CHUNK_SIZE: usize = 10;
3331
const BLOCK_INFO_TXN: Bytes = bytes!(
3432
"0x7ef90104a06c0c775b6b492bab9d7e81abdf27f77cafb698551226455a82f559e0f93fea3794deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8b0098999be000008dd00101c1200000000000000020000000068869d6300000000015f277f000000000000000000000000000000000000000000000000000000000d42ac290000000000000000000000000000000000000000000000000000000000000001abf52777e63959936b1bf633a2a643f0da38d63deffe49452fed1bf8a44975d50000000000000000000000005050f69a9786f081509234f1a7f4684b5e5b76c9000000000000000000000000"
3533
);
36-
const BLOCK_INFO_TXN_HASH: B256 =
37-
b256!("0xba56c8b0deb460ff070f8fca8e2ee01e51a3db27841cc862fdd94cc1a47662b6");
3834

3935
struct BenchSetup {
4036
provider: LocalNodeProvider,
@@ -203,20 +199,6 @@ fn base_flashblock(
203199
canonical_block: &RecoveredBlock<OpBlock>,
204200
block_number: BlockNumber,
205201
) -> Flashblock {
206-
let mut receipts = alloy_primitives::map::HashMap::default();
207-
receipts.insert(
208-
BLOCK_INFO_TXN_HASH,
209-
OpReceipt::Deposit(OpDepositReceipt {
210-
inner: Receipt {
211-
status: true.into(),
212-
cumulative_gas_used: DEPOSIT_GAS_USED,
213-
logs: vec![],
214-
},
215-
deposit_nonce: Some(0),
216-
deposit_receipt_version: None,
217-
}),
218-
);
219-
220202
Flashblock {
221203
payload_id: PayloadId::default(),
222204
index: 0,
@@ -242,7 +224,7 @@ fn base_flashblock(
242224
transactions: vec![BLOCK_INFO_TXN.clone()],
243225
blob_gas_used: Default::default(),
244226
},
245-
metadata: Metadata { block_number, receipts, new_account_balances: Default::default() },
227+
metadata: Metadata { block_number },
246228
}
247229
}
248230

@@ -252,20 +234,11 @@ fn transaction_flashblock(
252234
transactions: &[OpTransactionSigned],
253235
gas_used: &mut u64,
254236
) -> Flashblock {
255-
let mut tx_receipts = alloy_primitives::map::HashMap::default();
256237
let mut tx_bytes = Vec::with_capacity(transactions.len());
257238

258239
for tx in transactions {
259240
*gas_used += TX_GAS_USED;
260241
tx_bytes.push(tx.encoded_2718().into());
261-
tx_receipts.insert(
262-
tx.hash().clone(),
263-
OpReceipt::Eip1559(Receipt {
264-
status: true.into(),
265-
cumulative_gas_used: *gas_used,
266-
logs: vec![],
267-
}),
268-
);
269242
}
270243

271244
Flashblock {
@@ -283,11 +256,7 @@ fn transaction_flashblock(
283256
transactions: tx_bytes,
284257
blob_gas_used: Default::default(),
285258
},
286-
metadata: Metadata {
287-
block_number,
288-
receipts: tx_receipts,
289-
new_account_balances: Default::default(),
290-
},
259+
metadata: Metadata { block_number },
291260
}
292261
}
293262

0 commit comments

Comments
 (0)