From cac37cb5fe0aea98c274cbb573e960230660b8f7 Mon Sep 17 00:00:00 2001 From: Leonardo Yvens Date: Thu, 12 Mar 2026 15:04:20 +0000 Subject: [PATCH] fix(core): avoid redudant work when chain did not move --- crates/core/worker-datasets-raw/src/job_impl.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/core/worker-datasets-raw/src/job_impl.rs b/crates/core/worker-datasets-raw/src/job_impl.rs index 60bef7467..79f151825 100644 --- a/crates/core/worker-datasets-raw/src/job_impl.rs +++ b/crates/core/worker-datasets-raw/src/job_impl.rs @@ -289,6 +289,7 @@ pub async fn execute( // // We wrap the loop in a block to handle errors and emit failure events. let materialize_result: Result<(), Error> = async { + let mut prev_latest_block: Option = None; loop { let Some(latest_block) = client .latest_block(finalized_blocks_only) @@ -299,6 +300,13 @@ pub async fn execute( timer.tick().await; continue; }; + + // Skip recomputing missing ranges if latest_block hasn't changed. + if Some(latest_block) == prev_latest_block { + timer.tick().await; + continue; + } + if latest_block < start { // Start not yet reached, wait for more data timer.tick().await; @@ -337,6 +345,9 @@ pub async fn execute( // If there are no ranges then there is no more work to do, check materialize end condition. if missing_dataset_ranges.is_empty() { + // Work for this block is complete + prev_latest_block = Some(latest_block); + // If we've reached the configured end block, stop completely and return. if let Some(end) = end && end <= latest_block