Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): removing gossip node service #916

Merged
merged 1 commit into from Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions config/example_config.toml
Expand Up @@ -82,10 +82,6 @@
# Default is `true`.
## node_network = true

# `node_gossip_experimental` indicates whether the node participates in the gossiping protocol.
# Default is `false`.
## node_gossip_experimental = false

# `sync.firewall` contains configuration options for the sync firewall.
[sync.firewall]
# `enable` indicates whether the firewall should be enabled or not.
Expand Down
2 changes: 0 additions & 2 deletions network/config.go
Expand Up @@ -27,7 +27,6 @@ type Config struct {
DefaultRelayAddrStrings []string `toml:"-"`
DefaultBootstrapAddrStrings []string `toml:"-"`
IsBootstrapper bool `toml:"-"`
IsGossiper bool `toml:"-"`
}

func DefaultConfig() *Config {
Expand All @@ -46,7 +45,6 @@ func DefaultConfig() *Config {
ForcePrivateNetwork: false,
DefaultPort: 21888,
IsBootstrapper: false,
IsGossiper: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion network/dht.go
Expand Up @@ -20,7 +20,7 @@ func newDHTService(ctx context.Context, host lp2phost.Host, protocolID lp2pcore.
conf *Config, log *logger.SubLogger,
) *dhtService {
mode := lp2pdht.ModeAuto
if conf.IsBootstrapper || conf.IsGossiper {
if conf.IsBootstrapper {
mode = lp2pdht.ModeServer
}
opts := []lp2pdht.Option{
Expand Down
22 changes: 19 additions & 3 deletions network/gossip.go
Expand Up @@ -3,6 +3,7 @@ package network
import (
"context"
"sync"
"time"

lp2pps "github.com/libp2p/go-libp2p-pubsub"
lp2pcore "github.com/libp2p/go-libp2p/core"
Expand All @@ -22,20 +23,35 @@ type gossipService struct {
}

func newGossipService(ctx context.Context, host lp2phost.Host, eventCh chan Event,
_ *Config, log *logger.SubLogger,
conf *Config, log *logger.SubLogger,
) *gossipService {
opts := []lp2pps.Option{
lp2pps.WithFloodPublish(true),
lp2pps.WithMessageSignaturePolicy(lp2pps.StrictNoSign),
lp2pps.WithNoAuthor(),
lp2pps.WithMessageIdFn(MessageIDFunc),
lp2pps.WithPeerOutboundQueueSize(600),
}

pubsub, err := lp2pps.NewFloodSub(ctx, host, opts...)
if conf.IsBootstrapper {
// enable Peer eXchange on bootstrappers
opts = append(opts, lp2pps.WithPeerExchange(true))
}

gsParams := lp2pps.DefaultGossipSubParams()
if conf.IsBootstrapper {
gsParams.Dhi = 12
gsParams.D = 8
gsParams.Dlo = 6
gsParams.HeartbeatInterval = 700 * time.Millisecond
}
opts = append(opts, lp2pps.WithGossipSubParams(gsParams))

pubsub, err := lp2pps.NewGossipSub(ctx, host, opts...)
if err != nil {
log.Panic("unable to start Gossip service", "error", err)
return nil
}

return &gossipService{
ctx: ctx,
host: host,
Expand Down
3 changes: 1 addition & 2 deletions network/network.go
Expand Up @@ -249,8 +249,7 @@ func newNetwork(conf *Config, log *logger.SubLogger, opts []lp2p.Option) (*netwo
n.logger.Info("network setup", "id", n.host.ID(),
"name", conf.NetworkName,
"address", conf.ListenAddrStrings,
"bootstrapper", conf.IsBootstrapper,
"gossiper", conf.IsGossiper)
"bootstrapper", conf.IsBootstrapper)

return n, nil
}
Expand Down
1 change: 0 additions & 1 deletion node/node.go
Expand Up @@ -48,7 +48,6 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config,
"version", version.Version(),
"network", genDoc.ChainType())

conf.Network.IsGossiper = conf.Sync.NodeGossip
net, err := network.NewNetwork(conf.Network)
if err != nil {
return nil, err
Expand Down
5 changes: 0 additions & 5 deletions sync/config.go
Expand Up @@ -12,7 +12,6 @@ type Config struct {
Moniker string `toml:"moniker"`
SessionTimeout time.Duration `toml:"session_timeout"`
NodeNetwork bool `toml:"node_network"`
NodeGossip bool `toml:"node_gossip_experimental"`
Firewall *firewall.Config `toml:"firewall"`

// Private configs
Expand All @@ -25,7 +24,6 @@ func DefaultConfig() *Config {
return &Config{
SessionTimeout: time.Second * 10,
NodeNetwork: true,
NodeGossip: false,
BlockPerMessage: 60,
MaxSessions: 8,
LatestBlockInterval: 720,
Expand All @@ -48,8 +46,5 @@ func (conf *Config) Services() service.Services {
if conf.NodeNetwork {
s.Append(service.Network)
}
if conf.NodeGossip {
s.Append(service.Gossip)
}
return s
}
25 changes: 4 additions & 21 deletions sync/sync.go
Expand Up @@ -572,27 +572,10 @@ func (sync *synchronizer) prepareBlocks(from, count uint32) [][]byte {

// weAreInTheCommittee checks if one of the validators is a member of the committee
// at the current height.
func (sync *synchronizer) weAreInTheCommittee() bool {
return sync.consMgr.HasActiveInstance()
func (sync *synchronizer) shouldPropagateGeneralMessage(_ *network.GossipMessage) bool {
return true
}

func (sync *synchronizer) shouldPropagateMessage(msg *network.GossipMessage) bool {
// Propagate our messages
if msg.From == sync.SelfID() {
return true
}

if sync.config.NodeGossip {
return true
}

return sync.weAreInTheCommittee()
}

func (sync *synchronizer) shouldPropagateGeneralMessage(msg *network.GossipMessage) bool {
return sync.shouldPropagateMessage(msg)
}

func (sync *synchronizer) shouldPropagateConsensusMessage(msg *network.GossipMessage) bool {
return sync.shouldPropagateMessage(msg)
func (sync *synchronizer) shouldPropagateConsensusMessage(_ *network.GossipMessage) bool {
return true
}