Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: re-establish bond on ping #11989

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,23 @@ impl Discv4Service {

let old_enr = match self.kbuckets.entry(&key) {
kbucket::Entry::Present(mut entry, _) => {
is_proven = entry.value().has_endpoint_proof;
if entry.value().is_expired() {
// If no communication with the sender has occurred within the last 12h, a ping
// should be sent in addition to pong in order to receive an endpoint proof.
needs_bond = true;
} else {
is_proven = entry.value().has_endpoint_proof;
}
entry.value_mut().update_with_enr(ping.enr_sq)
}
kbucket::Entry::Pending(mut entry, _) => {
is_proven = entry.value().has_endpoint_proof;
if entry.value().is_expired() {
// If no communication with the sender has occurred within the last 12h, a ping
// should be sent in addition to pong in order to receive an endpoint proof.
needs_bond = true;
} else {
is_proven = entry.value().has_endpoint_proof;
}
entry.value().update_with_enr(ping.enr_sq)
}
kbucket::Entry::Absent(entry) => {
Expand Down Expand Up @@ -1223,7 +1235,8 @@ impl Discv4Service {
self.update_on_pong(node, pong.enr_sq);
}
PingReason::EstablishBond => {
// nothing to do here
// same as `InitialInsert` which renews the bond if the peer is in the table
self.update_on_pong(node, pong.enr_sq);
}
PingReason::RePing => {
self.update_on_reping(node, pong.enr_sq);
Expand Down Expand Up @@ -2268,8 +2281,7 @@ impl NodeEntry {
enum PingReason {
/// Initial ping to a previously unknown peer that was inserted into the table.
InitialInsert,
/// Initial ping to a previously unknown peer that didn't fit into the table. But we still want
/// to establish a bond.
/// A ping to a peer to establish a bond (endpoint proof).
EstablishBond,
/// Re-ping a peer.
RePing,
Expand Down
Loading