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

Tweaks around libp2p pubsub seen messages cache #3773

Merged
merged 2 commits into from
Feb 8, 2024
Merged

Conversation

lukasz-zimnoch
Copy link
Member

@lukasz-zimnoch lukasz-zimnoch commented Feb 7, 2024

Refs: #3770
Depends on: #3771

Recent libp2p versions (we started to use them in #3771) introduced a way to set the seen messages cache TTL and strategy. Here we leverage those settings to reduce the excessive message flooding effect that sometimes occurs on mainnet. This pull request consists of two steps

Use longer TTL for pubsub seen messages cache

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.

Use LastSeen as seen messages cache strategy

By default, the libp2p seen messages cache uses the FirstSeen strategy which expires an entry once TTL elapses from when 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 causes 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.

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.
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.
@lukasz-zimnoch lukasz-zimnoch self-assigned this Feb 7, 2024
@lukasz-zimnoch lukasz-zimnoch added this to the v2.0.0-m7 milestone Feb 7, 2024
Base automatically changed from upgrade-libp2p to main February 8, 2024 13:47
@lukasz-zimnoch lukasz-zimnoch marked this pull request as ready for review February 8, 2024 13:57
@tomaszslabon tomaszslabon merged commit 499a3d5 into main Feb 8, 2024
29 checks passed
@tomaszslabon tomaszslabon deleted the tweak-libp2p branch February 8, 2024 15:21
tomaszslabon added a commit that referenced this pull request Feb 8, 2024
Closes: #3772
Depends on: #3773

Here we bump up `go-etherum` version to
[`v1.13.11`](https://github.com/ethereum/go-ethereum/releases/tag/v1.13.11).
This version is ready for the Cancun-Deneb (Dencun) upgrade and adds
support for the new “blob-carrying” EIP-4844 transaction type in API
methods. The RPC client used in older `go-ethereum` versions does not
recognize EIP-4844 transactions and may error out if there is a need to
parse return data from transaction-related functions called against
chains where the Dencun upgrade has been enabled. We observed this
problem on our Sepolia testnet when calling `eth_getBlockByNumber` using
version `v1.10.19` after Jan 31th so after the date when Dencun was
enabled on Sepolia

We are also taking an opportunity and optimize our
`GetBlockHashByNumber` function. So far this function called the
`BlockByNumber` function of the RPC client. Under the hood, that
resulted in an inefficient `eth_getBlockByNumber` call with the `show
transaction details` flag set to `true` which loaded full transaction
data of the given block which is not necessary for the context of
`GetBlockHashByNumber`. Here we improve that behavior by using the
`HeaderByNumber` function of the RPC client. That function calls
`eth_getBlockByNumber` with the `show transaction details` flag set to
`false` which does not load transaction data and returns only data
specific to the block header. This is enough to get the hash of the
block.
lukasz-zimnoch added a commit that referenced this pull request Feb 12, 2024
This pull request backports
#3773 to the
`releases/mainnet/v2.0.0-m7` branch.
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