Skip to content

Commit

Permalink
add peer gater source decay to config w/ cli flag
Browse files Browse the repository at this point in the history
- set default source decay to 10m
- disable the peer gater by default
  • Loading branch information
kc1116 committed Sep 20, 2024
1 parent 53bd57b commit cffba51
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 10 deletions.
6 changes: 5 additions & 1 deletion config/default-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,11 @@ network-config:
# keep the entire network's size. Otherwise, the local node's view of the network will be incomplete due to cache eviction.
# Recommended size is 10x the number of peers in the network.
cache-size: 10000
peer-gater-enabled: true
# Enables or disables the libp2p peer gater.
peer-gater-enabled: false
# The per IP decay for all counters tracked by the peer gater for a peer.
peer-gater-source-decay: 10m
# The priority topic delivery weights.
peer-gater-topic-delivery-weights-override: |
consensus-committee: 1.5, sync-committee: .75
Expand Down
4 changes: 3 additions & 1 deletion insecure/corruptlibp2p/pubsub_adapter_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package corruptlibp2p

import (
"time"

pb "github.com/libp2p/go-libp2p-pubsub/pb"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/routing"
Expand Down Expand Up @@ -157,7 +159,7 @@ func (c *CorruptPubSubAdapterConfig) WithRpcInspector(_ p2p.GossipSubRPCInspecto
// CorruptPubSub does not support inspector suite. This is a no-op.
}

func (c *CorruptPubSubAdapterConfig) WithPeerGater(_ map[string]float64) {
func (c *CorruptPubSubAdapterConfig) WithPeerGater(_ map[string]float64, _ time.Duration) {
// CorruptPubSub does not need peer gater. This is a no-op.
}

Expand Down
6 changes: 5 additions & 1 deletion network/netconf/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func AllFlagNames() []string {
BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.ClusterPrefixedReductionFactorKey),

BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.EnabledKey),
BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.SourceDecayKey),
BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.TopicDeliveryWeightsKey),
}

Expand Down Expand Up @@ -601,8 +602,11 @@ func InitializeNetworkFlags(flags *pflag.FlagSet, config *Config) {
"the factor used to reduce the penalty for control message misbehaviours on cluster prefixed topics")

flags.Bool(BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.EnabledKey),
config.GossipSub.PeerScoringEnabled,
config.GossipSub.PeerGaterEnabled,
"enable the libp2p peer gater")
flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.SourceDecayKey),
config.GossipSub.PeerGaterSourceDecay,
"the per IP decay for all counters tracked by the peer gater for a peer")
flags.String(BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.TopicDeliveryWeightsKey),
config.GossipSub.PeerGaterTopicDeliveryWeightsOverride,
"topic delivery weights override, this is a comma separated with the format topic_1:2.2,topic_2:3.2,topic_3:1.7 these will be used to override the default topic weight of 1.0 for the specified topic.")
Expand Down
2 changes: 1 addition & 1 deletion network/p2p/builder/gossipsub/gossipSubBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (g *Builder) Build(ctx irrecoverable.SignalerContext) (p2p.PubSubAdapter, e
if err != nil {
return nil, fmt.Errorf("failed to add peer gater option: %w", err)
}
gossipSubConfigs.WithPeerGater(topicDeliveryWeights)
gossipSubConfigs.WithPeerGater(topicDeliveryWeights, g.gossipSubCfg.PeerGaterSourceDecay)
}

if g.routingSystem != nil {
Expand Down
3 changes: 3 additions & 0 deletions network/p2p/config/gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
ScoreParamsKey = "scoring-parameters"
SubscriptionProviderKey = "subscription-provider"
PeerGaterKey = "peer-gater"
SourceDecayKey = "source-decay"
TopicDeliveryWeightsKey = "topic-delivery-weights-override"
)

Expand All @@ -83,6 +84,8 @@ type GossipSubParameters struct {

// PeerGaterEnabled enables the peer gater.
PeerGaterEnabled bool `mapstructure:"peer-gater-enabled"`
// PeerGaterSourceDecay the per IP decay for all counters tracked by the peer gater for a peer.
PeerGaterSourceDecay time.Duration `mapstructure:"peer-gater-source-decay"`
// PeerGaterTopicDeliveryWeightsOverride topic delivery weights that will override the default value for the specified channel.
// This is a comma separated list "channel:weight, channel2:weight, channel3:weight".
// i.e: consensus-committee: 1.5, sync-committee: .75
Expand Down
8 changes: 5 additions & 3 deletions network/p2p/mock/pub_sub_adapter_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions network/p2p/node/gossipSubAdapterConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func (g *GossipSubAdapterConfig) WithTracer(tracer p2p.PubSubTracer) {
// - params: the topic delivery weights to use
// Returns:
// -None
func (g *GossipSubAdapterConfig) WithPeerGater(topicDeliveryWeights map[string]float64) {
peerGaterParams := pubsub.NewPeerGaterParams(pubsub.DefaultPeerGaterThreshold, pubsub.DefaultPeerGaterGlobalDecay, pubsub.ScoreParameterDecay(10*time.Minute)).WithTopicDeliveryWeights(topicDeliveryWeights)
func (g *GossipSubAdapterConfig) WithPeerGater(topicDeliveryWeights map[string]float64, sourceDecay time.Duration) {
peerGaterParams := pubsub.NewPeerGaterParams(pubsub.DefaultPeerGaterThreshold, pubsub.DefaultPeerGaterGlobalDecay, pubsub.ScoreParameterDecay(sourceDecay)).WithTopicDeliveryWeights(topicDeliveryWeights)
g.options = append(g.options, pubsub.WithPeerGater(peerGaterParams))
}

Expand Down
2 changes: 1 addition & 1 deletion network/p2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type PubSubAdapterConfig interface {
// This is used to expose the local scoring table of the GossipSub node to its higher level components.
WithScoreTracer(tracer PeerScoreTracer)
WithRpcInspector(GossipSubRPCInspector)
WithPeerGater(topicDeliveryWeights map[string]float64)
WithPeerGater(topicDeliveryWeights map[string]float64, sourceDecay time.Duration)
}

// GossipSubRPCInspector abstracts the general behavior of an app specific RPC inspector specifically
Expand Down

0 comments on commit cffba51

Please sign in to comment.