Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions madara/crates/client/block_production/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ pub enum ExecutorMessage {
exec_ctx: BlockExecutionContext,
},
BatchExecuted(BatchExecutionResult),
/// Normal block closing (block time reached, block full, or explicit CloseBlock).
EndBlock(Box<BlockExecutionSummary>),
/// Final block closing during graceful shutdown. Only sent when executor detects shutdown.
EndFinalBlock(Box<BlockExecutionSummary>),
}

#[derive(Default, Debug)]
Expand Down
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 EndFinalBlock message so main loop can close the block during shutdown
if self
.replies_sender
.blocking_send(super::ExecutorMessage::EndFinalBlock(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 EndFinalBlock 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