Skip to content

Commit a37f90c

Browse files
committed
Add outgoing signers tests
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 4b490d0 commit a37f90c

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jobs:
137137
- tests::signer::v0::global_acceptance_depends_on_block_announcement
138138
- tests::signer::v0::no_reorg_due_to_successive_block_validation_ok
139139
- tests::signer::v0::incoming_signers_ignore_block_proposals
140+
- tests::signer::v0::outgoing_signers_ignore_block_proposals
140141
- tests::nakamoto_integrations::burn_ops_integration_test
141142
- tests::nakamoto_integrations::check_block_heights
142143
- tests::nakamoto_integrations::clarity_burn_state

stacks-signer/src/runloop.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use stacks_common::{debug, error, info, warn};
2626
use crate::chainstate::SortitionsView;
2727
use crate::client::{retry_with_exponential_backoff, ClientError, StacksClient};
2828
use crate::config::{GlobalConfig, SignerConfig};
29+
#[cfg(any(test, feature = "testing"))]
30+
use crate::v0::tests::TEST_SKIP_SIGNER_CLEANUP;
2931
use crate::Signer as SignerTrait;
3032

3133
#[derive(thiserror::Error, Debug)]
@@ -423,6 +425,11 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug> RunLo
423425
}
424426

425427
fn cleanup_stale_signers(&mut self, current_reward_cycle: u64) {
428+
#[cfg(any(test, feature = "testing"))]
429+
if TEST_SKIP_SIGNER_CLEANUP.get() {
430+
warn!("Skipping signer cleanup due to testing directive.");
431+
return;
432+
}
426433
let mut to_delete = Vec::new();
427434
for (idx, signer) in &mut self.stacks_signers {
428435
let reward_cycle = signer.reward_cycle();

stacks-signer/src/v0/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pub static TEST_SKIP_BLOCK_BROADCAST: LazyLock<TestFlag<bool>> = LazyLock::new(T
4545
pub static TEST_STALL_BLOCK_VALIDATION_SUBMISSION: LazyLock<TestFlag<bool>> =
4646
LazyLock::new(TestFlag::default);
4747

48+
/// A global variable that can be used to prevent signer cleanup
49+
pub static TEST_SKIP_SIGNER_CLEANUP: LazyLock<TestFlag<bool>> = LazyLock::new(TestFlag::default);
50+
4851
impl Signer {
4952
/// Skip the block broadcast if the TEST_SKIP_BLOCK_BROADCAST flag is set
5053
pub fn test_skip_block_broadcast(&self, block: &NakamotoBlock) -> bool {

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10346,10 +10346,6 @@ fn outgoing_signers_ignore_block_proposals() {
1034610346
let mined_blocks = signer_test.running_nodes.nakamoto_blocks_mined.clone();
1034710347
let blocks_before = mined_blocks.load(Ordering::SeqCst);
1034810348

10349-
let old_signature_hash = test_observer::get_mined_nakamoto_blocks()
10350-
.last()
10351-
.unwrap()
10352-
.signer_signature_hash;
1035310349
test_observer::clear();
1035410350

1035510351
info!("------------------------- Test Mine A Valid Block -------------------------");
@@ -10371,6 +10367,10 @@ fn outgoing_signers_ignore_block_proposals() {
1037110367
})
1037210368
.expect("Timed out waiting for a block to be mined");
1037310369

10370+
let new_signature_hash = test_observer::get_mined_nakamoto_blocks()
10371+
.last()
10372+
.unwrap()
10373+
.signer_signature_hash;
1037410374
let blocks_before = mined_blocks.load(Ordering::SeqCst);
1037510375
let mut stackerdb = StackerDB::new(
1037610376
&signer_test.running_nodes.conf.node.rpc_bind,
@@ -10386,7 +10386,7 @@ fn outgoing_signers_ignore_block_proposals() {
1038610386
.map(|id| id.0)
1038710387
.collect();
1038810388

10389-
let mut old_signers_ignore_block_proposals = || {
10389+
let mut old_signers_ignore_block_proposals = |hash| {
1039010390
let _ = wait_for(10, || {
1039110391
for slot_id in old_signer_slot_ids.iter() {
1039210392
let latest_msgs = StackerDB::get_messages::<SignerMessage>(
@@ -10398,14 +10398,14 @@ fn outgoing_signers_ignore_block_proposals() {
1039810398
.expect("Failed to get message from stackerdb");
1039910399
for msg in latest_msgs.iter() {
1040010400
if let SignerMessage::BlockResponse(response) = msg {
10401-
assert_eq!(response.get_signer_signature_hash(), old_signature_hash);
10401+
assert_ne!(response.get_signer_signature_hash(), hash);
1040210402
}
1040310403
}
1040410404
}
1040510405
Ok(false)
1040610406
});
1040710407
};
10408-
old_signers_ignore_block_proposals();
10408+
old_signers_ignore_block_proposals(new_signature_hash);
1040910409

1041010410
let proposal_conf = ProposalEvalConfig {
1041110411
first_proposal_burn_block_timing: Duration::from_secs(0),
@@ -10434,7 +10434,7 @@ fn outgoing_signers_ignore_block_proposals() {
1043410434
signer_test
1043510435
.wait_for_block_rejections(30, &all_signers)
1043610436
.expect("Timed out waiting for block rejections");
10437-
old_signers_ignore_block_proposals();
10437+
old_signers_ignore_block_proposals(signer_signature_hash_1);
1043810438
test_observer::clear();
1043910439

1044010440
// Propose a block to the signers that passes initial checks but will be rejected by the stacks node
@@ -10453,7 +10453,7 @@ fn outgoing_signers_ignore_block_proposals() {
1045310453
signer_test
1045410454
.wait_for_block_rejections(30, &all_signers)
1045510455
.expect("Timed out waiting for block rejections");
10456-
old_signers_ignore_block_proposals();
10456+
old_signers_ignore_block_proposals(signer_signature_hash_2);
1045710457

1045810458
assert_eq!(blocks_before, mined_blocks.load(Ordering::SeqCst));
1045910459
signer_test.shutdown();

0 commit comments

Comments
 (0)