-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add Libp2p Gossipsub Peer Gater #6479
Changes from 7 commits
7a274e1
8036f8b
ab61f5d
bc2f1cf
5a20034
f053cd8
4b26c3c
5b8e4c3
3e888d6
02fadc6
cd75886
53bd57b
cffba51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/onflow/flow-go/network/channels" | ||
p2pconfig "github.com/onflow/flow-go/network/p2p/config" | ||
) | ||
|
||
|
@@ -200,6 +201,10 @@ func AllFlagNames() []string { | |
BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.IWantKey), | ||
BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.PublishKey), | ||
BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.ClusterPrefixedReductionFactorKey), | ||
|
||
BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.EnableKey), | ||
BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.TopicDeliveryWeightsKey, channels.ConsensusCommittee.String()), | ||
BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.TopicDeliveryWeightsKey, channels.SyncCommittee.String()), | ||
} | ||
|
||
for _, scope := range []string{systemScope, transientScope, protocolScope, peerScope, peerProtocolScope} { | ||
|
@@ -597,6 +602,16 @@ func InitializeNetworkFlags(flags *pflag.FlagSet, config *Config) { | |
config.GossipSub.ScoringParameters.ScoringRegistryParameters.MisbehaviourPenalties.ClusterPrefixedReductionFactor, | ||
"the factor used to reduce the penalty for control message misbehaviours on cluster prefixed topics") | ||
|
||
flags.Bool(BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.EnableKey), | ||
config.GossipSub.PeerGaterParameters.Enabled, | ||
"enable the libp2p peer gater") | ||
flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.TopicDeliveryWeightsKey, channels.ConsensusCommittee.String()), | ||
config.GossipSub.PeerGaterParameters.TopicDeliveryWeightsOverride.ConsensusCommittee, | ||
"topic delivery weights override for the consensus-committee topic") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the goal for the Just as an example what I mean, you could write something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.PeerGaterKey, p2pconfig.TopicDeliveryWeightsKey, channels.SyncCommittee.String()), | ||
config.GossipSub.PeerGaterParameters.TopicDeliveryWeightsOverride.SyncCommittee, | ||
"topic delivery weights override for the sync-committee topic") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly here. |
||
|
||
} | ||
|
||
// LoadLibP2PResourceManagerFlags loads all CLI flags for the libp2p resource manager configuration on the provided pflag set. | ||
|
@@ -666,6 +681,7 @@ func SetAliases(conf *viper.Viper) error { | |
// mapping should be from network-p2pconfig.key1.key2.key3... to network-config-key1-key2-key3... | ||
m[strings.Join(s[1:], "-")] = key | ||
} | ||
|
||
// each flag name should correspond to exactly one key in our config store after it is loaded with the default config | ||
for _, flagName := range AllFlagNames() { | ||
fullKey, ok := m[flagName] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,8 @@ const ( | |
PeerScoringEnabledKey = "peer-scoring-enabled" | ||
ScoreParamsKey = "scoring-parameters" | ||
SubscriptionProviderKey = "subscription-provider" | ||
PeerGaterKey = "peer-gater" | ||
TopicDeliveryWeightsKey = "topic-delivery-weights-override" | ||
) | ||
|
||
// GossipSubParameters is the configuration for the GossipSub pubsub implementation. | ||
|
@@ -76,6 +78,9 @@ type GossipSubParameters struct { | |
PeerScoringEnabled bool `mapstructure:"peer-scoring-enabled"` | ||
SubscriptionProvider SubscriptionProviderParameters `mapstructure:"subscription-provider"` | ||
ScoringParameters ScoringParameters `mapstructure:"scoring-parameters"` | ||
|
||
// PeerGaterParameters is the configuration for the libp2p peer gater. | ||
PeerGaterParameters PeerGaterParameters `mapstructure:"peer-gater"` | ||
} | ||
|
||
const ( | ||
|
@@ -89,6 +94,32 @@ type ScoringParameters struct { | |
ScoringRegistryParameters ScoringRegistryParameters `validate:"required" mapstructure:"scoring-registry"` | ||
} | ||
|
||
// PeerGaterParameters are the parameters for the libp2p peer gater. This config provides operators the ability | ||
// to override topic delivery weights for the peer gater. The default weight is 1.0. | ||
// Parameters are "numerical values" that are used to compute or build components that compute the score of a peer in GossipSub system. | ||
type PeerGaterParameters struct { | ||
// Enabled enables the peer gater. | ||
Enabled bool `validate:"required" mapstructure:"enable"` | ||
// TopicDeliveryWeightsOverride topic delivery weights that will override the default value for the specified channel. | ||
TopicDeliveryWeightsOverride TopicDeliveryWeightsOverride `validate:"required" mapstructure:"topic-delivery-weights-override"` | ||
} | ||
|
||
// TopicDeliveryWeightsOverride topic delivery weights used to override the default topic delivery weight 1.0 of the peer gater. | ||
// Parameters are "numerical values" that are used to compute or build components that compute the score of a peer in GossipSub system. | ||
type TopicDeliveryWeightsOverride struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be difficult to allow arbitrary strings here instead of a fixed list? It might be useful to be able to add overrides for other channels without having to rollout a new image There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
ConsensusCommittee float64 `validate:"required" mapstructure:"consensus-committee"` | ||
SyncCommittee float64 `validate:"required" mapstructure:"sync-committee"` | ||
} | ||
|
||
// ToMap returns the topic delivery weights configured on this struct as a map[string]float64 . | ||
// Note: When new topic delivery weights are added to the struct this func should be updated. | ||
func (t *TopicDeliveryWeightsOverride) ToMap() map[string]float64 { | ||
return map[string]float64{ | ||
"consensus-committee": t.ConsensusCommittee, | ||
"sync-committee": t.SyncCommittee, | ||
} | ||
} | ||
|
||
// SubscriptionProviderParameters keys. | ||
const ( | ||
UpdateIntervalKey = "update-interval" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this
enabled
so the full name isgossipsub-peer-gater-enabed
. it's more consistent with our other configsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3e888d6