Skip to content

Commit

Permalink
Merge pull request #5719 from stacks-network/fix/flaky-responses-check
Browse files Browse the repository at this point in the history
fix: prevent flaky check for responses by only checking threshold
  • Loading branch information
jferrant authored Jan 21, 2025
2 parents c53b10f + a8f23bd commit 947c302
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
29 changes: 28 additions & 1 deletion testnet/stacks-node/src/tests/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::time::{Duration, Instant};
use clarity::boot_util::boot_code_id;
use clarity::vm::types::PrincipalData;
use libsigner::v0::messages::{
BlockAccepted, BlockResponse, MessageSlotID, PeerInfo, SignerMessage,
BlockAccepted, BlockRejection, BlockResponse, MessageSlotID, PeerInfo, SignerMessage,
};
use libsigner::{BlockProposal, SignerEntries, SignerEventTrait};
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
Expand Down Expand Up @@ -694,6 +694,33 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
})
}

/// Get all block rejections for a given block
pub fn get_block_rejections(
&self,
signer_signature_hash: &Sha512Trunc256Sum,
) -> Vec<BlockRejection> {
let stackerdb_events = test_observer::get_stackerdb_chunks();
let block_rejections = stackerdb_events
.into_iter()
.flat_map(|chunk| chunk.modified_slots)
.filter_map(|chunk| {
let message = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
.expect("Failed to deserialize SignerMessage");
match message {
SignerMessage::BlockResponse(BlockResponse::Rejected(rejection)) => {
if rejection.signer_signature_hash == *signer_signature_hash {
Some(rejection)
} else {
None
}
}
_ => None,
}
})
.collect::<Vec<_>>();
block_rejections
}

/// Get the latest block response from the given slot
pub fn get_latest_block_response(&self, slot_id: u32) -> BlockResponse {
let mut stackerdb = StackerDB::new(
Expand Down
17 changes: 6 additions & 11 deletions testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10722,16 +10722,8 @@ fn outgoing_signers_ignore_block_proposals() {
txs: vec![],
};
block.header.timestamp = get_epoch_time_secs();
let signer_signature_hash_1 = block.header.signer_signature_hash();

info!("------------------------- Test Attempt to Mine Invalid Block {signer_signature_hash_1} -------------------------");

let short_timeout = Duration::from_secs(30);
let all_signers: Vec<_> = signer_test
.signer_stacks_private_keys
.iter()
.map(StacksPublicKey::from_private)
.collect();
test_observer::clear();

// Propose a block to the signers that passes initial checks but will be rejected by the stacks node
Expand All @@ -10747,9 +10739,12 @@ fn outgoing_signers_ignore_block_proposals() {
signer_test.propose_block(block, short_timeout);
// Verify the signers rejected the second block via the endpoint
signer_test.wait_for_validate_reject_response(short_timeout, signer_signature_hash);
signer_test
.wait_for_block_rejections(30, &all_signers)
.expect("Timed out waiting for block rejections");
wait_for(30, || {
let min_rejects = num_signers * 3 / 10;
let block_rejections = signer_test.get_block_rejections(&signer_signature_hash);
Ok(block_rejections.len() >= min_rejects)
})
.expect("Timed out waiting for block rejections");
old_signers_ignore_block_proposals(signer_signature_hash);

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

0 comments on commit 947c302

Please sign in to comment.