Skip to content

Commit 1d39f7d

Browse files
Fix: Block stream ignoring configured endBlock in specific cases (#6474)
* core: Fix subgraph scanning past endBlock when endBlock has no triggers * core: Fix max_end_block being None when data sources share the same endBlock
1 parent 3787b76 commit 1d39f7d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,15 @@ impl<S: SubgraphStore, AC: amp::Client> SubgraphInstanceManager<S, AC> {
399399
// when to stop processing them.
400400
// - Offchain data sources might require processing beyond the end block of
401401
// onchain data sources, so the subgraph needs to continue.
402-
let max_end_block: Option<BlockNumber> = if data_sources.len() == end_blocks.len() {
402+
//
403+
// Note: we explicitly check each data source rather than comparing lengths, because
404+
// `end_blocks` is a BTreeSet and deduplicates equal values, which would cause the
405+
// length comparison to fail when multiple data sources share the same `end_block`.
406+
let max_end_block: Option<BlockNumber> = if data_sources.iter().all(|d| {
407+
d.as_onchain()
408+
.and_then(|d: &C::DataSource| d.end_block())
409+
.is_some()
410+
}) {
403411
end_blocks.iter().max().cloned()
404412
} else {
405413
None

core/src/subgraph/runner/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,18 @@ where
555555
.observe(block.trigger_count() as f64);
556556
}
557557

558-
// Check if we should skip this block (optimization for blocks without triggers)
558+
// Check if we should skip this block (optimization for blocks without triggers).
559+
// Do not skip if max_end_block has been reached — fall through to process_block so the
560+
// block pointer is persisted and the existing max_end_block check in handle_action fires.
561+
let max_end_block_reached = self
562+
.inputs
563+
.max_end_block
564+
.is_some_and(|max| block_ptr.number >= max);
559565
if block.trigger_count() == 0
560566
&& self.state.skip_ptr_updates_timer.elapsed() <= SKIP_PTR_UPDATES_THRESHOLD
561567
&& !self.inputs.store.is_deployment_synced()
562568
&& !close_to_chain_head(&block_ptr, &self.inputs.chain.chain_head_ptr().await?, 1000)
569+
&& !max_end_block_reached
563570
{
564571
// Skip this block and continue with the same stream
565572
return Ok(RunnerState::AwaitingBlock { block_stream });

0 commit comments

Comments
 (0)