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

Discv5 Routing Table: Add support for banning nodes #768

Merged
merged 7 commits into from
Jan 24, 2025

Conversation

bhartnett
Copy link
Contributor

@bhartnett bhartnett commented Jan 20, 2025

This PR adds support for banning nodes from the Discv5 routing table. This feature will be used by both Discv5 and the portal subnetworks in Fluffy. See the related task here: status-im/nimbus-eth1#2809

  • Nodes are banned by id so they can be banned even if not yet present in the routing table.
  • Once banned, nodes cannot be added to the routing table.
  • When banned, nodes are removed from the routing table and replaced using the replacement cache.

The updates to the Discv5 protocol to implement banning of peers will be included in a separate PR.

@bhartnett bhartnett marked this pull request as ready for review January 21, 2025 03:42
@bhartnett bhartnett requested a review from kdeme January 21, 2025 03:49
@bhartnett
Copy link
Contributor Author

@kdeme FYI, I didn't implement any filter in the neighbors function because we are now removing banned nodes from the routing table so they shouldn't need to be filtered out.

# Remove the node from the routing table
let node = r.getNode(nodeId)
if node.isSome():
r.replaceNode(node.get())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we replace the node as I've done here or simply remove it without using the replacement cache?

Copy link
Contributor

Choose a reason for hiding this comment

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

Replace is the way to go 👍

In general we never really use remove AFAIK (maybe in testing?), always use the replacement cache as that cache is not actively used to search for nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok great, I'll leave it as it is then.

# Remove the node from the routing table
let node = r.getNode(nodeId)
if node.isSome():
r.replaceNode(node.get())
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace is the way to go 👍

In general we never really use remove AFAIK (maybe in testing?), always use the replacement cache as that cache is not actively used to search for nodes.

table.banNode(node1.id, 1.nanoseconds)
table.banNode(node2.id, 1.nanoseconds)

sleep(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is 100 ms right? can be just value of 1 then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes true, I'll update. I guess it will speed up the test.

Comment on lines 228 to 229
# Peer is in bannedNodes table but the time period has expired
r.bannedNodes.del(nodeId)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is sufficient for banned nodes clean-up.

A node could be started, send 1 invalid message and then disappear from the network? Repeat this continuously and there is a small but increasing mem leak?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good point. Maybe a better implementation would be to clean up expired nodes for the entire routing table inside the call to addNode.

@bhartnett bhartnett requested a review from kdeme January 22, 2025 02:16
@bhartnett
Copy link
Contributor Author

@kdeme I've updated this PR based on your suggestions. Ready for another review.

r.replaceNode(node.get())

# Remove all expired bans from the banned nodes table
r.cleanupExpiredBans()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think having the cleanup here is potentially worse than the actual mem leak.

Allowing this to run in the banNode call effectively puts it in an attacker's power to run this cleanup. While at the same time the attacker can make it more expensive by "adding bans".

I think that this type of clean-up call should always be run independently of any peer node actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see so the concern in this case is the computational overhead of looping over the table rather than the list growing?

Did you have a suggestion for where you think the cleanup should happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've now removed the call to cleanupExpiredBans from the banPeer function and made it public so it can be called at a high layer.

@bhartnett bhartnett enabled auto-merge (squash) January 24, 2025 05:24
@bhartnett bhartnett disabled auto-merge January 24, 2025 05:29
@bhartnett bhartnett merged commit c6c9dc7 into master Jan 24, 2025
18 checks passed
@bhartnett bhartnett deleted the routing-table-ban-list branch January 24, 2025 05:30
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.

2 participants