From a39318d1e7a533e6d204a8d1748ed0bb6187a599 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Tue, 4 Jun 2024 10:25:16 -0400 Subject: [PATCH] WIP: no idea what I am doing Signed-off-by: Jacinta Ferrant --- .../stacks-node/src/nakamoto_node/miner.rs | 5 ++- .../stacks-node/src/nakamoto_node/relayer.rs | 33 +++++++++++-------- .../src/tests/nakamoto_integrations.rs | 22 +++++++++---- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/testnet/stacks-node/src/nakamoto_node/miner.rs b/testnet/stacks-node/src/nakamoto_node/miner.rs index c411f348f65..8441fd17365 100644 --- a/testnet/stacks-node/src/nakamoto_node/miner.rs +++ b/testnet/stacks-node/src/nakamoto_node/miner.rs @@ -67,7 +67,10 @@ pub enum MinerDirective { burnchain_tip: BlockSnapshot, }, /// The miner should try to continue their tenure if they are the active miner - ContinueTenure { new_burn_view: ConsensusHash }, + ContinueTenure { + parent_tenure_start: StacksBlockId, + new_burn_view: ConsensusHash, + }, /// The miner did not win sortition StopTenure, } diff --git a/testnet/stacks-node/src/nakamoto_node/relayer.rs b/testnet/stacks-node/src/nakamoto_node/relayer.rs index 2a757dc8e5c..c2a86e09429 100644 --- a/testnet/stacks-node/src/nakamoto_node/relayer.rs +++ b/testnet/stacks-node/src/nakamoto_node/relayer.rs @@ -341,6 +341,7 @@ impl RelayerThread { } } else { MinerDirective::ContinueTenure { + parent_tenure_start: committed_index_hash, new_burn_view: consensus_hash, } } @@ -650,7 +651,11 @@ impl RelayerThread { Ok(()) } - fn continue_tenure(&mut self, new_burn_view: ConsensusHash) -> Result<(), NakamotoNodeError> { + fn continue_tenure( + &mut self, + parent_tenure_start: StacksBlockId, + new_burn_view: ConsensusHash, + ) -> Result<(), NakamotoNodeError> { if let Err(e) = self.stop_tenure() { error!("Relayer: Failed to stop tenure: {:?}", e); return Ok(()); @@ -672,10 +677,11 @@ impl RelayerThread { "block_snapshot_winning_block_txid" => %block_snapshot.winning_block_txid ); return Ok(()); + } else { + debug!("Relayer: the miner won the last sortition. Continuing tenure."); }; - match self.start_new_tenure( - block_snapshot.get_canonical_stacks_block_id(), + parent_tenure_start, block_snapshot, MinerReason::Extended { burn_view_consensus_hash: new_burn_view, @@ -717,17 +723,18 @@ impl RelayerThread { error!("Relayer: Failed to start new tenure: {:?}", e); } }, - MinerDirective::ContinueTenure { new_burn_view } => { - match self.continue_tenure(new_burn_view) { - Ok(()) => { - debug!("Relayer: successfully handled continue tenure."); - } - Err(e) => { - error!("Relayer: Failed to continue tenure: {:?}", e); - return false; - } + MinerDirective::ContinueTenure { + new_burn_view, + parent_tenure_start, + } => match self.continue_tenure(parent_tenure_start, new_burn_view) { + Ok(()) => { + debug!("Relayer: successfully handled continue tenure."); } - } + Err(e) => { + error!("Relayer: Failed to continue tenure: {:?}", e); + return false; + } + }, MinerDirective::StopTenure => match self.stop_tenure() { Ok(()) => { debug!("Relayer: successfully stopped tenure."); diff --git a/testnet/stacks-node/src/tests/nakamoto_integrations.rs b/testnet/stacks-node/src/tests/nakamoto_integrations.rs index 2d3b863d6d2..cf615d63911 100644 --- a/testnet/stacks-node/src/tests/nakamoto_integrations.rs +++ b/testnet/stacks-node/src/tests/nakamoto_integrations.rs @@ -4095,17 +4095,25 @@ fn continue_tenure_extend() { &signers, ); + debug!("Unpausing commit op"); TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false); - debug!("MINIGNT HE TENURES"); + debug!("MINING THE NEXT TENURES"); // Mine 15 more regular nakamoto tenures for _i in 0..15 { - next_block_and_mine_commit( - &mut btc_regtest_controller, - 60, - &coord_channel, - &commits_submitted, - ) + let commits_before = commits_submitted.load(Ordering::SeqCst); + let blocks_processed_before = coord_channel + .lock() + .expect("Mutex poisoned") + .get_stacks_blocks_processed(); + next_block_and(&mut btc_regtest_controller, 60, || { + let commits_count = commits_submitted.load(Ordering::SeqCst); + let blocks_processed = coord_channel + .lock() + .expect("Mutex poisoned") + .get_stacks_blocks_processed(); + Ok(commits_count > commits_before && blocks_processed > blocks_processed_before) + }) .unwrap(); signer_vote_if_needed(