Skip to content

Commit bc43088

Browse files
committed
fix: prevent flaky check for responses by only checking threshold
1 parent ab90a9d commit bc43088

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::time::{Duration, Instant};
3737
use clarity::boot_util::boot_code_id;
3838
use clarity::vm::types::PrincipalData;
3939
use libsigner::v0::messages::{
40-
BlockAccepted, BlockResponse, MessageSlotID, PeerInfo, SignerMessage,
40+
BlockAccepted, BlockRejection, BlockResponse, MessageSlotID, PeerInfo, SignerMessage,
4141
};
4242
use libsigner::{BlockProposal, SignerEntries, SignerEventTrait};
4343
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
@@ -694,6 +694,33 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
694694
})
695695
}
696696

697+
/// Get all block rejections for a given block
698+
pub fn get_block_rejections(
699+
&self,
700+
signer_signature_hash: &Sha512Trunc256Sum,
701+
) -> Vec<BlockRejection> {
702+
let stackerdb_events = test_observer::get_stackerdb_chunks();
703+
let block_rejections = stackerdb_events
704+
.into_iter()
705+
.flat_map(|chunk| chunk.modified_slots)
706+
.filter_map(|chunk| {
707+
let message = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
708+
.expect("Failed to deserialize SignerMessage");
709+
match message {
710+
SignerMessage::BlockResponse(BlockResponse::Rejected(rejection)) => {
711+
if rejection.signer_signature_hash == *signer_signature_hash {
712+
Some(rejection)
713+
} else {
714+
None
715+
}
716+
}
717+
_ => None,
718+
}
719+
})
720+
.collect::<Vec<_>>();
721+
block_rejections
722+
}
723+
697724
/// Get the latest block response from the given slot
698725
pub fn get_latest_block_response(&self, slot_id: u32) -> BlockResponse {
699726
let mut stackerdb = StackerDB::new(

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10708,16 +10708,8 @@ fn outgoing_signers_ignore_block_proposals() {
1070810708
txs: vec![],
1070910709
};
1071010710
block.header.timestamp = get_epoch_time_secs();
10711-
let signer_signature_hash_1 = block.header.signer_signature_hash();
10712-
10713-
info!("------------------------- Test Attempt to Mine Invalid Block {signer_signature_hash_1} -------------------------");
1071410711

1071510712
let short_timeout = Duration::from_secs(30);
10716-
let all_signers: Vec<_> = signer_test
10717-
.signer_stacks_private_keys
10718-
.iter()
10719-
.map(StacksPublicKey::from_private)
10720-
.collect();
1072110713
test_observer::clear();
1072210714

1072310715
// Propose a block to the signers that passes initial checks but will be rejected by the stacks node
@@ -10733,9 +10725,12 @@ fn outgoing_signers_ignore_block_proposals() {
1073310725
signer_test.propose_block(block, short_timeout);
1073410726
// Verify the signers rejected the second block via the endpoint
1073510727
signer_test.wait_for_validate_reject_response(short_timeout, signer_signature_hash);
10736-
signer_test
10737-
.wait_for_block_rejections(30, &all_signers)
10738-
.expect("Timed out waiting for block rejections");
10728+
wait_for(30, || {
10729+
let min_rejects = num_signers * 3 / 10;
10730+
let block_rejections = signer_test.get_block_rejections(&signer_signature_hash);
10731+
Ok(block_rejections.len() >= min_rejects)
10732+
})
10733+
.expect("Timed out waiting for block rejections");
1073910734
old_signers_ignore_block_proposals(signer_signature_hash);
1074010735

1074110736
assert_eq!(blocks_before, mined_blocks.load(Ordering::SeqCst));

0 commit comments

Comments
 (0)