Skip to content

Commit 5cc34c0

Browse files
Use longer TTL for pubsub seen messages
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)
1 parent 6fc7b5d commit 5cc34c0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/net/libp2p/channel_manager.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ import (
1717
const (
1818
libp2pPeerOutboundQueueSize = 256
1919
libp2pValidationQueueSize = 4096
20+
// libp2pSeenMessagesTTL is the time-to-live used for pubsub seen messages
21+
// cache. Once a message is received and validated, pubsub re-broadcasts it
22+
// to other peers and puts it into the seen messages cache. This way,
23+
// subsequent arrivals of the same message are not re-broadcasted
24+
// unnecessarily. This mechanism is important for the network to avoid
25+
// excessive message flooding. The default value used by libp2p is 2 minutes.
26+
// However, Keep client messaging sessions are quite time-consuming so,
27+
// we use a longer TTL to reduce flooding risk even further. Worth noting
28+
// that this time cannot be too long as the cache may grow excessively and
29+
// impact memory consumption.
30+
libp2pSeenMessagesTTL = 5 * time.Minute
2031
)
2132

2233
type channelManager struct {
@@ -53,6 +64,7 @@ func newChannelManager(
5364
pubsub.WithPeerOutboundQueueSize(libp2pPeerOutboundQueueSize),
5465
pubsub.WithValidateQueueSize(libp2pValidationQueueSize),
5566
pubsub.WithSeenMessagesStrategy(pubsubtc.Strategy_LastSeen),
67+
pubsub.WithSeenMessagesTTL(libp2pSeenMessagesTTL),
5668
)
5769
if err != nil {
5870
return nil, err

0 commit comments

Comments
 (0)