Skip to content

Commit c1d3ad7

Browse files
committed
verify node instance before accepting
1 parent a1c00e5 commit c1d3ad7

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

gossip/src/cluster_info.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,14 @@ impl ClusterInfo {
25052505
false
25062506
}
25072507
};
2508+
let mut verify_node_instance = |value: &CrdsValue| {
2509+
if self.verify_node_instance(value) {
2510+
true
2511+
} else {
2512+
self.stats.num_unverifed_node_instances.add_relaxed(1);
2513+
false
2514+
}
2515+
};
25082516
// Split packets based on their types.
25092517
let mut pull_requests = vec![];
25102518
let mut pull_responses = vec![];
@@ -2522,13 +2530,15 @@ impl ClusterInfo {
25222530
Protocol::PullResponse(_, mut data) => {
25232531
check_duplicate_instance(&data)?;
25242532
data.retain(&mut verify_gossip_addr);
2533+
data.retain(&mut verify_node_instance);
25252534
if !data.is_empty() {
25262535
pull_responses.append(&mut data);
25272536
}
25282537
}
25292538
Protocol::PushMessage(from, mut data) => {
25302539
check_duplicate_instance(&data)?;
25312540
data.retain(&mut verify_gossip_addr);
2541+
data.retain(&mut verify_node_instance);
25322542
if !data.is_empty() {
25332543
push_messages.push((from, data));
25342544
}
@@ -2578,6 +2588,20 @@ impl ClusterInfo {
25782588
Ok(())
25792589
}
25802590

2591+
fn verify_node_instance(&self, value: &CrdsValue) -> bool {
2592+
let pubkey = match &value.data {
2593+
CrdsData::NodeInstance(node) => node.from(),
2594+
_ => return true, // If not a NodeInstance, nothing to verify.
2595+
};
2596+
// if contact info for the pubkey exists in the crds table, then the
2597+
// the contact info has already been verified. Therefore, the node
2598+
// instance is valid.
2599+
if self.lookup_contact_info(pubkey, |ci| ci.clone()).is_some() {
2600+
return true;
2601+
}
2602+
false
2603+
}
2604+
25812605
// Consumes packets received from the socket, deserializing, sanitizing and
25822606
// verifying them and then sending them down the channel for the actual
25832607
// handling of requests/messages.

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)