Skip to content

Commit 9e37483

Browse files
iovoidjrchatrucpablodeymo
authored
perf(l1): validate receipts in the same thread as the execution (#5170)
**Motivation** In pipelined execution we have two threads: executor and merkelizer. Currently we perform validations (gas usage, receipts, requests) after both are done. However, these do not depend on the results of the merkelization so they can be merged with the execution thread. **Description** Since the merkelization thread necessarily finishes after execution is complete, we don't need to worry about the executor taking too long. --------- Co-authored-by: Javier Rodríguez Chatruc <[email protected]> Co-authored-by: Pablo Deymonnaz <[email protected]>
1 parent f86cb00 commit 9e37483

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Perf
44

5+
### 2025-11-03
6+
- Merge execution with some post-execution validations [#5170](https://github.com/lambdaclass/ethrex/pull/5170)
7+
58
### 2025-10-31
69
- Reduce overhead of trie opening [#5145](https://github.com/lambdaclass/ethrex/pull/5145)
710
- Improved discovery and peer initialization [#5147](https://github.com/lambdaclass/ethrex/pull/5147)

crates/blockchain/blockchain.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Blockchain {
190190
AccountUpdatesList,
191191
// FIXME: extract to stats struct
192192
usize,
193-
[Instant; 7],
193+
[Instant; 6],
194194
),
195195
ChainError,
196196
> {
@@ -217,10 +217,16 @@ impl Blockchain {
217217
let mut max_queue_length = 0;
218218
let (execution_result, account_updates_list) = std::thread::scope(|s| {
219219
let (tx, rx) = channel();
220-
let execution_handle = s.spawn(move || {
221-
let execution_result = vm.execute_block_pipeline(block, tx, queue_length_ref);
220+
let execution_handle = s.spawn(move || -> Result<_, ChainError> {
221+
let execution_result = vm.execute_block_pipeline(block, tx, queue_length_ref)?;
222+
223+
// Validate execution went alright
224+
validate_gas_used(&execution_result.receipts, &block.header)?;
225+
validate_receipts_root(&block.header, &execution_result.receipts)?;
226+
validate_requests_hash(&block.header, &chain_config, &execution_result.requests)?;
227+
222228
let exec_end_instant = Instant::now();
223-
execution_result.map(move |r| (r, exec_end_instant))
229+
Ok((execution_result, exec_end_instant))
224230
});
225231
let merkleize_handle = s.spawn(move || -> Result<_, StoreError> {
226232
let account_updates_list = self.handle_merkleization(
@@ -234,7 +240,7 @@ impl Blockchain {
234240
});
235241
(
236242
execution_handle.join().unwrap_or_else(|_| {
237-
Err(EvmError::Custom("execution thread panicked".to_string()))
243+
Err(ChainError::Custom("execution thread panicked".to_string()))
238244
}),
239245
merkleize_handle.join().unwrap_or_else(|_| {
240246
Err(StoreError::Custom(
@@ -247,12 +253,6 @@ impl Blockchain {
247253
let (execution_result, exec_end_instant) = execution_result?;
248254
let exec_merkle_end_instant = Instant::now();
249255

250-
// Validate execution went alright
251-
validate_gas_used(&execution_result.receipts, &block.header)?;
252-
validate_receipts_root(&block.header, &execution_result.receipts)?;
253-
validate_requests_hash(&block.header, &chain_config, &execution_result.requests)?;
254-
let results_validated_instant = Instant::now();
255-
256256
Ok((
257257
execution_result,
258258
account_updates_list,
@@ -264,7 +264,6 @@ impl Blockchain {
264264
exec_end_instant,
265265
merkle_end_instant,
266266
exec_merkle_end_instant,
267-
results_validated_instant,
268267
],
269268
))
270269
}
@@ -942,9 +941,8 @@ impl Blockchain {
942941
exec_end_instant,
943942
merkle_end_instant,
944943
exec_merkle_end_instant,
945-
results_validated_instant,
946944
stored_instant,
947-
]: [Instant; 8],
945+
]: [Instant; 7],
948946
) {
949947
let interval = stored_instant.duration_since(start_instant).as_secs_f64();
950948
if interval != 0f64 {
@@ -974,13 +972,12 @@ impl Blockchain {
974972
};
975973
let extra_log = if as_gigas > 0.0 {
976974
format!(
977-
" block validation: {}% exec+merkle: {}% (exec: {}% merkle: {}% max_queue_length: {merkle_queue_length}) results validation: {}% store: {}%",
975+
" block validation: {}% exec+merkle: {}% (exec: {}% merkle: {}% max_queue_length: {merkle_queue_length}) store: {}%",
978976
percentage(start_instant, block_validated_instant),
979977
percentage(exec_merkle_start, exec_merkle_end_instant),
980978
percentage(exec_merkle_start, exec_end_instant),
981979
percentage(exec_merkle_start, merkle_end_instant),
982-
percentage(merkle_end_instant, results_validated_instant),
983-
percentage(results_validated_instant, stored_instant),
980+
percentage(merkle_end_instant, stored_instant),
984981
)
985982
} else {
986983
"".to_string()

0 commit comments

Comments
 (0)