Skip to content

Conversation

@nisdas
Copy link
Contributor

@nisdas nisdas commented Dec 26, 2024

When a new peer wants to graft us into their mesh, we check our current mesh size to determine whether we can add any more new peers to it. This is done to prevent our mesh size from being greater than Dhi and prevent mesh takeover attacks here:

if len(peers) >= gs.params.Dhi && !gs.outbound[p] {

During every heartbeat we check our mesh size and if it is greater than Dhi then we will prune our mesh back down to D.

if len(peers) > gs.params.Dhi {

However if you look closely at both lines there is a problematic end result. Since we only stop grafting new peers into our mesh if our current mesh size is greater than or equal to Dhi and we only prune peers if the current mesh size is greater than Dhi.

This would result in the mesh being in a state of stasis at Dhi. Rather than float between D and Dhi , the mesh stagnates at Dhi . This would end up increasing the target degree of the node to Dhi from D. This had been observed in ethereum mainnet by recording mesh interactions and message fulfillment from those peers.

This PR fixes it by adding an equality check to the conditional so that it can be periodically pruned. The PR also adds a regression test for this particular case.

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

oh nice, thank you!

Copy link
Contributor

@ppopth ppopth left a comment

Choose a reason for hiding this comment

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

LGTM

@vyzo vyzo merged commit 3536508 into libp2p:master Dec 26, 2024
9 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