Skip to content

Commit

Permalink
fix(pubsub): Switch to a last-seen cache strategy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Stebalien committed Aug 14, 2024
1 parent 860781c commit d8e22b7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions node/modules/lp2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...)
}

Expand Down

0 comments on commit d8e22b7

Please sign in to comment.