Skip to content

Commit c439560

Browse files
authored
Merge branch 'develop' into fix/clippy-ci-stacks-lib-needless-borrow
2 parents 407d744 + 947c302 commit c439560

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
@@ -10722,16 +10722,8 @@ fn outgoing_signers_ignore_block_proposals() {
1072210722
txs: vec![],
1072310723
};
1072410724
block.header.timestamp = get_epoch_time_secs();
10725-
let signer_signature_hash_1 = block.header.signer_signature_hash();
10726-
10727-
info!("------------------------- Test Attempt to Mine Invalid Block {signer_signature_hash_1} -------------------------");
1072810725

1072910726
let short_timeout = Duration::from_secs(30);
10730-
let all_signers: Vec<_> = signer_test
10731-
.signer_stacks_private_keys
10732-
.iter()
10733-
.map(StacksPublicKey::from_private)
10734-
.collect();
1073510727
test_observer::clear();
1073610728

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

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

0 commit comments

Comments
 (0)