Skip to content

Commit f157a78

Browse files
ElFantasmaxqft
authored andcommitted
feat(l1): named block_executor thread and subthreads (#5211)
Easier identification on samply: <img width="1099" height="646" alt="image" src="https://github.com/user-attachments/assets/ab0095f4-b352-4883-b92b-ddc305913911" />
1 parent adde5fe commit f157a78

2 files changed

Lines changed: 42 additions & 28 deletions

File tree

crates/blockchain/blockchain.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -218,27 +218,38 @@ impl Blockchain {
218218
let (execution_result, account_updates_list) = std::thread::scope(|s| {
219219
let max_queue_length_ref = &mut max_queue_length;
220220
let (tx, rx) = channel();
221-
let execution_handle = s.spawn(move || -> Result<_, ChainError> {
222-
let execution_result = vm.execute_block_pipeline(block, tx, queue_length_ref)?;
223-
224-
// Validate execution went alright
225-
validate_gas_used(&execution_result.receipts, &block.header)?;
226-
validate_receipts_root(&block.header, &execution_result.receipts)?;
227-
validate_requests_hash(&block.header, &chain_config, &execution_result.requests)?;
228-
229-
let exec_end_instant = Instant::now();
230-
Ok((execution_result, exec_end_instant))
231-
});
232-
let merkleize_handle = s.spawn(move || -> Result<_, StoreError> {
233-
let account_updates_list = self.handle_merkleization(
234-
rx,
235-
&parent_header,
236-
queue_length_ref,
237-
max_queue_length_ref,
238-
)?;
239-
let merkle_end_instant = Instant::now();
240-
Ok((account_updates_list, merkle_end_instant))
241-
});
221+
let execution_handle = std::thread::Builder::new()
222+
.name("block_executor_execution".to_string())
223+
.spawn_scoped(s, move || -> Result<_, ChainError> {
224+
let execution_result =
225+
vm.execute_block_pipeline(block, tx, queue_length_ref)?;
226+
227+
// Validate execution went alright
228+
validate_gas_used(&execution_result.receipts, &block.header)?;
229+
validate_receipts_root(&block.header, &execution_result.receipts)?;
230+
validate_requests_hash(
231+
&block.header,
232+
&chain_config,
233+
&execution_result.requests,
234+
)?;
235+
236+
let exec_end_instant = Instant::now();
237+
Ok((execution_result, exec_end_instant))
238+
})
239+
.expect("Failed to spawn block_executor exec thread");
240+
let merkleize_handle = std::thread::Builder::new()
241+
.name("block_executor_merkleizer".to_string())
242+
.spawn_scoped(s, move || -> Result<_, StoreError> {
243+
let account_updates_list = self.handle_merkleization(
244+
rx,
245+
&parent_header,
246+
queue_length_ref,
247+
max_queue_length_ref,
248+
)?;
249+
let merkle_end_instant = Instant::now();
250+
Ok((account_updates_list, merkle_end_instant))
251+
})
252+
.expect("Failed to spawn block_executor merkleizer thread");
242253
(
243254
execution_handle.join().unwrap_or_else(|_| {
244255
Err(ChainError::Custom("execution thread panicked".to_string()))

crates/networking/rpc/rpc.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,16 @@ pub fn start_block_executor(
208208
) -> UnboundedSender<(oneshot::Sender<Result<(), ChainError>>, Block)> {
209209
let (block_worker_channel, mut block_receiver) =
210210
unbounded_channel::<(oneshot::Sender<Result<(), ChainError>>, Block)>();
211-
std::thread::spawn(move || {
212-
while let Some((notify, block)) = block_receiver.blocking_recv() {
213-
let _ = notify
214-
.send(blockchain.add_block_pipeline(block))
215-
.inspect_err(|_| tracing::error!("failed to notify caller"));
216-
}
217-
});
211+
std::thread::Builder::new()
212+
.name("block_executor".to_string())
213+
.spawn(move || {
214+
while let Some((notify, block)) = block_receiver.blocking_recv() {
215+
let _ = notify
216+
.send(blockchain.add_block_pipeline(block))
217+
.inspect_err(|_| tracing::error!("failed to notify caller"));
218+
}
219+
})
220+
.expect("Falied to spawn block_executor thread");
218221
block_worker_channel
219222
}
220223

0 commit comments

Comments
 (0)