@@ -24,6 +24,7 @@ use crate::{
2424 helpers:: { Cache , PrimarySender , Storage , SyncSender , WorkerSender , assign_to_worker} ,
2525 spawn_blocking,
2626} ;
27+ use smol_str:: SmolStr ;
2728use snarkos_account:: Account ;
2829use snarkos_node_bft_events:: {
2930 BlockRequest ,
@@ -50,6 +51,7 @@ use snarkos_node_network::{
5051 bootstrap_peers,
5152 get_repo_commit_hash,
5253 log_repo_sha_comparison,
54+ shorten_snarkos_sha,
5355} ;
5456use snarkos_node_sync:: { InsertBlockResponseError , MAX_BLOCKS_BEHIND , communication_service:: CommunicationService } ;
5557use snarkos_node_tcp:: {
@@ -475,6 +477,7 @@ impl<N: Network> Gateway<N> {
475477 address,
476478 NodeType :: Validator ,
477479 0 ,
480+ get_repo_commit_hash ( ) ,
478481 ConnectionMode :: Gateway ,
479482 ) ;
480483 }
@@ -886,7 +889,7 @@ impl<N: Network> Gateway<N> {
886889 /// Logs the connected validators.
887890 fn log_connected_validators ( & self ) {
888891 // Retrieve the connected validators and current committee.
889- let connected_validators = self . connected_peers ( ) ;
892+ let connected_validators = self . get_connected_peers ( ) ;
890893 let committee = match self . ledger . current_committee ( ) {
891894 Ok ( c) => c,
892895 Err ( err) => {
@@ -908,15 +911,32 @@ impl<N: Network> Gateway<N> {
908911
909912 // Collect the connected validator addresses and stake.
910913 let mut connected_validator_addresses = HashSet :: with_capacity ( connected_validators. len ( ) ) ;
914+ let mut connected_validator_shas: HashMap < SmolStr , u64 > = HashMap :: with_capacity ( connected_validators. len ( ) ) ;
915+ // Insert our sha.
916+ let our_sha = shorten_snarkos_sha ( & get_repo_commit_hash ( ) ) ;
917+ let our_stake = committee. get_stake ( self . account . address ( ) ) ;
918+ connected_validator_shas. insert ( our_sha. clone ( ) , our_stake) ;
911919 // Include our own address.
912920 connected_validator_addresses. insert ( self . account . address ( ) ) ;
913921 // Include and log the connected validators.
914- for peer_ip in & connected_validators {
915- let address = self . resolve_to_aleo_addr ( * peer_ip) . map_or ( "Unknown" . to_string ( ) , |a| {
916- connected_validator_addresses. insert ( a) ;
917- a. to_string ( )
918- } ) ;
919- debug ! ( "{}" , format!( " Connected to: {peer_ip} - {address}" ) . dimmed( ) ) ;
922+ for peer in & connected_validators {
923+ let peer_ip = peer. listener_addr ;
924+ // Register the Aleo address.
925+ let address = peer. aleo_addr ;
926+ connected_validator_addresses. insert ( address) ;
927+ // Register the snarkOS commit SHA and the associated stake.
928+ let address_stake = committee. get_stake ( address) ;
929+ let short_peer_sha = shorten_snarkos_sha ( & peer. snarkos_sha ) ;
930+ * connected_validator_shas. entry ( short_peer_sha. clone ( ) ) . or_default ( ) += address_stake;
931+ // Log the connected validator.
932+ debug ! ( "{}" , format!( " Connected to: {peer_ip} - {address} @ {short_peer_sha}" ) . dimmed( ) ) ;
933+ }
934+
935+ if let Some ( combined_stake) = connected_validator_shas. get ( & our_sha) {
936+ let percentage = * combined_stake as f64 / committee. total_stake ( ) as f64 * 100.0 ;
937+ debug ! ( "{}" , format!( " Combined stake @ {our_sha}: {percentage:.2}%" ) . dimmed( ) ) ;
938+ #[ cfg( feature = "metrics" ) ]
939+ metrics:: gauge ( metrics:: bft:: CONNECTED_STAKE_WITH_MATCHING_SHA , percentage) ;
920940 }
921941
922942 // Log the validators that are not connected.
@@ -1423,6 +1443,7 @@ impl<N: Network> Handshake for Gateway<N> {
14231443 cr. address ,
14241444 node_type,
14251445 cr. version ,
1446+ cr. snarkos_sha ,
14261447 ConnectionMode :: Gateway ,
14271448 ) ;
14281449 }
@@ -1508,8 +1529,9 @@ impl<N: Network> Gateway<N> {
15081529 // Determine the snarkOS SHA to send to the peer.
15091530 let current_block_height = self . ledger . latest_block_height ( ) ;
15101531 let consensus_version = N :: CONSENSUS_VERSION ( current_block_height) . unwrap ( ) ;
1511- let snarkos_sha = match ( consensus_version >= ConsensusVersion :: V12 , get_repo_commit_hash ( ) ) {
1512- ( true , Some ( sha) ) => Some ( sha) ,
1532+ let snarkos_sha = match ( self . is_dev ( ) , consensus_version >= ConsensusVersion :: V12 , get_repo_commit_hash ( ) ) {
1533+ ( true , _, Some ( sha) ) => Some ( sha) ,
1534+ ( _, true , Some ( sha) ) => Some ( sha) ,
15131535 _ => None ,
15141536 } ;
15151537 // Send a challenge request to the peer.
@@ -1615,8 +1637,9 @@ impl<N: Network> Gateway<N> {
16151637 // Determine the snarkOS SHA to send to the peer.
16161638 let current_block_height = self . ledger . latest_block_height ( ) ;
16171639 let consensus_version = N :: CONSENSUS_VERSION ( current_block_height) . unwrap ( ) ;
1618- let snarkos_sha = match ( consensus_version >= ConsensusVersion :: V12 , get_repo_commit_hash ( ) ) {
1619- ( true , Some ( sha) ) => Some ( sha) ,
1640+ let snarkos_sha = match ( self . is_dev ( ) , consensus_version >= ConsensusVersion :: V12 , get_repo_commit_hash ( ) ) {
1641+ ( true , _, Some ( sha) ) => Some ( sha) ,
1642+ ( _, true , Some ( sha) ) => Some ( sha) ,
16201643 _ => None ,
16211644 } ;
16221645 // Send the challenge request.
0 commit comments