From 40be104949471c33112e57372e9fbca792302ab6 Mon Sep 17 00:00:00 2001 From: Vaclav Barta Date: Tue, 2 Apr 2024 10:33:55 +0200 Subject: [PATCH] checking requested against actual end block --- state-reconstruct-fetcher/src/l1_fetcher.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/state-reconstruct-fetcher/src/l1_fetcher.rs b/state-reconstruct-fetcher/src/l1_fetcher.rs index e3f4386..d65df2d 100644 --- a/state-reconstruct-fetcher/src/l1_fetcher.rs +++ b/state-reconstruct-fetcher/src/l1_fetcher.rs @@ -225,7 +225,7 @@ impl L1Fetcher { hash_tx: mpsc::Sender, cancellation_token: CancellationToken, mut current_l1_block_number: U64, - mut end_block: Option, + max_end_block: Option, disable_polling: bool, ) -> Result> { let metrics = self.metrics.clone(); @@ -236,6 +236,7 @@ impl L1Fetcher { async move { let mut latest_l2_block_number = U256::zero(); let mut previous_hash = None; + let mut end_block: Option = None; loop { // Break on the receivement of a `ctrl_c` signal. if cancellation_token.is_cancelled() { @@ -251,7 +252,17 @@ impl L1Fetcher { .await { if let Some(found_block) = new_end { - if let Some(end_block_number) = found_block.number { + if let Some(ebn) = found_block.number { + let end_block_number = + if let Some(end_block_limit) = max_end_block { + if end_block_limit < ebn { + end_block_limit + } else { + ebn + } + } else { + ebn + }; end_block = Some(end_block_number); metrics.lock().await.last_l1_block = end_block_number.as_u64(); }