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

[Networking] GossipSub Spam Mitigation- Dynamic Decay Speed #4891

Merged
merged 57 commits into from
Nov 29, 2023

Conversation

kc1116
Copy link
Contributor

@kc1116 kc1116 commented Oct 27, 2023

This PR addresses the issue of spam record decay in the GossipSub scoring registry, which currently decays at a constant rate of 0.99, a hard-coded package-level value. This constant decay rate affects both honest and malicious nodes equally, potentially causing network degradation, especially when honest nodes take longer to recover their gossip scores.

To mitigate this issue, this PR introduces a mechanism for dynamic spam record decay. With this enhancement, each spam record is now initialized with a random decay value, denoted as 'n,' falling within the range specified by ...scoringRegistryConfig.InitDecayLowerBound and ...scoringRegistryConfig.InitDecayUpperBound.

Furthermore, when a record's penalty reaches the threshold defined by ...scoringRegistryConfig.IncreaseDecayThreshold, the record's decay rate is increased by ...scoringRegistryConfig.DecayThresholdIncrementer. This change ensures that nodes engaging in sustained malicious behavior will have spam records with the highest decay rate, resulting in a slower recovery process.

By introducing dynamic decay rates for spam records, this PR enhances the fairness and resilience of the GossipSub scoring mechanism, creating a more robust foundation for the network's health and performance.

ref: https://github.com/dapperlabs/flow-go/issues/6662

- remove static decay of .99 instead initialize to random decay that is updated based on gossip score
- update tests ensure initial decay is between constant lower and upper bounds
- add new GossipSubScoringRegistryConfig struct to hold configs needed for registry that were previously hard coded
- update builders
@@ -136,7 +136,7 @@ func TestInvalidCtrlMsgScoringIntegration(t *testing.T) {
})

// now simulates node2 spamming node1 with invalid gossipsub control messages.
for i := 0; i < 30; i++ {
for i := 0; i < 750; i++ {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that decay will start lower than .99 and only be incremented by default .01 we need to spam more messages in this test so that the node gets disallow listed.

config/config_test.go Outdated Show resolved Hide resolved
err := c.Validate()
require.Error(t, err)
errs, ok := errors.Unwrap(err).(validator.ValidationErrors)
require.True(t, ok)
require.Len(t, errs, 2)
require.Len(t, errs, 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only checks that there were 3 errors returned but it doesn't check what those errors were. Would be better to check the actual errors returned.

# The lower bound on the decay value for a spam record when initialized.
# A random value in a range of InitDecayLowerBound and InitDecayUpperBound is used when initializing the decay
# of a spam record.
gossipsub-scoring-registry-init-decay-lowerbound: .5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gossipsub-scoring-registry-init-decay-lowerbound: .5
gossipsub-scoring-registry-init-decay-lower-bound: .5

# of a spam record.
gossipsub-scoring-registry-init-decay-lowerbound: .5
# The upper bound on the decay value for a spam record when initialized.
gossipsub-scoring-registry-init-decay-upperbound: .7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gossipsub-scoring-registry-init-decay-upperbound: .7
gossipsub-scoring-registry-init-decay-upper-bound: .7

// InitDecayLowerBound is the lower bound on the decay value for a spam record when initialized.
// A random value in a range of InitDecayLowerBound and InitDecayUpperBound is used when initializing the decay
// of a spam record.
InitDecayLowerBound float64 `validate:"gt=0,lt=1" mapstructure:"gossipsub-scoring-registry-init-decay-lowerbound"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
InitDecayLowerBound float64 `validate:"gt=0,lt=1" mapstructure:"gossipsub-scoring-registry-init-decay-lowerbound"`
InitDecayLowerBound float64 `validate:"gt=0,lt=1,ltfield=InitDecayUpperBound" mapstructure:"gossipsub-scoring-registry-init-decay-lowerbound"`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 354 to 355
// - decayLowerbound: the lower bound of the range for the initial random decay value
// - decayUpperbound: the upper bound of the range for the initial random decay value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// - decayLowerbound: the lower bound of the range for the initial random decay value
// - decayUpperbound: the upper bound of the range for the initial random decay value
// - decayLowerBound: the lower bound of the range for the initial random decay value
// - decayUpperBound: the upper bound of the range for the initial random decay value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 359 to 362
func InitAppScoreRecordStateFunc(decayLowerbound, decayUpperbound float64) func() p2p.GossipSubSpamRecord {
return func() p2p.GossipSubSpamRecord {
return p2p.GossipSubSpamRecord{
Decay: rand.Float64()*(decayUpperbound-decayLowerbound) + decayLowerbound,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func InitAppScoreRecordStateFunc(decayLowerbound, decayUpperbound float64) func() p2p.GossipSubSpamRecord {
return func() p2p.GossipSubSpamRecord {
return p2p.GossipSubSpamRecord{
Decay: rand.Float64()*(decayUpperbound-decayLowerbound) + decayLowerbound,
func InitAppScoreRecordStateFunc(decayLowerBound, decayUpperBound float64) func() p2p.GossipSubSpamRecord {
return func() p2p.GossipSubSpamRecord {
return p2p.GossipSubSpamRecord{
Decay: rand.Float64()*(decayUpperBound-decayLowerBound) + decayLowerBound,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@gomisha gomisha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A bunch of nits and 1 testing issue that should be addressed before merging.

kc1116 and others added 8 commits November 6, 2023 12:32
Co-authored-by: Misha <15269764+gomisha@users.noreply.github.com>
Co-authored-by: Misha <15269764+gomisha@users.noreply.github.com>
Co-authored-by: Misha <15269764+gomisha@users.noreply.github.com>
Co-authored-by: Misha <15269764+gomisha@users.noreply.github.com>
Co-authored-by: Misha <15269764+gomisha@users.noreply.github.com>
Co-authored-by: Misha <15269764+gomisha@users.noreply.github.com>
Co-authored-by: Misha <15269764+gomisha@users.noreply.github.com>
kc1116 and others added 13 commits November 29, 2023 00:47
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
…& MaximumSpamPenaltyDecaySpeed -> MaximumSpamPenaltyDecayFactor
…w/flow-go into khalil/6662-peer-id-specific-decay
@kc1116 kc1116 added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 29, 2023
@kc1116 kc1116 added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 29, 2023
@kc1116 kc1116 added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 29, 2023
@kc1116 kc1116 added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 29, 2023
@kc1116 kc1116 added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 29, 2023
@kc1116 kc1116 added this pull request to the merge queue Nov 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 29, 2023
@kc1116 kc1116 added this pull request to the merge queue Nov 29, 2023
Merged via the queue into master with commit c26077a Nov 29, 2023
54 checks passed
@kc1116 kc1116 deleted the khalil/6662-peer-id-specific-decay branch November 29, 2023 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants