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

Prevent storing non-contactable ENRs #246

Merged
merged 2 commits into from
Apr 9, 2024
Merged

Prevent storing non-contactable ENRs #246

merged 2 commits into from
Apr 9, 2024

Conversation

AgeManning
Copy link
Member

ENR updates could allow for storing non-contactable ENRs.

This PR handles some edge cases where we could update old ENRs with newer ones which are no longer contactable.

@AgeManning
Copy link
Member Author

I think this should resolve #243

@AgeManning AgeManning requested a review from ackintosh April 2, 2024 23:35
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM age

Comment on lines +1235 to +1245
match self.kbuckets.write().entry(&key) {
kbucket::Entry::Present(entry, _) if entry.value().seq() < enr.seq() => {
entry.remove()
}
kbucket::Entry::Pending(mut entry, _) => {
if entry.value().seq() < enr.seq() {
entry.remove()
}
}
_ => {}
}
Copy link
Member

@jxs jxs Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
is there be a situation for legit storing a non contactable ENR?
If not can we (instead) panic if it exists inkbuckets` while on debug, as we do in

debug_unreachable!("Stored ENR is not contactable. {}", enr);

something like:

#[cfg(debug_assertions)]
{
    match self.kbuckets.write().entry(&key) {
        kbucket::Entry::Present(entry, _) if entry.value().seq() < enr.seq() => {
            panic!("ENR shouldn't have been stored");
        }
        kbucket::Entry::Pending(mut entry, _) => {
            if entry.value().seq() < enr.seq() {
                panic!("ENR shouldn't have been stored");
            }
        }
        _ => {}
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entry here is about finding a new ENR.

So we could have an ENR that is contactable and we store it in the routing table. Then later, we find they have changed their ENR to something non-contactable and we see an updated version. Because the key in the table is the node-id, it can be that the earlier version was contactable but the new one is not. So we remove the old one here and don't store the new one.

I can't wrap this in a debug only mode, because this is a valid case.

For the sake of speed, I"ll merge this PR and if my analysis here is wrong we can make a future PR to add this in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying age, makes sense

Copy link
Member

@ackintosh ackintosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AgeManning AgeManning merged commit 10cf228 into master Apr 9, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants