Skip to content

Commit

Permalink
Cluster info shred spies (bp #16389) (#16394)
Browse files Browse the repository at this point in the history
* cluster-info: Don't subtract non-shred spies from node count

(cherry picked from commit b6b0870)

* cluster-info: Get rid of some integer math while we're here

(cherry picked from commit b71875d)

Co-authored-by: Trent Nelson <[email protected]>
  • Loading branch information
mergify[bot] and t-nelson authored Apr 6, 2021
1 parent 6107de8 commit a23fb49
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,23 +882,28 @@ impl ClusterInfo {

pub fn contact_info_trace(&self) -> String {
let now = timestamp();
let mut spy_nodes = 0;
let mut different_shred_nodes = 0;
let mut shred_spy_nodes = 0usize;
let mut total_spy_nodes = 0usize;
let mut different_shred_nodes = 0usize;
let my_pubkey = self.id();
let my_shred_version = self.my_shred_version();
let nodes: Vec<_> = self
.all_peers()
.into_iter()
.filter_map(|(node, last_updated)| {
if Self::is_spy_node(&node) {
spy_nodes += 1;
let is_spy_node = Self::is_spy_node(&node);
if is_spy_node {
total_spy_nodes = total_spy_nodes.saturating_add(1);
}

let node_version = self.get_node_version(&node.id);
if my_shred_version != 0 && (node.shred_version != 0 && node.shred_version != my_shred_version) {
different_shred_nodes += 1;
different_shred_nodes = different_shred_nodes.saturating_add(1);
None
} else {
if is_spy_node {
shred_spy_nodes = shred_spy_nodes.saturating_add(1);
}
fn addr_to_string(default_ip: &IpAddr, addr: &SocketAddr) -> String {
if ContactInfo::is_valid_address(addr) {
if &addr.ip() == default_ip {
Expand Down Expand Up @@ -947,9 +952,9 @@ impl ClusterInfo {
{}\
Nodes: {}{}{}",
nodes.join(""),
nodes.len() - spy_nodes,
if spy_nodes > 0 {
format!("\nSpies: {}", spy_nodes)
nodes.len().saturating_sub(shred_spy_nodes),
if total_spy_nodes > 0 {
format!("\nSpies: {}", total_spy_nodes)
} else {
"".to_string()
},
Expand Down

0 comments on commit a23fb49

Please sign in to comment.