@@ -504,61 +504,11 @@ impl<N: Network> Service<N> {
504504 return ;
505505 }
506506 }
507-
508- batch_from = batch_to - 1 ;
509507 }
510508
511509 info ! ( batch_count = iter. batch_count( ) , "Rewind completed" ) ;
512510 }
513511
514- /// Handles re-scanning of reorged blocks.
515- ///
516- /// Returns `true` on success, `false` if stream closed or terminal error occurred.
517- async fn handle_reorg_rescan (
518- tip : & mut N :: BlockResponse ,
519- common_ancestor : N :: BlockResponse ,
520- max_block_range : u64 ,
521- sender : & mpsc:: Sender < BlockScannerResult > ,
522- provider : & RobustProvider < N > ,
523- ) -> bool {
524- let tip_number = tip. header ( ) . number ( ) ;
525- let common_ancestor_block = common_ancestor. header ( ) . number ( ) ;
526- info ! (
527- block_number = %tip_number,
528- hash = %tip. header( ) . hash( ) ,
529- common_ancestor_block = %common_ancestor_block,
530- "Reorg detected"
531- ) ;
532-
533- if !sender. try_stream ( Notification :: ReorgDetected { common_ancestor } ) . await {
534- return false ;
535- }
536-
537- // Get the new tip block (same height as original tip, but new hash)
538- * tip = match provider. get_block_by_number ( tip_number. into ( ) ) . await {
539- Ok ( block) => block,
540- Err ( RobustProviderError :: BlockNotFound ( _) ) => {
541- panic ! ( "Block with number '{tip_number}' should exist post-reorg" ) ;
542- }
543- Err ( e) => {
544- error ! ( error = %e, "Terminal RPC call error, shutting down" ) ;
545- _ = sender. try_stream ( e) . await ;
546- return false ;
547- }
548- } ;
549-
550- // Re-scan only the affected range (from common_ancestor + 1 up to tip)
551- let rescan_from = common_ancestor_block + 1 ;
552-
553- for batch in BatchIterator :: forward ( rescan_from, tip_number, max_block_range) {
554- if !sender. try_stream ( batch) . await {
555- return false ;
556- }
557- }
558-
559- true
560- }
561-
562512 /// Handles re-scanning of reorged blocks.
563513 ///
564514 /// Returns `true` on success, `false` if stream closed or terminal error occurred.
@@ -599,18 +549,10 @@ impl<N: Network> Service<N> {
599549 // Re-scan only the affected range (from common_ancestor + 1 up to tip)
600550 let rescan_from = common_ancestor + 1 ;
601551
602- let mut rescan_batch_start = rescan_from;
603- while rescan_batch_start <= tip_number {
604- let rescan_batch_end = ( rescan_batch_start + max_block_range - 1 ) . min ( tip_number) ;
605-
606- if !sender. try_stream ( rescan_batch_start..=rescan_batch_end) . await {
552+ for batch in BatchIterator :: forward ( rescan_from, tip_number, max_block_range) {
553+ if !sender. try_stream ( batch) . await {
607554 return false ;
608555 }
609-
610- if rescan_batch_end == tip_number {
611- break ;
612- }
613- rescan_batch_start = rescan_batch_end + 1 ;
614556 }
615557
616558 true
0 commit comments