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

[ALSP] Adjust Node Penalty Decay Speed on Repeated Disallow-listing #4485

Merged
merged 217 commits into from
Aug 22, 2023

Conversation

gomisha
Copy link
Contributor

@gomisha gomisha commented Jun 15, 2023

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

Creates a DecayList of values that are used to decay the Penalty value of the misbehaving node on subsequent disallow listings 10 times slower [1000, 100, 10, 1]. This allows us to increase the time a repeatedly misbehaving node is not able to communicate with the victim node.

Main test: TestHandleReportedMisbehavior_And_DisallowListing_RepeatOffender_Integration

  • test checks that each time a decay value is updated, the ALSP Manager uses the new decay value (e.g. 1000, 100, 10, 1)
  • test decays penalty to zero in one heart beat by using custom WithDecayFunc(fastDecayFunc) option to avoid having to wait for full decay
  • checks that the decay value stays at 1 after subsequent misbehaviors after the 4th misbehavior (i.e. after decay decreases from 1000 to 100 to 10 to 1, any subsequent misbehaviors will keep using a decay of 1)
  • relies on [Testing] Refactoring Network Test Fixtures for Enhanced Customizability and Maintenance #4524 to allow disabling libp2p backoff mechanism when connecting / disconnecting to a node many times in a row

Copy link
Contributor

@yhassanzadeh13 yhassanzadeh13 left a comment

Choose a reason for hiding this comment

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

🚀 great job, thanks for applying the comments!

Comment on lines 358 to 361

//// after fully decaying the penalty, update decay for next disallow listing
//record.UpdateDecay()

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove commented code if it is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

p2ptest.RequireConnectedEventually(t, []p2p.LibP2PNode{nodes[honestIndex], nodes[spammerIndex]}, 1*time.Millisecond, 100*time.Millisecond)

// ensures that the spammer is disallow-listed for the expected amount of time

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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


// check the penalty of the spammer node. It should be greater than the disallow-listing threshold.
require.Greater(t, float64(model.DisallowListingThreshold), record.Penalty)

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

require.Equal(t, float64(expectedDecays[expectedDecay]), record.Decay)
require.Equal(t, true, record.DisallowListed)
require.Equal(t, uint64(expectedCutoffCounter), record.CutoffCounter)

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

expectedDecays := []int{1000, 100, 10, 1, 1, 1} // list of expected decay values after each disallow listing

t.Log("resetting cutoff counter")
expectedCutoffCounter := 0
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
expectedCutoffCounter := 0
expectedCutoffCounter := uint64(0)

Please also remove the type casting of uint64(expectedCutoffCounter) and use expectedCutoffCounter instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

require.Greater(t, float64(model.DisallowListingThreshold), record.Penalty)

require.Equal(t, float64(expectedDecays[expectedDecay]), record.Decay)
require.Equal(t, true, record.DisallowListed)
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
require.Equal(t, true, record.DisallowListed)
// when a node is disallow-listed, it remains disallow-listed till its penalty decays back to zero.
require.Equal(t, true, record.DisallowListed)

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 +1716 to +1719
////////////////////////////// TEST HELPERS ///////////////////////////////////////////////////////////////////////////////
// The following functions are helpers for the tests. It wasn't feasible to put them in a helper file in the alspmgr_test
// package because that would break encapsulation of the ALSP manager and require making some fields exportable.
// Putting them in alspmgr package would cause a circular import cycle. Therefore, they are put in the internal test package here.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe moving these test helpers into a separate file but in the same package is more maintainable, e.g., testHelpers.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, Go doesn't allow that. Only *_test.go files are allowed to be in the alspmgr_test package. If I try and create a new test_helpers.go file with the same alspmgr_test package, the compiler complains: Multiple packages in the directory: alspmgr, alspmgr_test.

expectedCutoffCounter := 0

// keep misbehaving until the spammer is disallow-listed and check that the decay is as expected
for expectedDecay := range expectedDecays {
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
for expectedDecay := range expectedDecays {
for expectedDecayIndex := range expectedDecays {

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 395 to 396
// check the penalty of the spammer node. It should be greater than the disallow-listing threshold.
require.Greater(t, float64(model.DisallowListingThreshold), record.Penalty)
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
// check the penalty of the spammer node. It should be greater than the disallow-listing threshold.
require.Greater(t, float64(model.DisallowListingThreshold), record.Penalty)
// check the penalty of the spammer node. It should be below the disallow-listing threshold, i.e.,
// spammer penalty should be more negative than the disallow-listing threshold, hence disallow-listed.
require.Less(t, record.Penalty, float64(model.DisallowListingThreshold))

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 379 to 380
// check the penalty of the spammer node. It should be greater than the disallow-listing threshold.
require.Greater(t, float64(model.DisallowListingThreshold), record.Penalty)
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
// check the penalty of the spammer node. It should be greater than the disallow-listing threshold.
require.Greater(t, float64(model.DisallowListingThreshold), record.Penalty)
// check the penalty of the spammer node. It should be below the disallow-listing threshold, i.e.,
// spammer penalty should be more negative than the disallow-listing threshold, hence disallow-listed.
require.Less(t, record.Penalty, float64(model.DisallowListingThreshold))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gomisha and others added 2 commits August 17, 2023 07:38
Co-authored-by: Khalil Claybon <khalil.claybon@dapperlabs.com>
@gomisha
Copy link
Contributor Author

gomisha commented Aug 17, 2023

bors merge

bors bot added a commit that referenced this pull request Aug 17, 2023
4485: [ALSP] Adjust Node Penalty Decay Speed on Repeated Disallow-listing r=gomisha a=gomisha

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

Creates a `DecayList` of values that are used to decay the Penalty value of the misbehaving node on subsequent disallow listings 10 times slower `[1000, 100, 10, 1]`. This allows us to increase the time a repeatedly misbehaving node is not able to communicate with the victim node.

Main test: `TestHandleReportedMisbehavior_And_DisallowListing_RepeatOffender_Integration`

- test checks that each time a decay value is updated, the ALSP Manager uses the new decay value (e.g. 1000, 100, 10, 1)
- test decays penalty to zero in one heart beat by using custom `WithDecayFunc(fastDecayFunc)` option to avoid having to wait for full decay
- checks that the decay value stays at 1 after subsequent misbehaviors after the 4th misbehavior (i.e. after decay decreases from 1000 to 100 to 10 to 1, any subsequent misbehaviors will keep using a decay of 1)
- relies on #4524 to allow disabling libp2p backoff mechanism when connecting / disconnecting to a node many times in a row


Co-authored-by: Misha <misha.rybalov@dapperlabs.com>
@bors
Copy link
Contributor

bors bot commented Aug 17, 2023

Build failed:

@gomisha gomisha enabled auto-merge August 18, 2023 21:29
@gomisha gomisha disabled auto-merge August 18, 2023 21:31
@gomisha gomisha enabled auto-merge August 18, 2023 21:54
@gomisha gomisha added this pull request to the merge queue Aug 21, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 21, 2023
@gomisha gomisha added this pull request to the merge queue Aug 22, 2023
Merged via the queue into master with commit fe774b1 Aug 22, 2023
@gomisha gomisha deleted the misha/6766-adjust-node-penalty-decay-speed branch August 22, 2023 17:17
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