@@ -17,7 +17,7 @@ mod commands;
17
17
pub mod multiversion;
18
18
pub mod v0;
19
19
20
- use std:: collections:: HashSet ;
20
+ use std:: collections:: { HashMap , HashSet } ;
21
21
use std:: fs:: File ;
22
22
use std:: path:: PathBuf ;
23
23
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
@@ -1134,7 +1134,7 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
1134
1134
wait_for_state_machine_update_by_miner_tenure_id (
1135
1135
timeout. as_secs ( ) ,
1136
1136
& get_chain_info ( & self . running_nodes . conf ) . pox_consensus ,
1137
- & self . signer_addresses_versions ( ) ,
1137
+ & self . signer_addresses_versions_majority ( ) ,
1138
1138
)
1139
1139
. expect ( "Failed to update signer state machine" ) ;
1140
1140
@@ -1381,7 +1381,7 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
1381
1381
. collect ( )
1382
1382
}
1383
1383
1384
- /// Get the signer addresses and corresponding versions
1384
+ /// Get the signer addresses and corresponding versions configured versions
1385
1385
pub fn signer_addresses_versions ( & self ) -> Vec < ( StacksAddress , u64 ) > {
1386
1386
self . signer_stacks_private_keys
1387
1387
. iter ( )
@@ -1395,6 +1395,33 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
1395
1395
. collect ( )
1396
1396
}
1397
1397
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
+
1398
1425
/// Get the signer public keys for the given reward cycle
1399
1426
fn get_signer_public_keys ( & self , reward_cycle : u64 ) -> Vec < StacksPublicKey > {
1400
1427
let entries = self . get_reward_set_signers ( reward_cycle) ;
0 commit comments