From 8e776541beeea869113ed9337135563bc0849d29 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Wed, 29 Jan 2020 20:50:26 -0800 Subject: [PATCH] Add shred version filters to Crds Accessors --- core/src/cluster_info.rs | 40 ++++++++++++++++++++++++++++++++++++-- core/src/gossip_service.rs | 4 ++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 825895380b1819..cc5159b33c2437 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -413,6 +413,7 @@ impl ClusterInfo { .values() .filter_map(|x| x.value.contact_info()) .filter(|x| x.id != me.id) + .filter(|x| x.shred_version == me.shred_version) .filter(|x| ContactInfo::is_valid_address(&x.rpc)) .cloned() .collect() @@ -440,12 +441,29 @@ impl ClusterInfo { .values() .filter_map(|x| x.value.contact_info()) .filter(|x| x.id != me) + /* shred_version not considered for gossip peers (ie, spy nodes do not set + shred_version) */ .filter(|x| ContactInfo::is_valid_address(&x.gossip)) .cloned() .collect() } - /// all validators that have a valid tvu port. + /// all validators that have a valid tvu port regardless of `shred_version`. + pub fn all_tvu_peers(&self) -> Vec { + let me = self.my_data(); + self.gossip + .crds + .table + .values() + .filter_map(|x| x.value.contact_info()) + .filter(|x| ContactInfo::is_valid_address(&x.tvu)) + .filter(|x| !ClusterInfo::is_archiver(x)) + .filter(|x| x.id != me.id) + .cloned() + .collect() + } + + /// all validators that have a valid tvu port and are on the same `shred_version`. pub fn tvu_peers(&self) -> Vec { let me = self.my_data(); self.gossip @@ -456,11 +474,26 @@ impl ClusterInfo { .filter(|x| ContactInfo::is_valid_address(&x.tvu)) .filter(|x| !ClusterInfo::is_archiver(x)) .filter(|x| x.id != me.id) + .filter(|x| x.shred_version == me.shred_version) + .cloned() + .collect() + } + + /// all peers that have a valid storage addr regardless of `shred_version`. + pub fn all_storage_peers(&self) -> Vec { + let me = self.my_data(); + self.gossip + .crds + .table + .values() + .filter_map(|x| x.value.contact_info()) + .filter(|x| ContactInfo::is_valid_address(&x.storage_addr)) + .filter(|x| x.id != me.id) .cloned() .collect() } - /// all peers that have a valid storage addr + /// all peers that have a valid storage addr and are on the same `shred_version`. pub fn storage_peers(&self) -> Vec { let me = self.my_data(); self.gossip @@ -470,6 +503,7 @@ impl ClusterInfo { .filter_map(|x| x.value.contact_info()) .filter(|x| ContactInfo::is_valid_address(&x.storage_addr)) .filter(|x| x.id != me.id) + .filter(|x| x.shred_version == me.shred_version) .cloned() .collect() } @@ -483,6 +517,7 @@ impl ClusterInfo { .values() .filter_map(|x| x.value.contact_info()) .filter(|x| x.id != me.id) + .filter(|x| x.shred_version == me.shred_version) .filter(|x| ContactInfo::is_valid_address(&x.tvu)) .filter(|x| ContactInfo::is_valid_address(&x.tvu_forwards)) .cloned() @@ -495,6 +530,7 @@ impl ClusterInfo { ClusterInfo::tvu_peers(self) .into_iter() .filter(|x| x.id != me.id) + .filter(|x| x.shred_version == me.shred_version) .filter(|x| ContactInfo::is_valid_address(&x.gossip)) .filter(|x| { self.get_epoch_state_for_node(&x.id, None) diff --git a/core/src/gossip_service.rs b/core/src/gossip_service.rs index 119c28c09370b4..374fba896989a8 100644 --- a/core/src/gossip_service.rs +++ b/core/src/gossip_service.rs @@ -197,10 +197,10 @@ fn spy( tvu_peers = spy_ref .read() .unwrap() - .tvu_peers() + .all_tvu_peers() .into_iter() .collect::>(); - archivers = spy_ref.read().unwrap().storage_peers(); + archivers = spy_ref.read().unwrap().all_storage_peers(); if let Some(num) = num_nodes { if tvu_peers.len() + archivers.len() >= num { if let Some(gossip_addr) = find_node_by_gossip_addr {