Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(overlay-service): Check for peer NodeId in discovery ENR cache #935

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

ogenev
Copy link
Member

@ogenev ogenev commented Sep 27, 2023

What was wrong?

Many FindContent queries fail when the result is an uTP stream. This is because we cannot find the ENR of the source NodeID and reject the incoming uTP content.

This fix is expected to also improve FindNode queries.

How was it fixed?

Check in the discovery ENR cache when trying to find an ENR for a known NodeId when processing FIndContent and FindNode queries.

To-Do

  • Add entry to the release notes (may forgo for trivial changes)
  • Clean up commit history

@ogenev ogenev force-pushed the fix-find-content-query branch from a7af9ef to 31dd074 Compare September 27, 2023 08:27
@ogenev ogenev marked this pull request as ready for review September 27, 2023 08:35
Copy link
Collaborator

@mrferris mrferris left a comment

Choose a reason for hiding this comment

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

Looks good 👍

One thing is that I'd use your defined put_cached_node_addr function within Discovery::start instead of doing the same thing inline at line 171

Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

Just a few questions so I can wrap my head around what's happening here, but it looks like a nice fix!

A thought I've had is... It seems like we're operating under the assumption that each NodeId correlates to a single network participant. Which is perfectly reasonable in theory. But in practice, we might have some (lazy) users using the same private keys (eg. 0x0000.., 0x1111.., 0x0101.., etc). While I don't think this is something we need to account for, it might be worth keeping in mind as we build these caching mechanisms. Though, I also feel like there's very little we can do about this case, besides simply encouraging users (via docs & defaults) to use truly random private keys if they want their node to run cleanly.

@@ -264,6 +264,14 @@ impl Discovery {
self.node_addr_cache.write().get(node_id).cloned()
}

/// Put a `NodeAddress` into cache. If the key already exists in the cache, then it updates the key's value and
/// returns the old value. Otherwise, `None` is returned.
pub fn put_cached_node_addr(&self, node_addr: NodeAddress) -> Option<NodeAddress> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we're never calling this, besides in your test? Is there somewhere else in the production code that will update the node_addr_cache?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about a use case to add a node to the cache outside of discovery, besides in testing. The other way around is to expose the cache and make it public but I think it is more foolproof to add a discovery method for it.

service.discovery.put_cached_node_addr(node_addr);

let found_enr3 = service.find_enr(&node_id_3).unwrap();
assert_eq!(found_enr3, enr3);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this test should include checking the case that the node id can still be found after the enr has been updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't feel so, the scope of this test is to check if OverlayService find_enr is looking into the discovery cache. I think updating Enr is out of scope here.

@ogenev
Copy link
Member Author

ogenev commented Sep 28, 2023

A thought I've had is... It seems like we're operating under the assumption that each NodeId correlates to a single network participant. Which is perfectly reasonable in theory. But in practice, we might have some (lazy) users using the same private keys (eg. 0x0000.., 0x1111.., 0x0101.., etc). While I don't think this is something we need to account for, it might be worth keeping in mind as we build these caching mechanisms. Though, I also feel like there's very little we can do about this case, besides simply encouraging users (via docs & defaults) to use truly random private keys if they want their node to run cleanly.

Well, if someone cares about privacy and security, their private key should be random and secure. Operating a staking node or crypto wallet uses the same concepts so I don't think we will need to do a lot of teaching here.

Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

🚢

@ogenev ogenev self-assigned this Sep 28, 2023
@ogenev ogenev merged commit 5b385c9 into ethereum:master Sep 28, 2023
@ogenev ogenev deleted the fix-find-content-query branch September 28, 2023 15:58
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants