Skip to content

Commit

Permalink
fix(node): PubSub should create msgid according to the msg hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Nov 23, 2021
1 parent 88f97ae commit 85f445e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/libp2p/go-libp2p-pubsub v0.5.4
github.com/libp2p/go-libp2p-record v0.1.3
github.com/libp2p/go-libp2p-routing-helpers v0.2.3
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-base32 v0.0.4
github.com/multiformats/go-multiaddr v0.4.0
Expand Down
8 changes: 8 additions & 0 deletions node/p2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/libp2p/go-libp2p-core/host"
pubsub "github.com/libp2p/go-libp2p-pubsub"
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
"github.com/minio/blake2b-simd"
"go.uber.org/fx"

"github.com/celestiaorg/celestia-node/node/fxutil"
Expand All @@ -29,6 +31,7 @@ func PubSub(cfg Config) func(pubSubParams) (*pubsub.PubSub, error) {
opts := []pubsub.Option{
pubsub.WithPeerExchange(cfg.PeerExchange || cfg.Bootstrapper),
pubsub.WithDirectPeers(fpeers),
pubsub.WithMessageIdFn(hashMsgID),
}

return pubsub.NewGossipSub(
Expand All @@ -39,6 +42,11 @@ func PubSub(cfg Config) func(pubSubParams) (*pubsub.PubSub, error) {
}
}

func hashMsgID(m *pubsub_pb.Message) string {
hash := blake2b.Sum256(m.Data)
return string(hash[:])
}

type pubSubParams struct {
fx.In

Expand Down

0 comments on commit 85f445e

Please sign in to comment.