@@ -574,7 +574,32 @@ impl BlockMinerThread {
574
574
) ;
575
575
self . reset_nonce_cache = false ;
576
576
577
- thread:: sleep ( self . config . miner . empty_mempool_sleep_time ) ;
577
+ // Pause the miner to wait for transactions to arrive
578
+ let now = Instant :: now ( ) ;
579
+ while now. elapsed ( ) < self . config . miner . empty_mempool_sleep_time {
580
+ if self . abort_flag . load ( Ordering :: SeqCst ) {
581
+ info ! ( "Miner interrupted while mining in order to shut down" ) ;
582
+ self . globals
583
+ . raise_initiative ( format ! ( "MiningFailure: aborted by node" ) ) ;
584
+ return Err ( ChainstateError :: MinerAborted . into ( ) ) ;
585
+ }
586
+
587
+ // Check if the burnchain tip has changed
588
+ let Ok ( sort_db) = SortitionDB :: open (
589
+ & self . config . get_burn_db_file_path ( ) ,
590
+ false ,
591
+ self . burnchain . pox_constants . clone ( ) ,
592
+ ) else {
593
+ error ! ( "Failed to open sortition DB. Will try mining again." ) ;
594
+ continue ;
595
+ } ;
596
+ if self . check_burn_tip_changed ( & sort_db) . is_err ( ) {
597
+ return Err ( NakamotoNodeError :: BurnchainTipChanged ) ;
598
+ }
599
+
600
+ thread:: sleep ( Duration :: from_millis ( ABORT_TRY_AGAIN_MS ) ) ;
601
+ }
602
+
578
603
break None ;
579
604
}
580
605
Err ( e) => {
@@ -685,6 +710,13 @@ impl BlockMinerThread {
685
710
686
711
thread:: sleep ( Duration :: from_millis ( ABORT_TRY_AGAIN_MS ) ) ;
687
712
713
+ if self . abort_flag . load ( Ordering :: SeqCst ) {
714
+ info ! ( "Miner interrupted while mining in order to shut down" ) ;
715
+ self . globals
716
+ . raise_initiative ( format ! ( "MiningFailure: aborted by node" ) ) ;
717
+ return Err ( ChainstateError :: MinerAborted . into ( ) ) ;
718
+ }
719
+
688
720
// Check if the burnchain tip has changed
689
721
let Ok ( sort_db) = SortitionDB :: open (
690
722
& self . config . get_burn_db_file_path ( ) ,
0 commit comments