Skip to content

Commit c301621

Browse files
committed
test(signer): Add checks for duplicate signing keys
1 parent 3057547 commit c301621

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

testnet/stacks-node/src/tests/neon_integrations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ pub mod test_observer {
574574
pub fn contains_burn_block_range(range: impl RangeBounds<u64>) -> Result<(), String> {
575575
// Get set of all burn block heights
576576
let burn_block_heights = get_blocks()
577-
.iter()
577+
.into_iter()
578578
.map(|x| x.get("burn_block_height").unwrap().as_u64().unwrap())
579579
.collect::<HashSet<_>>();
580580

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

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ impl SignerTest<SpawnedSigner> {
321321
// Verify that the signers signed the proposed block
322322
let mut signer_index = 0;
323323
let mut signature_index = 0;
324+
let mut signing_keys = HashSet::new();
324325
let validated = loop {
325326
// Since we've already checked `signature.len()`, this means we've
326327
// validated all the signatures in this loop
@@ -331,6 +332,9 @@ impl SignerTest<SpawnedSigner> {
331332
error!("Failed to validate the mined nakamoto block: ran out of signers to try to validate signatures");
332333
break false;
333334
};
335+
if !signing_keys.insert(signer.signing_key) {
336+
panic!("Duplicate signing key detected: {:?}", signer.signing_key);
337+
}
334338
let stacks_public_key = Secp256k1PublicKey::from_slice(signer.signing_key.as_slice())
335339
.expect("Failed to convert signing key to StacksPublicKey");
336340
let valid = stacks_public_key
@@ -488,11 +492,7 @@ fn block_proposal_rejection() {
488492
while !found_signer_signature_hash_1 && !found_signer_signature_hash_2 {
489493
std::thread::sleep(Duration::from_secs(1));
490494
let chunks = test_observer::get_stackerdb_chunks();
491-
for chunk in chunks
492-
.into_iter()
493-
.map(|chunk| chunk.modified_slots)
494-
.flatten()
495-
{
495+
for chunk in chunks.into_iter().flat_map(|chunk| chunk.modified_slots) {
496496
let Ok(message) = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
497497
else {
498498
continue;
@@ -2982,6 +2982,13 @@ fn duplicate_signers() {
29822982

29832983
// First two signers have same private key
29842984
signer_stacks_private_keys[1] = signer_stacks_private_keys[0];
2985+
let duplicate_pubkey = Secp256k1PublicKey::from_private(&signer_stacks_private_keys[0]);
2986+
let duplicate_pubkey_from_copy =
2987+
Secp256k1PublicKey::from_private(&signer_stacks_private_keys[1]);
2988+
assert_eq!(
2989+
duplicate_pubkey, duplicate_pubkey_from_copy,
2990+
"Recovered pubkeys don't match"
2991+
);
29852992

29862993
let mut signer_test: SignerTest<SpawnedSigner> = SignerTest::new_with_config_modifications(
29872994
num_signers,
@@ -2992,37 +2999,13 @@ fn duplicate_signers() {
29922999
None,
29933000
Some(signer_stacks_private_keys),
29943001
);
2995-
let timeout = Duration::from_secs(30);
2996-
let mined_blocks = signer_test.running_nodes.nakamoto_blocks_mined.clone();
2997-
let blocks_mined_before = mined_blocks.load(Ordering::SeqCst);
29983002

29993003
signer_test.boot_to_epoch_3();
3004+
let timeout = Duration::from_secs(30);
30003005

3001-
// give the system a chance to reach the Nakamoto start tip
3002-
// mine a Nakamoto block
3003-
wait_for(30, || {
3004-
let blocks_mined = mined_blocks.load(Ordering::SeqCst);
3005-
Ok(blocks_mined > blocks_mined_before)
3006-
})
3007-
.unwrap();
3006+
info!("------------------------- Try mining one block -------------------------");
30083007

3009-
info!("------------------------- Test Mine and Verify Confirmed Nakamoto Block -------------------------");
30103008
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers);
30113009

3012-
// Test prometheus metrics response
3013-
#[cfg(feature = "monitoring_prom")]
3014-
{
3015-
let metrics_response = signer_test.get_signer_metrics();
3016-
3017-
// Because 5 signers are running in the same process, the prometheus metrics
3018-
// are incremented once for every signer. This is why we expect the metric to be
3019-
// `5`, even though there is only one block proposed.
3020-
let expected_result = format!("stacks_signer_block_proposals_received {}", num_signers);
3021-
assert!(metrics_response.contains(&expected_result));
3022-
let expected_result = format!(
3023-
"stacks_signer_block_responses_sent{{response_type=\"accepted\"}} {}",
3024-
num_signers
3025-
);
3026-
assert!(metrics_response.contains(&expected_result));
3027-
}
3010+
signer_test.shutdown();
30283011
}

0 commit comments

Comments
 (0)