From a65dc5d5c46d607133d4c84b41011717c6cf96e8 Mon Sep 17 00:00:00 2001 From: akhercha Date: Sun, 3 Nov 2024 01:19:38 +0100 Subject: [PATCH] dev(better_theoros): Prevent overflows in indexer --- rust/theoros/src/services/indexer/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/theoros/src/services/indexer/mod.rs b/rust/theoros/src/services/indexer/mod.rs index 9e986c5..e81d15a 100644 --- a/rust/theoros/src/services/indexer/mod.rs +++ b/rust/theoros/src/services/indexer/mod.rs @@ -1,3 +1,5 @@ +use std::cmp::max; + use anyhow::{anyhow, bail, Context, Result}; use apibara_core::{ node::v1alpha2::DataFinality, @@ -61,7 +63,7 @@ impl IndexerService { current_block: u64, ) -> Result { let stream_config = Configuration::::default() - .with_starting_block(current_block - START_INDEXER_DELTA) + .with_starting_block(max(1, current_block.saturating_sub(START_INDEXER_DELTA))) .with_filter(|mut filter| { filter .with_header(HeaderFilter::weak())