diff --git a/f3-sidecar/go.mod b/f3-sidecar/go.mod index 5886251442b..da504c7f835 100644 --- a/f3-sidecar/go.mod +++ b/f3-sidecar/go.mod @@ -14,6 +14,7 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.33.1 github.com/libp2p/go-libp2p-pubsub v0.14.0 github.com/stretchr/testify v1.10.0 + golang.org/x/crypto v0.39.0 ) require ( @@ -135,7 +136,6 @@ require ( go.uber.org/mock v0.5.2 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/crypto v0.39.0 // indirect golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect golang.org/x/mod v0.25.0 // indirect golang.org/x/net v0.41.0 // indirect diff --git a/f3-sidecar/p2p.go b/f3-sidecar/p2p.go index 7818e71d7e0..d8bfeb1601a 100644 --- a/f3-sidecar/p2p.go +++ b/f3-sidecar/p2p.go @@ -7,8 +7,10 @@ import ( "github.com/libp2p/go-libp2p" dht "github.com/libp2p/go-libp2p-kad-dht" pubsub "github.com/libp2p/go-libp2p-pubsub" + pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/protocol" + "golang.org/x/crypto/blake2b" ) const ListenAddr = "/ip4/127.0.0.1/tcp/0" @@ -51,6 +53,16 @@ func createP2PHost(ctx context.Context, networkName string) (*P2PHost, error) { ps, err := pubsub.NewGossipSub(ctx, host, pubsub.WithPeerExchange(true), pubsub.WithFloodPublish(true), + pubsub.WithMessageIdFn(hashMsgId), + // Bump the validation queue to accommodate the increase in gossipsub message + // exchange rate as a result of f3. The size of 256 should offer enough headroom + // for slower F3 validation while avoiding: 1) avoid excessive memory usage, 2) + // dropped consensus related messages and 3) cascading effect among other topics + // since this config isn't topic-specific. + // + // Note that the worst case memory footprint is 256 MiB based on the default + // message size of 1 MiB, which isn't overridden in Lotus. + pubsub.WithValidateQueueSize(256), pubsub.WithPeerScore(PubsubPeerScoreParams, PubsubPeerScoreThresholds)) if err != nil { return nil, err @@ -58,3 +70,8 @@ func createP2PHost(ctx context.Context, networkName string) (*P2PHost, error) { return &P2PHost{host, hostDHT, backupHostDHT, ps}, nil } + +func hashMsgId(m *pubsub_pb.Message) string { + hash := blake2b.Sum256(m.Data) + return string(hash[:]) +}