Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Wait until in nakamoto to shutdown 2.x block downloader #5676 #5735

Merged
merged 19 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e667b82
fix: only shut off the epoch2x state machines once the Stacks tip is …
jcnelson Jan 22, 2025
413a89c
Merge branch 'develop' into fix/5676
jcnelson Jan 22, 2025
f035175
chore: make the epoch2x state machine check testable, and extend Test…
jcnelson Jan 23, 2025
fb18290
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jcnelson Jan 23, 2025
683586f
Merge branch 'develop' into fix/5676
jcnelson Jan 23, 2025
b060bce
Merge branch 'fix/5676' of https://github.com/stacks-network/stacks-c…
jcnelson Jan 23, 2025
4b5402c
Merge branch 'develop' into fix/5676
jcnelson Jan 23, 2025
56e0581
chore: address PR feedback
jcnelson Jan 24, 2025
25515f9
Merge branch 'fix/5676' of https://github.com/stacks-network/stacks-c…
jcnelson Jan 24, 2025
27ba315
Merge branch 'develop' into fix/5676
jcnelson Jan 24, 2025
5d81c61
Merge branch 'develop' into fix/5676
aldur Jan 29, 2025
3420de3
chore: honor config option to force nakamoto state machine transition
jcnelson Feb 4, 2025
d5201e7
Merge branch 'fix/5676' of https://github.com/stacks-network/stacks-c…
jcnelson Feb 4, 2025
e7df7a4
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jcnelson Feb 4, 2025
57f44d7
Merge branch 'develop' into fix/5676
jcnelson Feb 4, 2025
0915796
chore: fix failing unit test
jcnelson Feb 5, 2025
d371d38
Merge branch 'develop' into fix/5676
jcnelson Feb 5, 2025
d6a1c64
Merge branch 'develop' into fix/5676
jcnelson Feb 5, 2025
d5308ce
Merge branch 'develop' into fix/5676
jcnelson Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions stackslib/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3313,6 +3313,10 @@ pub mod test {

let old_tip = self.network.stacks_tip.clone();

// make sure the right state machines run
let epoch2_passes = self.network.epoch2_state_machine_passes;
let nakamoto_passes = self.network.nakamoto_state_machine_passes;

let ret = self.network.run(
&indexer,
&sortdb,
Expand All @@ -3325,6 +3329,19 @@ pub mod test {
&RPCHandlerArgs::default(),
);

if self.network.get_current_epoch().epoch_id >= StacksEpochId::Epoch30 {
assert_eq!(
self.network.nakamoto_state_machine_passes,
nakamoto_passes + 1
);
}
if self
.network
.need_epoch2_state_machines(self.network.get_current_epoch().epoch_id)
{
assert_eq!(self.network.epoch2_state_machine_passes, epoch2_passes + 1);
}
jcnelson marked this conversation as resolved.
Show resolved Hide resolved

self.sortdb = Some(sortdb);
self.stacks_node = Some(stacks_node);
self.mempool = Some(mempool);
Expand Down Expand Up @@ -3393,6 +3410,10 @@ pub mod test {

let old_tip = self.network.stacks_tip.clone();

// make sure the right state machines run
let epoch2_passes = self.network.epoch2_state_machine_passes;
let nakamoto_passes = self.network.nakamoto_state_machine_passes;

let ret = self.network.run(
&indexer,
&sortdb,
Expand All @@ -3405,6 +3426,19 @@ pub mod test {
&RPCHandlerArgs::default(),
);

if self.network.get_current_epoch().epoch_id >= StacksEpochId::Epoch30 {
assert_eq!(
self.network.nakamoto_state_machine_passes,
nakamoto_passes + 1
);
}
if self
.network
.need_epoch2_state_machines(self.network.get_current_epoch().epoch_id)
{
assert_eq!(self.network.epoch2_state_machine_passes, epoch2_passes + 1);
}

self.sortdb = Some(sortdb);
self.stacks_node = Some(stacks_node);
self.mempool = Some(mempool);
Expand Down
28 changes: 22 additions & 6 deletions stackslib/src/net/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ pub struct PeerNetwork {
// how many downloader passes have we done?
pub num_downloader_passes: u64,

// number of epoch2 state machine passes
pub(crate) epoch2_state_machine_passes: u128,

// number of nakamoto state machine passes
pub(crate) nakamoto_state_machine_passes: u128,

// to whom did we send a block or microblock stream as part of our anti-entropy protocol, and
// when did we send it?
antientropy_blocks: HashMap<NeighborKey, HashMap<StacksBlockId, u64>>,
Expand Down Expand Up @@ -593,6 +599,8 @@ impl PeerNetwork {
num_state_machine_passes: 0,
num_inv_sync_passes: 0,
num_downloader_passes: 0,
epoch2_state_machine_passes: 0,
nakamoto_state_machine_passes: 0,

antientropy_blocks: HashMap::new(),
antientropy_microblocks: HashMap::new(),
Expand Down Expand Up @@ -3578,6 +3586,15 @@ impl PeerNetwork {
}
}

/// Check to see if we need to run the epoch 2.x state machines.
/// This will be true if we're either in epoch 2.5 or lower, OR, if we're in epoch 3.0 or
/// higher AND the Stacks tip is not yet a Nakamoto block. This latter condition indicates
/// that the epoch 2.x state machines are still needed to download the final epoch 2.x blocks.
pub(crate) fn need_epoch2_state_machines(&self, epoch_id: StacksEpochId) -> bool {
epoch_id < StacksEpochId::Epoch30
|| (epoch_id >= StacksEpochId::Epoch30 && !self.stacks_tip.is_nakamoto)
}

/// Do the actual work in the state machine.
/// Return true if we need to prune connections.
/// This will call the epoch-appropriate network worker
Expand Down Expand Up @@ -3606,12 +3623,7 @@ impl PeerNetwork {

// in Nakamoto epoch, but we might still be doing epoch 2.x things since Nakamoto does
// not begin on a reward cycle boundary.
if cur_epoch.epoch_id == StacksEpochId::Epoch30
&& (self.burnchain_tip.block_height
<= cur_epoch.start_height
+ u64::from(self.burnchain.pox_constants.reward_cycle_length)
|| self.connection_opts.force_nakamoto_epoch_transition)
{
if self.need_epoch2_state_machines(cur_epoch.epoch_id) {
debug!(
"{:?}: run Epoch 2.x work loop in Nakamoto epoch",
self.get_local_peer()
Expand Down Expand Up @@ -3660,6 +3672,8 @@ impl PeerNetwork {
ibd: bool,
network_result: &mut NetworkResult,
) {
self.nakamoto_state_machine_passes += 1;

// always do an inv sync
let learned = self.do_network_inv_sync_nakamoto(sortdb, ibd);
debug!(
Expand Down Expand Up @@ -3709,6 +3723,8 @@ impl PeerNetwork {
ibd: bool,
network_result: &mut NetworkResult,
) -> bool {
self.epoch2_state_machine_passes += 1;

// do some Actual Work(tm)
let mut do_prune = false;
let mut did_cycle = false;
Expand Down