@@ -3560,8 +3560,8 @@ impl PeerNetwork {
3560
3560
let prune = if cur_epoch. epoch_id >= StacksEpochId :: Epoch30 {
3561
3561
debug ! ( "{:?}: run Nakamoto work loop" , self . get_local_peer( ) ) ;
3562
3562
3563
- // in Nakamoto epoch, so do Nakamoto things
3564
- let prune = self . do_network_work_nakamoto (
3563
+ // in Nakamoto epoch, so we can always prune
3564
+ self . do_network_work_nakamoto (
3565
3565
burnchain_height,
3566
3566
sortdb,
3567
3567
chainstate,
@@ -3593,9 +3593,10 @@ impl PeerNetwork {
3593
3593
"{:?}: ran Epoch 2.x work loop in Nakamoto epoch" ,
3594
3594
self . get_local_peer( )
3595
3595
) ;
3596
- prune || epoch2_prune
3596
+ epoch2_prune
3597
3597
} else {
3598
- prune
3598
+ // we can always prune in Nakamoto, since all state machines pin their connections
3599
+ true
3599
3600
}
3600
3601
} else {
3601
3602
// in epoch 2.x, so do epoch 2.x things
@@ -3623,89 +3624,41 @@ impl PeerNetwork {
3623
3624
chainstate : & mut StacksChainState ,
3624
3625
ibd : bool ,
3625
3626
network_result : & mut NetworkResult ,
3626
- ) -> bool {
3627
- // do some Actual Work(tm)
3628
- let mut do_prune = false ;
3629
- let mut did_cycle = false ;
3630
-
3631
- while !did_cycle {
3632
- // always do an inv sync
3633
- let learned = self . do_network_inv_sync_nakamoto ( sortdb, ibd) ;
3634
- debug ! (
3635
- "{:?}: network work state is {:?}" ,
3636
- self . get_local_peer( ) ,
3637
- & self . nakamoto_work_state;
3638
- "learned_new_blocks?" => learned
3639
- ) ;
3640
-
3641
- // always do block download
3642
- let new_blocks = self
3643
- . do_network_block_sync_nakamoto ( burnchain_height, sortdb, chainstate, ibd)
3644
- . map_err ( |e| {
3645
- warn ! (
3646
- "{:?}: Failed to perform Nakamoto block sync: {:?}" ,
3647
- & self . get_local_peer( ) ,
3648
- & e
3649
- ) ;
3650
- e
3651
- } )
3652
- . unwrap_or ( HashMap :: new ( ) ) ;
3653
-
3654
- network_result. consume_nakamoto_blocks ( new_blocks) ;
3655
-
3656
- let cur_state = self . nakamoto_work_state ;
3657
- match self . nakamoto_work_state {
3658
- PeerNetworkWorkState :: GetPublicIP => {
3659
- if cfg ! ( test) && self . connection_opts . disable_natpunch {
3660
- self . nakamoto_work_state = PeerNetworkWorkState :: BlockDownload ;
3661
- } else {
3662
- // (re)determine our public IP address
3663
- let done = self . do_get_public_ip ( ) ;
3664
- if done {
3665
- self . nakamoto_work_state = PeerNetworkWorkState :: BlockDownload ;
3666
- }
3667
- }
3668
- }
3669
- PeerNetworkWorkState :: BlockInvSync => {
3670
- // this state is useless in Nakamoto since we're always doing inv-syncs
3671
- self . nakamoto_work_state = PeerNetworkWorkState :: BlockDownload ;
3672
- }
3673
- PeerNetworkWorkState :: BlockDownload => {
3674
- // this state is useless in Nakamoto since we're always doing download-syncs
3675
- self . nakamoto_work_state = PeerNetworkWorkState :: AntiEntropy ;
3676
- }
3677
- PeerNetworkWorkState :: AntiEntropy => {
3678
- debug ! (
3679
- "{:?}: Block anti-entropy for Nakamoto is not yet implemented" ,
3680
- self . get_local_peer( )
3681
- ) ;
3682
- self . nakamoto_work_state = PeerNetworkWorkState :: Prune ;
3683
- }
3684
- PeerNetworkWorkState :: Prune => {
3685
- // did one pass
3686
- did_cycle = true ;
3687
- do_prune = true ;
3627
+ ) {
3628
+ // always do an inv sync
3629
+ let learned = self . do_network_inv_sync_nakamoto ( sortdb, ibd) ;
3630
+ debug ! (
3631
+ "{:?}: network work state is {:?}" ,
3632
+ self . get_local_peer( ) ,
3633
+ & self . nakamoto_work_state;
3634
+ "learned_new_blocks?" => learned
3635
+ ) ;
3688
3636
3689
- // restart
3690
- self . nakamoto_work_state = PeerNetworkWorkState :: GetPublicIP ;
3691
- }
3692
- }
3637
+ // always do block download
3638
+ let new_blocks = self
3639
+ . do_network_block_sync_nakamoto ( burnchain_height, sortdb, chainstate, ibd)
3640
+ . map_err ( |e| {
3641
+ warn ! (
3642
+ "{:?}: Failed to perform Nakamoto block sync: {:?}" ,
3643
+ & self . get_local_peer( ) ,
3644
+ & e
3645
+ ) ;
3646
+ e
3647
+ } )
3648
+ . unwrap_or ( HashMap :: new ( ) ) ;
3693
3649
3694
- if self . nakamoto_work_state == cur_state {
3695
- // only break early if we can't make progress
3696
- break ;
3697
- }
3698
- }
3650
+ network_result. consume_nakamoto_blocks ( new_blocks) ;
3699
3651
3700
- if did_cycle {
3701
- self . num_state_machine_passes += 1 ;
3702
- debug ! (
3703
- "{:?}: Finished full p2p state-machine pass for Nakamoto ({})" ,
3704
- & self . local_peer, self . num_state_machine_passes
3705
- ) ;
3652
+ // make sure our public IP is fresh (this self-throttles if we recently learned it).
3653
+ if !self . connection_opts . disable_natpunch {
3654
+ self . do_get_public_ip ( ) ;
3706
3655
}
3707
3656
3708
- do_prune
3657
+ self . num_state_machine_passes += 1 ;
3658
+ debug ! (
3659
+ "{:?}: Finished full p2p state-machine pass for Nakamoto ({})" ,
3660
+ & self . local_peer, self . num_state_machine_passes
3661
+ ) ;
3709
3662
}
3710
3663
3711
3664
/// Do the actual work in the state machine.
0 commit comments