From 54777d302b7e9a7576ac888da75e9c6dfe7fb0c6 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Mon, 19 Aug 2024 13:27:56 -0400 Subject: [PATCH 1/4] Wait for a new block commit. Not just 1 commit Signed-off-by: Jacinta Ferrant --- testnet/stacks-node/src/tests/signer/v0.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/testnet/stacks-node/src/tests/signer/v0.rs b/testnet/stacks-node/src/tests/signer/v0.rs index cb232edd60..c7106a0037 100644 --- a/testnet/stacks-node/src/tests/signer/v0.rs +++ b/testnet/stacks-node/src/tests/signer/v0.rs @@ -63,8 +63,9 @@ use crate::nakamoto_node::sign_coordinator::TEST_IGNORE_SIGNERS; use crate::neon::Counters; use crate::run_loop::boot_nakamoto; use crate::tests::nakamoto_integrations::{ - boot_to_epoch_25, boot_to_epoch_3_reward_set, next_block_and, setup_epoch_3_reward_set, - wait_for, POX_4_DEFAULT_STACKER_BALANCE, POX_4_DEFAULT_STACKER_STX_AMT, + boot_to_epoch_25, boot_to_epoch_3_reward_set, next_block_and, next_block_and_mine_commit, + setup_epoch_3_reward_set, wait_for, POX_4_DEFAULT_STACKER_BALANCE, + POX_4_DEFAULT_STACKER_STX_AMT, }; use crate::tests::neon_integrations::{ get_account, get_chain_info, next_block_and_wait, run_until_burnchain_height, submit_tx, @@ -277,14 +278,15 @@ impl SignerTest { self.run_until_epoch_3_boundary(); - let commits_submitted = self.running_nodes.commits_submitted.clone(); - info!("Waiting 1 burnchain block for miner VRF key confirmation"); // Wait one block to confirm the VRF register, wait until a block commit is submitted - next_block_and(&mut self.running_nodes.btc_regtest_controller, 60, || { - let commits_count = commits_submitted.load(Ordering::SeqCst); - Ok(commits_count >= 1) - }) + let commits_submitted = self.running_nodes.commits_submitted.clone(); + next_block_and_mine_commit( + &mut self.running_nodes.btc_regtest_controller, + 30, + &self.running_nodes.coord_channel, + &commits_submitted, + ) .unwrap(); info!("Ready to mine Nakamoto blocks!"); } From 7a73f92e46c487b2866124869bfb51f68081bb7f Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Mon, 19 Aug 2024 14:42:30 -0400 Subject: [PATCH 2/4] Wait for a new block commit and don't use mine_commit fn Signed-off-by: Jacinta Ferrant --- testnet/stacks-node/src/tests/signer/v0.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/testnet/stacks-node/src/tests/signer/v0.rs b/testnet/stacks-node/src/tests/signer/v0.rs index c7106a0037..2a9c81c4dd 100644 --- a/testnet/stacks-node/src/tests/signer/v0.rs +++ b/testnet/stacks-node/src/tests/signer/v0.rs @@ -63,9 +63,8 @@ use crate::nakamoto_node::sign_coordinator::TEST_IGNORE_SIGNERS; use crate::neon::Counters; use crate::run_loop::boot_nakamoto; use crate::tests::nakamoto_integrations::{ - boot_to_epoch_25, boot_to_epoch_3_reward_set, next_block_and, next_block_and_mine_commit, - setup_epoch_3_reward_set, wait_for, POX_4_DEFAULT_STACKER_BALANCE, - POX_4_DEFAULT_STACKER_STX_AMT, + boot_to_epoch_25, boot_to_epoch_3_reward_set, next_block_and, setup_epoch_3_reward_set, + wait_for, POX_4_DEFAULT_STACKER_BALANCE, POX_4_DEFAULT_STACKER_STX_AMT, }; use crate::tests::neon_integrations::{ get_account, get_chain_info, next_block_and_wait, run_until_burnchain_height, submit_tx, @@ -278,15 +277,14 @@ impl SignerTest { self.run_until_epoch_3_boundary(); + let commits_submitted = self.running_nodes.commits_submitted.clone(); + let commits_before = commits_submitted.load(Ordering::SeqCst); info!("Waiting 1 burnchain block for miner VRF key confirmation"); // Wait one block to confirm the VRF register, wait until a block commit is submitted - let commits_submitted = self.running_nodes.commits_submitted.clone(); - next_block_and_mine_commit( - &mut self.running_nodes.btc_regtest_controller, - 30, - &self.running_nodes.coord_channel, - &commits_submitted, - ) + next_block_and(&mut self.running_nodes.btc_regtest_controller, 60, || { + let commits_count = commits_submitted.load(Ordering::SeqCst); + Ok(commits_count > commits_before) + }) .unwrap(); info!("Ready to mine Nakamoto blocks!"); } From 11de2a31ed901f75ba7979d1aa9bcb17cc5a5600 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Tue, 20 Aug 2024 11:39:31 -0400 Subject: [PATCH 3/4] Fix signer_set_rollover. Use the old signer set when at a reward cycle boundary Signed-off-by: Jacinta Ferrant --- testnet/stacks-node/src/tests/signer/v0.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/testnet/stacks-node/src/tests/signer/v0.rs b/testnet/stacks-node/src/tests/signer/v0.rs index 2a9c81c4dd..fcf88f8a68 100644 --- a/testnet/stacks-node/src/tests/signer/v0.rs +++ b/testnet/stacks-node/src/tests/signer/v0.rs @@ -293,6 +293,8 @@ impl SignerTest { fn mine_and_verify_confirmed_naka_block(&mut self, timeout: Duration, num_signers: usize) { info!("------------------------- Try mining one block -------------------------"); + let old_reward_cycle = self.get_current_reward_cycle(); + self.mine_nakamoto_block(timeout); // Verify that the signers accepted the proposed block, sending back a validate ok response @@ -311,7 +313,16 @@ impl SignerTest { // whenever it has crossed the threshold. assert!(signature.len() >= num_signers * 7 / 10); - let reward_cycle = self.get_current_reward_cycle(); + let new_reward_cycle = self.get_current_reward_cycle(); + let reward_cycle = if new_reward_cycle != old_reward_cycle { + old_reward_cycle + } else { + new_reward_cycle + }; + info!( + "Verifying signatures against signers for reward cycle {:?}", + reward_cycle + ); let signers = self.get_reward_set_signers(reward_cycle); // Verify that the signers signed the proposed block @@ -2784,8 +2795,7 @@ fn signer_set_rollover() { .running_nodes .btc_regtest_controller .get_burnchain() - .reward_cycle_to_block_height(next_reward_cycle) - .saturating_add(1); + .reward_cycle_to_block_height(next_reward_cycle); info!("---- Mining to next reward set calculation -----"); signer_test.run_until_burnchain_height_nakamoto( From 51e46faef150987cc298b730fc836aa8e67e018c Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Tue, 20 Aug 2024 12:01:20 -0400 Subject: [PATCH 4/4] Simplify logic to ensure at reward cycle boundaries, the old reward cycle is used Signed-off-by: Jacinta Ferrant --- testnet/stacks-node/src/tests/signer/v0.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/testnet/stacks-node/src/tests/signer/v0.rs b/testnet/stacks-node/src/tests/signer/v0.rs index fcf88f8a68..fbea6e8f1e 100644 --- a/testnet/stacks-node/src/tests/signer/v0.rs +++ b/testnet/stacks-node/src/tests/signer/v0.rs @@ -293,7 +293,7 @@ impl SignerTest { fn mine_and_verify_confirmed_naka_block(&mut self, timeout: Duration, num_signers: usize) { info!("------------------------- Try mining one block -------------------------"); - let old_reward_cycle = self.get_current_reward_cycle(); + let reward_cycle = self.get_current_reward_cycle(); self.mine_nakamoto_block(timeout); @@ -312,13 +312,6 @@ impl SignerTest { // NOTE: signature.len() does not need to equal signers.len(); the stacks miner can finish the block // whenever it has crossed the threshold. assert!(signature.len() >= num_signers * 7 / 10); - - let new_reward_cycle = self.get_current_reward_cycle(); - let reward_cycle = if new_reward_cycle != old_reward_cycle { - old_reward_cycle - } else { - new_reward_cycle - }; info!( "Verifying signatures against signers for reward cycle {:?}", reward_cycle