Skip to content

Commit d8e22b7

Browse files
committed
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: libp2p/go-libp2p-pubsub#573, but that requires deeper protocol changes.
1 parent 860781c commit d8e22b7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

node/modules/lp2p/pubsub.go

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
pubsub "github.com/libp2p/go-libp2p-pubsub"
1111
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
12+
"github.com/libp2p/go-libp2p-pubsub/timecache"
1213
"github.com/libp2p/go-libp2p/core/host"
1314
"github.com/libp2p/go-libp2p/core/peer"
1415
"github.com/minio/blake2b-simd"
@@ -486,6 +487,10 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
486487
options = append(options, pubsub.WithPeerScoreInspect(pst.UpdatePeerScore, 10*time.Second))
487488
}
488489

490+
// This way, we stop propegating a message until it drops off the network. Otherwise, we'll
491+
// ignore the message for 2m then start broadcasting it again.
492+
options = append(options, pubsub.WithSeenMessagesStrategy(timecache.Strategy_LastSeen))
493+
489494
return pubsub.NewGossipSub(helpers.LifecycleCtx(in.Mctx, in.Lc), in.Host, options...)
490495
}
491496

0 commit comments

Comments
 (0)