Skip to content
Merged
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
26 changes: 23 additions & 3 deletions crates/engine/tree/src/tree/payload_processor/prewarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,19 @@ where
});
}

/// Returns true if prewarming was terminated and no more transactions should be prewarmed.
fn is_execution_terminated(&self) -> bool {
self.ctx.terminate_execution.load(Ordering::Relaxed)
}

/// If configured and the tx returned proof targets, emit the targets the transaction produced
fn send_multi_proof_targets(&self, targets: Option<MultiProofTargets>) {
if self.is_execution_terminated() {
// if execution is already terminated then we dont need to send more proof fetch
// messages
return
}

if let Some((proof_targets, to_multi_proof)) = targets.zip(self.to_multi_proof.as_ref()) {
let _ = to_multi_proof.send(MultiProofMessage::PrefetchProofs(proof_targets));
}
Expand Down Expand Up @@ -308,6 +319,7 @@ where
match event {
PrewarmTaskEvent::TerminateTransactionExecution => {
// stop tx processing
debug!(target: "engine::tree::prewarm", "Terminating prewarm execution");
self.ctx.terminate_execution.store(true, Ordering::Relaxed);
}
PrewarmTaskEvent::Outcome { proof_targets } => {
Expand Down Expand Up @@ -338,7 +350,7 @@ where
}
}

trace!(target: "engine::tree::prewarm", "Completed prewarm execution");
debug!(target: "engine::tree::prewarm", "Completed prewarm execution");

// save caches and finish
if let Some(Some(state)) = final_block_output {
Expand Down Expand Up @@ -460,15 +472,16 @@ where
debug_span!(target: "engine::tree::payload_processor::prewarm", "prewarm tx", index, tx_hash=%tx.tx().tx_hash())
.entered();

// create the tx env
let start = Instant::now();

// If the task was cancelled, stop execution, send an empty result to notify the task,
// and exit.
if terminate_execution.load(Ordering::Relaxed) {
let _ = sender.send(PrewarmTaskEvent::Outcome { proof_targets: None });
break
}

// create the tx env
let start = Instant::now();
let res = match evm.transact(&tx) {
Ok(res) => res,
Err(err) => {
Expand All @@ -489,6 +502,13 @@ where

drop(_enter);

// If the task was cancelled, stop execution, send an empty result to notify the task,
// and exit.
if terminate_execution.load(Ordering::Relaxed) {
let _ = sender.send(PrewarmTaskEvent::Outcome { proof_targets: None });
break
}

// Only send outcome for transactions after the first txn
// as the main execution will be just as fast
if index > 0 {
Expand Down
Loading