From e2da5f3e70960d9f69287701154d7d7f90ed6815 Mon Sep 17 00:00:00 2001 From: mantre Date: Tue, 24 Oct 2023 19:15:15 +0800 Subject: [PATCH] fix(network): enabling peer exchange for bootstrappers --- network/dht.go | 2 -- network/gossip.go | 12 ++++++++++-- network/network.go | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/network/dht.go b/network/dht.go index 81cb43862..5767d87cd 100644 --- a/network/dht.go +++ b/network/dht.go @@ -28,8 +28,6 @@ func newDHTService(ctx context.Context, host lp2phost.Host, protocolID lp2pcore. opts := []lp2pdht.Option{ lp2pdht.Mode(mode), lp2pdht.ProtocolPrefix(protocolID), - lp2pdht.DisableProviders(), - lp2pdht.DisableValues(), lp2pdht.BootstrapPeers(bootsrapAddrs...), } diff --git a/network/gossip.go b/network/gossip.go index 590dde8b9..9de19a7ec 100644 --- a/network/gossip.go +++ b/network/gossip.go @@ -5,6 +5,7 @@ import ( "sync" lp2pps "github.com/libp2p/go-libp2p-pubsub" + pubsub "github.com/libp2p/go-libp2p-pubsub" lp2phost "github.com/libp2p/go-libp2p/core/host" "github.com/pactus-project/pactus/util/logger" ) @@ -21,9 +22,16 @@ type gossipService struct { } func newGossipService(ctx context.Context, host lp2phost.Host, eventCh chan Event, - logger *logger.SubLogger, + config *Config, logger *logger.SubLogger, ) *gossipService { - pubsub, err := lp2pps.NewGossipSub(ctx, host) + opts := []pubsub.Option{} + + if config.Bootstrapper { + // enable Peer eXchange on bootstrappers + opts = append(opts, lp2pps.WithPeerExchange(true)) + } + + pubsub, err := lp2pps.NewGossipSub(ctx, host, opts...) if err != nil { logger.Panic("unable to start Gossip service", "error", err) return nil diff --git a/network/network.go b/network/network.go index 3a372b808..ebc7096df 100644 --- a/network/network.go +++ b/network/network.go @@ -190,7 +190,7 @@ func newNetwork(networkName string, conf *Config, opts []lp2p.Option) (*network, n.dht = newDHTService(n.ctx, n.host, kadProtocolID, conf, n.logger) n.stream = newStreamService(ctx, n.host, streamProtocolID, relayAddrs, n.eventChannel, n.logger) - n.gossip = newGossipService(ctx, n.host, n.eventChannel, n.logger) + n.gossip = newGossipService(ctx, n.host, n.eventChannel, conf, n.logger) n.notifee = newNotifeeService(n.host, n.eventChannel, n.logger, streamProtocolID) n.host.Network().Notify(n.notifee)