@@ -30,6 +30,8 @@ const RETRY_INTERVAL: Duration = Duration::from_secs(5);
3030const BLOCK_BATCH_SIZE : u64 = 100 ;
3131/// How much to wait before polling the next latest block
3232const POLL_INTERVAL : Duration = Duration :: from_secs ( 2 ) ;
33+ /// Retry last N blocks
34+ const RETRY_PREVIOUS_BLOCKS : u64 = 100 ;
3335
3436#[ derive( Debug , Clone ) ]
3537pub struct BlockRange {
@@ -194,15 +196,13 @@ pub async fn watch_blocks_wrapper(
194196 chain_state : BlockchainState ,
195197 latest_safe_block : BlockNumber ,
196198 tx : mpsc:: Sender < BlockRange > ,
197- retry_previous_blocks : u64 ,
198199) {
199200 let mut last_safe_block_processed = latest_safe_block;
200201 loop {
201202 if let Err ( e) = watch_blocks (
202203 chain_state. clone ( ) ,
203204 & mut last_safe_block_processed,
204205 tx. clone ( ) ,
205- retry_previous_blocks,
206206 )
207207 . in_current_span ( )
208208 . await
@@ -221,7 +221,6 @@ pub async fn watch_blocks(
221221 chain_state : BlockchainState ,
222222 last_safe_block_processed : & mut BlockNumber ,
223223 tx : mpsc:: Sender < BlockRange > ,
224- retry_previous_blocks : u64 ,
225224) -> Result < ( ) > {
226225 tracing:: info!( "Watching blocks to handle new events" ) ;
227226
@@ -230,7 +229,7 @@ pub async fn watch_blocks(
230229
231230 let latest_safe_block = get_latest_safe_block ( & chain_state) . in_current_span ( ) . await ;
232231 if latest_safe_block > * last_safe_block_processed {
233- let mut from = latest_safe_block. saturating_sub ( retry_previous_blocks ) ;
232+ let mut from = latest_safe_block. saturating_sub ( RETRY_PREVIOUS_BLOCKS ) ;
234233
235234 // In normal situation, the difference between latest and last safe block should not be more than 2-3 (for arbitrum it can be 10)
236235 // TODO: add a metric for this in separate PR. We need alerts
0 commit comments