@@ -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 ( ) ,
@@ -3578,6 +3586,15 @@ impl PeerNetwork {
3578
3586
}
3579
3587
}
3580
3588
3589
+ /// Check to see if we need to run the epoch 2.x state machines.
3590
+ /// This will be true if we're either in epoch 2.5 or lower, OR, if we're in epoch 3.0 or
3591
+ /// higher AND the Stacks tip is not yet a Nakamoto block. This latter condition indicates
3592
+ /// that the epoch 2.x state machines are still needed to download the final epoch 2.x blocks.
3593
+ pub ( crate ) fn need_epoch2_state_machines ( & self , epoch_id : StacksEpochId ) -> bool {
3594
+ epoch_id < StacksEpochId :: Epoch30
3595
+ || ( epoch_id >= StacksEpochId :: Epoch30 && !self . stacks_tip . is_nakamoto )
3596
+ }
3597
+
3581
3598
/// Do the actual work in the state machine.
3582
3599
/// Return true if we need to prune connections.
3583
3600
/// This will call the epoch-appropriate network worker
@@ -3606,7 +3623,7 @@ impl PeerNetwork {
3606
3623
3607
3624
// in Nakamoto epoch, but we might still be doing epoch 2.x things since Nakamoto does
3608
3625
// not begin on a reward cycle boundary.
3609
- if cur_epoch . epoch_id >= StacksEpochId :: Epoch30 && ! self . stacks_tip . is_nakamoto {
3626
+ if self . need_epoch2_state_machines ( cur_epoch . epoch_id ) {
3610
3627
debug ! (
3611
3628
"{:?}: run Epoch 2.x work loop in Nakamoto epoch" ,
3612
3629
self . get_local_peer( )
@@ -3655,6 +3672,8 @@ impl PeerNetwork {
3655
3672
ibd : bool ,
3656
3673
network_result : & mut NetworkResult ,
3657
3674
) {
3675
+ self . nakamoto_state_machine_passes += 1 ;
3676
+
3658
3677
// always do an inv sync
3659
3678
let learned = self . do_network_inv_sync_nakamoto ( sortdb, ibd) ;
3660
3679
debug ! (
@@ -3704,6 +3723,8 @@ impl PeerNetwork {
3704
3723
ibd : bool ,
3705
3724
network_result : & mut NetworkResult ,
3706
3725
) -> bool {
3726
+ self . epoch2_state_machine_passes += 1 ;
3727
+
3707
3728
// do some Actual Work(tm)
3708
3729
let mut do_prune = false ;
3709
3730
let mut did_cycle = false ;
0 commit comments