@@ -79,14 +79,22 @@ async fn main() -> Result<(), MainError> {
7979 rlimit:: increase_nofile_limit ( 10240 ) . unwrap ( ) ;
8080 rlimit:: increase_nofile_limit ( u64:: MAX ) . unwrap ( ) ;
8181
82+ let last_block_height = namada_service:: get_last_block ( & client)
83+ . await
84+ . into_rpc_error ( ) ?;
85+ let crawler_state = db_service:: try_get_chain_crawler_state ( & conn)
86+ . await
87+ . into_db_error ( ) ?;
88+
89+ let limit = last_block_height - config. storage_read_past_height_limit ;
90+
91+ let can_continue =
92+ crawler_state. map ( |s| ( s. last_processed_block >= limit, s) ) ;
93+ let can_backfill = config. backfill_from . map ( |bf| ( bf >= limit, bf) ) ;
94+
8295 // See if we can start from existing crawler_state
83- let crawler_state = match (
84- config. backfill_from ,
85- db_service:: try_get_chain_crawler_state ( & conn)
86- . await
87- . into_db_error ( ) ?,
88- ) {
89- ( Some ( height) , _) => {
96+ let crawler_state = match ( can_backfill, can_continue) {
97+ ( Some ( ( true , height) ) , _) => {
9098 tracing:: warn!( "Backfilling from block height {}" , height) ;
9199 Some ( ChainCrawlerState {
92100 last_processed_block : height,
@@ -95,7 +103,7 @@ async fn main() -> Result<(), MainError> {
95103 timestamp : 0 ,
96104 } )
97105 }
98- ( None , Some ( crawler_state) ) => {
106+ ( None , Some ( ( true , crawler_state) ) ) => {
99107 tracing:: debug!(
100108 "Found chain crawler state, attempting initial crawl at block \
101109 {}...",
@@ -151,9 +159,11 @@ async fn main() -> Result<(), MainError> {
151159 }
152160 }
153161 }
154- ( None , None ) => {
155- tracing:: debug!(
156- "No chain crawler state found, starting from initial_query..."
162+ _ => {
163+ tracing:: warn!(
164+ "Couldn't continue from the last state. Cannot query more \
165+ than {} blocks in the past. Starting from initial_query...",
166+ config. storage_read_past_height_limit
157167 ) ;
158168 None
159169 }
0 commit comments