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: spamming peer is disconnected and seen cache doesn't grow indefinitely #1139

Closed
wants to merge 2 commits into from

Conversation

diegomrsantos
Copy link
Contributor

  • disconnectBadPeers is set to true.
  • a test is added that checks that a peer can't send invalid messages indefinitely.

@diegomrsantos diegomrsantos requested review from lchenut and kaiserd June 26, 2024 09:47
@@ -96,7 +96,7 @@ proc init*(
behaviourPenaltyWeight = -1.0,
behaviourPenaltyDecay = 0.999,
directPeers = initTable[PeerId, seq[MultiAddress]](),
disconnectBadPeers = false,
disconnectBadPeers = true,
Copy link
Collaborator

@kaiserd kaiserd Jun 26, 2024

Choose a reason for hiding this comment

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

What is the default in other implementations?
(I agree we should set this to true.)

Copy link
Contributor

Choose a reason for hiding this comment

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

The disconnection feature was a temporary hack because disconnection of a bad peer typically belongs in a different layer than gossipsub - what should be happening is that an event is raised to which the application reacts by taking appropriate action.

Usually this will involve not just disconnecting the peer but also adding them to a temporary ban list to prevent them from reconnecting within a short period of time (anything from a minute to an hour depending on the setup, doesn't greatly matter) - it might also involve judging the peer on other metrics than gossipsub.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, in terms of working on this issue, it would involve also working on the primary users of libp2p and making sure that the strategy of handling poor peers is integrated holistically with accompanying changes in nimbus-eth2 etc - I don't think making this change in libp2p on its own without making sure it fits a bigger picture makes much sense, ie the merit of the change should be evaluated in the context of how it gets used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you very much. Both Nimbus and Waku set disconnectBadPeers to true

Copy link
Contributor Author

@diegomrsantos diegomrsantos Jun 28, 2024

Choose a reason for hiding this comment

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

to prevent them from reconnecting within a short period of time

This has been implemented here https://github.com/vacp2p/nim-libp2p/pull/909/files#diff-abbf987f19a24c9940cd01bde79a1b1e0819f1c3b6d7ba2efa04ad680d022c78

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'm going to close this PR in favor of #1141

@kaiserd
Copy link
Collaborator

kaiserd commented Jun 26, 2024

seen cache doesn't grow indefinitely

This part does not seem to be in the code?

Edit: I just saw check gossip1.seen.len < 1000 in the test.
I assumed the title indicates this PR also generally limits he seen cache size.

I suggest changing the commit message when merging to:

fix: disconnect bad peers, add test incl check seen cache size is limited

@diegomrsantos
Copy link
Contributor Author

seen cache size is limited

IMO this implies a fixed limit in the cache more than the current title. There's no limit to the number of messages sent in the test and thus the size of the cache, it is checking there's some mechanism that prevents this from keep going indefinitely.

@diegomrsantos
Copy link
Contributor Author

diegomrsantos commented Jun 26, 2024

The spec https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#score-thresholds doesn't say a peer should be disconnected in this case, but rather that its RPC messages should be ignored.

It's not GossipSub purpose to disconnect peers. If GossipSub thinks a peer isn't following the protocol, it should not interact or limit interaction with the peer, but not disconnect the peer completely. There might also be other protocols in the system.

Disconnecting the peer seems a view where GossipSub is the most important protocol in the system and if a peer isn't following it, the peer isn't useful. Pragmatically, it might be true for our current systems, but I'm not sure it's right for the nim-libp2p lib in general.

We can merge this PR, but revisit it later.

@kaiserd
Copy link
Collaborator

kaiserd commented Jun 27, 2024

IMO this implies a fixed limit in the cache more than the current title. There's no limit to the number of messages sent in the test and thus the size of the cache, it is checking there's some mechanism that prevents this from keep going indefinitely.

That is OK. My point is mainly making it explicit that this is regarding the testing, and not limiting the seen cache.
Right now the title reads as: this PR fixes the fact that the seen cache grows indefinitely

@kaiserd
Copy link
Collaborator

kaiserd commented Jun 27, 2024

The spec https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#score-thresholds doesn't say a peer should be disconnected in this case, but rather that its RPC messages should be ignored.

It's not GossipSub purpose to disconnect peers. If GossipSub thinks a peer isn't following the protocol, it should not interact or limit interaction with the peer, but not disconnect the peer completely. There might also be other protocols in the system.

Disconnecting the peer seems a view where GossipSub is the most important protocol in the system and if a peer isn't following it, the peer isn't useful. Pragmatically, it might be true for our current systems, but I'm not sure it's right for the nim-libp2p lib in general.

We can merge this PR, but revisit it later.

Yes. Thanks you.
Let's add a comment to the "disconnectBadPeers = true" line.

@diegomrsantos
Copy link
Contributor Author

Closing this PR in favor of #1141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

3 participants