@@ -858,28 +858,30 @@ impl<N: Network> Service<N> {
858858 mut rx : mpsc:: Receiver < BlockNumber > ,
859859 end_num : BlockNumber ,
860860 ) {
861- let mut min_seen_below_end : Option < BlockNumber > = None ;
862- while let Ok ( live_blocks ) = rx . try_recv ( ) {
863- if live_blocks < end_num {
864- min_seen_below_end =
865- Some ( min_seen_below_end . map_or ( live_blocks , |latest_smallest_seen| {
866- latest_smallest_seen . min ( live_blocks )
867- } ) ) ;
861+ let Ok ( mut min_live_block ) = rx . try_recv ( ) else {
862+ return ;
863+ } ;
864+
865+ while let Ok ( live_block ) = rx . try_recv ( ) {
866+ if live_block < min_live_block {
867+ min_live_block = live_block ;
868868 }
869869 }
870870
871- if let Some ( reorg_start) = min_seen_below_end {
872- let max_read = self . config . blocks_read_per_epoch as u64 ;
871+ if min_live_block >= end_num {
872+ return ;
873+ }
873874
874- self . send_to_subscriber ( BlockRangeMessage :: Status ( ScannerStatus :: ReorgDetected ) ) . await ;
875+ let reorg_start = min_live_block;
876+ let max_read = self . config . blocks_read_per_epoch as u64 ;
875877
876- let mut current = reorg_start ;
877- // respect max read
878- while current <= end_num {
879- let batch_end = current . saturating_add ( max_read - 1 ) . min ( end_num) ;
880- self . send_to_subscriber ( BlockRangeMessage :: Data ( current..=batch_end ) ) . await ;
881- current = batch_end + 1 ;
882- }
878+ self . send_to_subscriber ( BlockRangeMessage :: Status ( ScannerStatus :: ReorgDetected ) ) . await ;
879+
880+ let mut current = reorg_start ;
881+ while current <= end_num {
882+ let batch_end = current. saturating_add ( max_read - 1 ) . min ( end_num ) ;
883+ self . send_to_subscriber ( BlockRangeMessage :: Data ( current..= batch_end) ) . await ;
884+ current = batch_end + 1 ;
883885 }
884886 }
885887
0 commit comments