Skip to content

Commit 40ba301

Browse files
committed
Fix multiversioned_signer_protocol_version_calculation test
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent a338608 commit 40ba301

File tree

1 file changed

+30
-3
lines changed
  • stacks-node/src/tests/signer

1 file changed

+30
-3
lines changed

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod commands;
1717
pub mod multiversion;
1818
pub mod v0;
1919

20-
use std::collections::HashSet;
20+
use std::collections::{HashMap, HashSet};
2121
use std::fs::File;
2222
use std::path::PathBuf;
2323
use std::sync::atomic::{AtomicBool, Ordering};
@@ -1134,7 +1134,7 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
11341134
wait_for_state_machine_update_by_miner_tenure_id(
11351135
timeout.as_secs(),
11361136
&get_chain_info(&self.running_nodes.conf).pox_consensus,
1137-
&self.signer_addresses_versions(),
1137+
&self.signer_addresses_versions_majority(),
11381138
)
11391139
.expect("Failed to update signer state machine");
11401140

@@ -1381,7 +1381,7 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
13811381
.collect()
13821382
}
13831383

1384-
/// Get the signer addresses and corresponding versions
1384+
/// Get the signer addresses and corresponding versions configured versions
13851385
pub fn signer_addresses_versions(&self) -> Vec<(StacksAddress, u64)> {
13861386
self.signer_stacks_private_keys
13871387
.iter()
@@ -1395,6 +1395,33 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
13951395
.collect()
13961396
}
13971397

1398+
/// Get the signer addresses and corresponding majority versions
1399+
pub fn signer_addresses_versions_majority(&self) -> Vec<(StacksAddress, u64)> {
1400+
let mut signer_address_versions = self.signer_addresses_versions();
1401+
let majority = (signer_address_versions.len() * 7 / 10) as u64;
1402+
let mut protocol_versions = HashMap::new();
1403+
for (_, version) in &self.signer_addresses_versions() {
1404+
let entry = protocol_versions.entry(*version).or_insert_with(|| 0);
1405+
*entry += 1;
1406+
}
1407+
1408+
// find the highest version number supported by a threshold number of signers
1409+
let mut protocol_versions: Vec<_> = protocol_versions.into_iter().collect();
1410+
protocol_versions.sort_by_key(|(version, _)| *version);
1411+
let mut total_weight_support = 0;
1412+
for (version, weight_support) in protocol_versions.into_iter().rev() {
1413+
total_weight_support += weight_support;
1414+
if total_weight_support > majority {
1415+
// We need to actually overwrite the versions passed in since the signers will go with the majority value if they can
1416+
signer_address_versions
1417+
.iter_mut()
1418+
.for_each(|(_, v)| *v = version);
1419+
break;
1420+
}
1421+
}
1422+
signer_address_versions
1423+
}
1424+
13981425
/// Get the signer public keys for the given reward cycle
13991426
fn get_signer_public_keys(&self, reward_cycle: u64) -> Vec<StacksPublicKey> {
14001427
let entries = self.get_reward_set_signers(reward_cycle);

0 commit comments

Comments
 (0)