@@ -105,6 +105,7 @@ pub struct Batcher {
105105 current_min_max_fee : RwLock < U256 > ,
106106 amount_of_proofs_for_min_max_fee : usize ,
107107 min_bump_percentage : U256 ,
108+ balance_unlock_polling_interval_seconds : u64 ,
108109
109110 // Shared state access:
110111 // Two kinds of threads interact with the shared state:
@@ -331,6 +332,7 @@ impl Batcher {
331332 max_batch_proof_qty : config. batcher . max_batch_proof_qty ,
332333 amount_of_proofs_for_min_max_fee : config. batcher . amount_of_proofs_for_min_max_fee ,
333334 min_bump_percentage : U256 :: from ( config. batcher . min_bump_percentage ) ,
335+ balance_unlock_polling_interval_seconds : config. batcher . balance_unlock_polling_interval_seconds ,
334336 last_uploaded_batch_block : Mutex :: new ( last_uploaded_batch_block) ,
335337 pre_verification_is_enabled : config. batcher . pre_verification_is_enabled ,
336338 non_paying_config,
@@ -496,10 +498,10 @@ impl Batcher {
496498 }
497499
498500 /// Poll for BalanceUnlocked events from BatcherPaymentService contract.
499- /// Runs every 10 minutes and checks the last 100 blocks for events.
501+ /// Runs at configurable intervals and checks recent blocks for events (2x the polling interval) .
500502 /// When an event is detected, removes user's proofs from queue and resets UserState.
501503 pub async fn poll_balance_unlocked_events ( self : Arc < Self > ) -> Result < ( ) , BatcherError > {
502- let mut interval = tokio:: time:: interval ( tokio:: time:: Duration :: from_secs ( 20 ) ) ; // 10 minutes
504+ let mut interval = tokio:: time:: interval ( tokio:: time:: Duration :: from_secs ( self . balance_unlock_polling_interval_seconds ) ) ;
503505
504506 loop {
505507 interval. tick ( ) . await ;
@@ -521,8 +523,10 @@ impl Batcher {
521523 }
522524 } ;
523525
524- // Calculate the block range (last 100 blocks)
525- let from_block = current_block. saturating_sub ( U64 :: from ( 100 ) ) ;
526+ // Calculate the block range based on polling interval
527+ // Formula: interval / 12 * 2 (assuming 12-second block times, look back 2x the interval)
528+ let block_range = ( self . balance_unlock_polling_interval_seconds / 12 ) * 2 ;
529+ let from_block = current_block. saturating_sub ( U64 :: from ( block_range) ) ;
526530
527531 // Create filter for BalanceUnlocked events
528532 let filter = self . payment_service
0 commit comments