Skip to content
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
48 changes: 47 additions & 1 deletion madara/crates/client/block_production/src/executor/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,53 @@ impl ExecutorThread {
}
},
// Channel closed. Exit gracefully.
WaitTxBatchOutcome::Exit => return Ok(()),
// Before exiting, check if we have an executing block that needs to be closed.
// This ensures graceful shutdown closes the block using the executor's existing state.
WaitTxBatchOutcome::Exit => {
match state {
ExecutorThreadState::Executing(mut execution_state) => {
tracing::debug!(
"Shutting down executor, closing block block_n={}",
execution_state.exec_ctx.block_number
);

// Finalize the block to get execution summary
// This uses the executor's current state - no re-execution needed
match execution_state.executor.finalize() {
Ok(block_exec_summary) => {
// Send EndBlock message so main loop can close the block
if self
.replies_sender
.blocking_send(super::ExecutorMessage::EndBlock(Box::new(
block_exec_summary,
)))
.is_err()
{
// Receiver closed - main loop already shut down
// Block will remain preconfirmed and be handled on restart
tracing::warn!(
"Could not send EndBlock during shutdown, block will remain preconfirmed"
);
}
}
Err(e) => {
// Finalization failed - log error but continue shutdown
// Block will remain preconfirmed and be handled on restart
tracing::warn!(
"Failed to finalize block during shutdown: {:?}. Block will remain preconfirmed",
e
);
}
}
}
ExecutorThreadState::NewBlock(_) => {
// No block to close, just exit
tracing::debug!("Shutting down executor, no block to close");
}
}

return Ok(());
}
};

for (tx, additional_info) in taken {
Expand Down
Loading