@@ -423,6 +423,12 @@ pub struct PeerNetwork {
423
423
// how many downloader passes have we done?
424
424
pub num_downloader_passes : u64 ,
425
425
426
+ // number of epoch2 state machine passes
427
+ pub ( crate ) epoch2_state_machine_passes : u128 ,
428
+
429
+ // number of nakamoto state machine passes
430
+ pub ( crate ) nakamoto_state_machine_passes : u128 ,
431
+
426
432
// to whom did we send a block or microblock stream as part of our anti-entropy protocol, and
427
433
// when did we send it?
428
434
antientropy_blocks : HashMap < NeighborKey , HashMap < StacksBlockId , u64 > > ,
@@ -593,6 +599,8 @@ impl PeerNetwork {
593
599
num_state_machine_passes : 0 ,
594
600
num_inv_sync_passes : 0 ,
595
601
num_downloader_passes : 0 ,
602
+ epoch2_state_machine_passes : 0 ,
603
+ nakamoto_state_machine_passes : 0 ,
596
604
597
605
antientropy_blocks : HashMap :: new ( ) ,
598
606
antientropy_microblocks : HashMap :: new ( ) ,
@@ -3554,6 +3562,15 @@ impl PeerNetwork {
3554
3562
}
3555
3563
}
3556
3564
3565
+ /// Check to see if we need to run the epoch 2.x state machines.
3566
+ /// This will be true if we're either in epoch 2.5 or lower, OR, if we're in epoch 3.0 or
3567
+ /// higher AND the Stacks tip is not yet a Nakamoto block. This latter condition indicates
3568
+ /// that the epoch 2.x state machines are still needed to download the final epoch 2.x blocks.
3569
+ pub ( crate ) fn need_epoch2_state_machines ( & self , epoch_id : StacksEpochId ) -> bool {
3570
+ epoch_id < StacksEpochId :: Epoch30
3571
+ || ( epoch_id >= StacksEpochId :: Epoch30 && !self . stacks_tip . is_nakamoto )
3572
+ }
3573
+
3557
3574
/// Do the actual work in the state machine.
3558
3575
/// Return true if we need to prune connections.
3559
3576
/// This will call the epoch-appropriate network worker
@@ -3582,11 +3599,8 @@ impl PeerNetwork {
3582
3599
3583
3600
// in Nakamoto epoch, but we might still be doing epoch 2.x things since Nakamoto does
3584
3601
// not begin on a reward cycle boundary.
3585
- if cur_epoch. epoch_id == StacksEpochId :: Epoch30
3586
- && ( self . burnchain_tip . block_height
3587
- <= cur_epoch. start_height
3588
- + u64:: from ( self . burnchain . pox_constants . reward_cycle_length )
3589
- || self . connection_opts . force_nakamoto_epoch_transition )
3602
+ if self . need_epoch2_state_machines ( cur_epoch. epoch_id )
3603
+ || self . connection_opts . force_nakamoto_epoch_transition
3590
3604
{
3591
3605
debug ! (
3592
3606
"{:?}: run Epoch 2.x work loop in Nakamoto epoch" ,
@@ -3636,6 +3650,8 @@ impl PeerNetwork {
3636
3650
ibd : bool ,
3637
3651
network_result : & mut NetworkResult ,
3638
3652
) {
3653
+ self . nakamoto_state_machine_passes += 1 ;
3654
+
3639
3655
// always do an inv sync
3640
3656
let learned = self . do_network_inv_sync_nakamoto ( sortdb, ibd) ;
3641
3657
debug ! (
@@ -3683,6 +3699,8 @@ impl PeerNetwork {
3683
3699
ibd : bool ,
3684
3700
network_result : & mut NetworkResult ,
3685
3701
) -> bool {
3702
+ self . epoch2_state_machine_passes += 1 ;
3703
+
3686
3704
// do some Actual Work(tm)
3687
3705
let mut do_prune = false ;
3688
3706
let mut did_cycle = false ;
0 commit comments