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

[Backport] Tweaks around libp2p pubsub seen messages cache #3783

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

lukasz-zimnoch
Copy link
Member

This pull request backports #3773 to the releases/mainnet/v2.0.0-m7 branch.

By default, the libp2p seen messages cache uses the `FirstSeen` strategy
which expires an entry once TTL elapses from the time it was added.
This means that if a single message is being received frequently and
consistently, pubsub will re-broadcast it every TTL, rather than never
re-broadcasting it.

In the context of the Keep client which additionally uses app-level
retransmissions, that often leads to a strong message amplification in the
broadcast channel which cause a significant increase in the network load.

As the problem is quite common
(see libp2p/go-libp2p-pubsub#502), the libp2p team
added a new `LastSeen` strategy which behaves differently. This strategy
expires an entry once TTL elapses from the last time the message was touched
by a cache write (`Add`) or read (`Has`) operation. That gives the desired
behavior of never re-broadcasting a message that was already seen within the
last TTL period. This reduces the risk of unintended over-amplification.

(cherry picked from commit 89a7b77)
Once a message is received and validated, pubsub re-broadcasts it
to other peers and puts it into the seen messages cache. This way,
subsequent arrivals of the same message are not re-broadcasted
unnecessarily. This mechanism is important for the network to avoid
excessive message flooding. The default value used by libp2p is 2 minutes.
However, Keep client messaging sessions are quite time-consuming so,
we use a longer TTL of 5 minutes to reduce flooding risk even further. Worth
noting that this time cannot be too long as the cache may grow excessively and
impact memory consumption.

(cherry picked from commit a712112)
@lukasz-zimnoch lukasz-zimnoch self-assigned this Feb 12, 2024
@lukasz-zimnoch lukasz-zimnoch added this to the v2.0.0-m7 milestone Feb 12, 2024
@lukasz-zimnoch lukasz-zimnoch marked this pull request as ready for review February 12, 2024 09:51
@lukasz-zimnoch lukasz-zimnoch merged commit efbb583 into releases/mainnet/v2.0.0-m7 Feb 12, 2024
27 of 28 checks passed
@lukasz-zimnoch lukasz-zimnoch deleted the backport-tweak-libp2p branch February 12, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants