Skip to content

Commit 1c0b23a

Browse files
committed
refactor: Move deterministic fail out of the instance manager loop
1 parent a7fd0fc commit 1c0b23a

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,26 @@ where
468468
let store_for_err = ctx.inputs.store.cheap_clone();
469469
let logger = ctx.state.logger.cheap_clone();
470470
let id_for_err = ctx.inputs.deployment.hash.clone();
471-
let mut should_try_unfail_deterministic = true;
472471
let mut should_try_unfail_non_deterministic = true;
473472

473+
// If a subgraph failed for deterministic reasons, before start indexing, we first
474+
// revert the deployment head. It should lead to the same result since the error was
475+
// deterministic.
476+
if let Some(current_ptr) = ctx.inputs.store.block_ptr()? {
477+
if let Some(parent_ptr) = ctx.inputs.triggers_adapter.parent_ptr(&current_ptr).await? {
478+
// This reverts the deployment head to the parent_ptr if
479+
// deterministic errors happened.
480+
//
481+
// There's no point in calling it if we have no current or parent block
482+
// pointers, because there would be: no block to revert to or to search
483+
// errors from (first execution).
484+
let _outcome = ctx
485+
.inputs
486+
.store
487+
.unfail_deterministic_error(&current_ptr, &parent_ptr)?;
488+
}
489+
}
490+
474491
// Exponential backoff that starts with two minutes and keeps
475492
// increasing its timeout exponentially until it reaches the ceiling.
476493
let mut backoff = ExponentialBackoff::new(MINUTE * 2, *SUBGRAPH_ERROR_RETRY_CEIL_SECS);
@@ -607,38 +624,6 @@ where
607624
let start = Instant::now();
608625
let deployment_failed = ctx.block_stream_metrics.deployment_failed.clone();
609626

610-
// If a subgraph failed for deterministic reasons, before processing a new block, we
611-
// revert the deployment head. It should lead to the same result since the error was
612-
// deterministic.
613-
//
614-
// As an optimization we check this only on the first run.
615-
if should_try_unfail_deterministic {
616-
should_try_unfail_deterministic = false;
617-
618-
if let Some(current_ptr) = ctx.inputs.store.block_ptr()? {
619-
if let Some(parent_ptr) =
620-
ctx.inputs.triggers_adapter.parent_ptr(&current_ptr).await?
621-
{
622-
// This reverts the deployment head to the parent_ptr if
623-
// deterministic errors happened.
624-
//
625-
// There's no point in calling it if we have no current or parent block
626-
// pointers, because there would be: no block to revert to or to search
627-
// errors from (first execution).
628-
let outcome = ctx
629-
.inputs
630-
.store
631-
.unfail_deterministic_error(&current_ptr, &parent_ptr)?;
632-
633-
if let UnfailOutcome::Unfailed = outcome {
634-
// If the unfail happened, we must restart the BlockStream so the
635-
// reverted block isn't skipped.
636-
break;
637-
}
638-
}
639-
}
640-
}
641-
642627
let res = process_block(
643628
&logger,
644629
ctx.inputs.triggers_adapter.cheap_clone(),

0 commit comments

Comments
 (0)