Fix the Router's Ability to Prune the Mesh Periodically #589
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:go-libp2p-pubsub/gossipsub.go
Line 943 in c06df2f
During every heartbeat we check our mesh size and if it is greater than
Dhi
then we will prune our mesh back down toD
.go-libp2p-pubsub/gossipsub.go
Line 1608 in c06df2f
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 thanDhi
.This would result in the mesh being in a state of stasis at
Dhi
. Rather than float betweenD
andDhi
, the mesh stagnates atDhi
. This would end up increasing the target degree of the node toDhi
fromD
. 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.