From d8e22b73d5e3b8cdb028bece92e21e23e9e92927 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 14 Aug 2024 11:19:38 -0700 Subject: [PATCH] fix(pubsub): Switch to a last-seen cache strategy We were using the default first-seen strategy which means we'd loop messages every 2 minutes (when they expire from the cache). This new strategy keeps the message in the cache until we haven't seen it for 2 minutes, ensuring that it eventually drops off the network (with high likelihood). The correct fix is message expiration: https://github.com/libp2p/go-libp2p-pubsub/issues/573, but that requires deeper protocol changes. --- node/modules/lp2p/pubsub.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/node/modules/lp2p/pubsub.go b/node/modules/lp2p/pubsub.go index 67dcb5134a7..f76520915f5 100644 --- a/node/modules/lp2p/pubsub.go +++ b/node/modules/lp2p/pubsub.go @@ -9,6 +9,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" + "github.com/libp2p/go-libp2p-pubsub/timecache" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" "github.com/minio/blake2b-simd" @@ -486,6 +487,10 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) { options = append(options, pubsub.WithPeerScoreInspect(pst.UpdatePeerScore, 10*time.Second)) } + // This way, we stop propegating a message until it drops off the network. Otherwise, we'll + // ignore the message for 2m then start broadcasting it again. + options = append(options, pubsub.WithSeenMessagesStrategy(timecache.Strategy_LastSeen)) + return pubsub.NewGossipSub(helpers.LifecycleCtx(in.Mctx, in.Lc), in.Host, options...) }