Skip to content
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
53 changes: 32 additions & 21 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,27 +218,38 @@ impl Blockchain {
let (execution_result, account_updates_list) = std::thread::scope(|s| {
let max_queue_length_ref = &mut max_queue_length;
let (tx, rx) = channel();
let execution_handle = s.spawn(move || -> Result<_, ChainError> {
let execution_result = vm.execute_block_pipeline(block, tx, queue_length_ref)?;

// Validate execution went alright
validate_gas_used(&execution_result.receipts, &block.header)?;
validate_receipts_root(&block.header, &execution_result.receipts)?;
validate_requests_hash(&block.header, &chain_config, &execution_result.requests)?;

let exec_end_instant = Instant::now();
Ok((execution_result, exec_end_instant))
});
let merkleize_handle = s.spawn(move || -> Result<_, StoreError> {
let account_updates_list = self.handle_merkleization(
rx,
&parent_header,
queue_length_ref,
max_queue_length_ref,
)?;
let merkle_end_instant = Instant::now();
Ok((account_updates_list, merkle_end_instant))
});
let execution_handle = std::thread::Builder::new()
.name("block_executor_execution".to_string())
.spawn_scoped(s, move || -> Result<_, ChainError> {
let execution_result =
vm.execute_block_pipeline(block, tx, queue_length_ref)?;

// Validate execution went alright
validate_gas_used(&execution_result.receipts, &block.header)?;
validate_receipts_root(&block.header, &execution_result.receipts)?;
validate_requests_hash(
&block.header,
&chain_config,
&execution_result.requests,
)?;

let exec_end_instant = Instant::now();
Ok((execution_result, exec_end_instant))
})
.expect("Failed to spawn block_executor exec thread");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just for reference, these panics were already there, but hidden inside the spawn functions.

let merkleize_handle = std::thread::Builder::new()
.name("block_executor_merkleizer".to_string())
.spawn_scoped(s, move || -> Result<_, StoreError> {
let account_updates_list = self.handle_merkleization(
rx,
&parent_header,
queue_length_ref,
max_queue_length_ref,
)?;
let merkle_end_instant = Instant::now();
Ok((account_updates_list, merkle_end_instant))
})
.expect("Failed to spawn block_executor merkleizer thread");
(
execution_handle.join().unwrap_or_else(|_| {
Err(ChainError::Custom("execution thread panicked".to_string()))
Expand Down
17 changes: 10 additions & 7 deletions crates/networking/rpc/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,16 @@ pub fn start_block_executor(
) -> UnboundedSender<(oneshot::Sender<Result<(), ChainError>>, Block)> {
let (block_worker_channel, mut block_receiver) =
unbounded_channel::<(oneshot::Sender<Result<(), ChainError>>, Block)>();
std::thread::spawn(move || {
while let Some((notify, block)) = block_receiver.blocking_recv() {
let _ = notify
.send(blockchain.add_block_pipeline(block))
.inspect_err(|_| tracing::error!("failed to notify caller"));
}
});
std::thread::Builder::new()
.name("block_executor".to_string())
.spawn(move || {
while let Some((notify, block)) = block_receiver.blocking_recv() {
let _ = notify
.send(blockchain.add_block_pipeline(block))
.inspect_err(|_| tracing::error!("failed to notify caller"));
}
})
.expect("Falied to spawn block_executor thread");
block_worker_channel
}

Expand Down
Loading