Skip to content

Commit 02b0a11

Browse files
committed
working
1 parent ac5c310 commit 02b0a11

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

gossip/src/cluster_info.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,16 @@ impl ClusterInfo {
25052505
false
25062506
}
25072507
};
2508+
let mut verify_node_instance = |value: &CrdsValue| {
2509+
if self.verify_node_instance(value) {
2510+
info!("greg: node instance verify good");
2511+
true
2512+
} else {
2513+
info!("greg: node instance verify bad");
2514+
self.stats.num_unverifed_node_instances.add_relaxed(1);
2515+
false
2516+
}
2517+
};
25082518
// Split packets based on their types.
25092519
let mut pull_requests = vec![];
25102520
let mut pull_responses = vec![];
@@ -2522,13 +2532,15 @@ impl ClusterInfo {
25222532
Protocol::PullResponse(_, mut data) => {
25232533
check_duplicate_instance(&data)?;
25242534
data.retain(&mut verify_gossip_addr);
2535+
data.retain(&mut verify_node_instance);
25252536
if !data.is_empty() {
25262537
pull_responses.append(&mut data);
25272538
}
25282539
}
25292540
Protocol::PushMessage(from, mut data) => {
25302541
check_duplicate_instance(&data)?;
25312542
data.retain(&mut verify_gossip_addr);
2543+
data.retain(&mut verify_node_instance);
25322544
if !data.is_empty() {
25332545
push_messages.push((from, data));
25342546
}
@@ -2578,6 +2590,23 @@ impl ClusterInfo {
25782590
Ok(())
25792591
}
25802592

2593+
fn verify_node_instance(&self, value: &CrdsValue) -> bool {
2594+
let pubkey = match &value.data {
2595+
CrdsData::NodeInstance(node) => node.from(),
2596+
_ => return true, // If not a NodeInstance, nothing to verify.
2597+
};
2598+
match self.lookup_contact_info(pubkey, |ci| ci.clone()) {
2599+
Some(_) => {
2600+
info!("greg: got contact info for pk: {pubkey:?}");
2601+
true
2602+
},
2603+
None => {
2604+
info!("greg: no contact info for pk: {pubkey:?}");
2605+
false // Need to receive contact info first
2606+
}
2607+
}
2608+
}
2609+
25812610
// Consumes packets received from the socket, deserializing, sanitizing and
25822611
// verifying them and then sending them down the channel for the actual
25832612
// handling of requests/messages.
@@ -3350,9 +3379,6 @@ fn verify_gossip_addr<R: Rng + CryptoRng>(
33503379
let (pubkey, addr) = match &value.data {
33513380
CrdsData::ContactInfo(node) => (node.pubkey(), node.gossip()),
33523381
CrdsData::LegacyContactInfo(node) => (node.pubkey(), node.gossip()),
3353-
CrdsData::NodeInstance(node) => {
3354-
ClusterInfo::lookup_contact_info(&self, id, map)
3355-
}
33563382
_ => return true, // If not a contact-info, nothing to verify.
33573383
};
33583384
// For (sufficiently) staked nodes, don't bother with ping/pong.

gossip/src/cluster_info_metrics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub struct GossipStats {
130130
pub(crate) new_push_requests: Counter,
131131
pub(crate) new_push_requests_num: Counter,
132132
pub(crate) num_unverifed_gossip_addrs: Counter,
133+
pub(crate) num_unverifed_node_instances: Counter,
133134
pub(crate) packets_received_count: Counter,
134135
pub(crate) packets_received_ping_messages_count: Counter,
135136
pub(crate) packets_received_pong_messages_count: Counter,
@@ -494,6 +495,11 @@ pub(crate) fn submit_gossip_stats(
494495
stats.num_unverifed_gossip_addrs.clear(),
495496
i64
496497
),
498+
(
499+
"num_unverifed_node_instances",
500+
stats.num_unverifed_node_instances.clear(),
501+
i64
502+
),
497503
(
498504
"packets_received_count",
499505
stats.packets_received_count.clear(),

gossip/src/crds_value.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ impl NodeInstance {
455455
}
456456
}
457457

458+
#[inline]
459+
pub fn from(&self) -> &Pubkey {
460+
&self.from
461+
}
462+
458463
// Clones the value with an updated wallclock.
459464
pub(crate) fn with_wallclock(&self, wallclock: u64) -> Self {
460465
Self { wallclock, ..*self }

0 commit comments

Comments
 (0)