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] Synchronization Engine spam detection flag support, config/README.md updates #4842

Merged
merged 21 commits into from
Oct 23, 2023

Conversation

gomisha
Copy link
Contributor

@gomisha gomisha commented Oct 19, 2023

Context

This PR:

  • Defines 3 new start up flags for the Sync Engine to update the probability values that determine how incoming messages will be flagged as spam:
    • alsp-sync-engine-batch-request-base-prob
    • alsp-sync-engine-range-request-base-prob
    • alsp-sync-engine-sync-request-prob
  • updates config/README.md with more examples, clarifications and broken link fixes

This PR adds flag support to the 3 PRs that added support for spam detection to the Sync Engine:

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

@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2023

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (cfab011) 55.91% compared to head (561d257) 53.84%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4842      +/-   ##
==========================================
- Coverage   55.91%   53.84%   -2.07%     
==========================================
  Files         945      676     -269     
  Lines       87965    67837   -20128     
==========================================
- Hits        49184    36527   -12657     
+ Misses      35089    28618    -6471     
+ Partials     3692     2692    -1000     
Flag Coverage Δ
unittests 53.84% <38.09%> (-2.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
engine/common/synchronization/config.go 57.69% <80.00%> (-20.09%) ⬇️
cmd/verification_builder.go 0.00% <0.00%> (ø)
cmd/execution_builder.go 0.00% <0.00%> (ø)

... and 277 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gomisha gomisha marked this pull request as ready for review October 19, 2023 19:17
@@ -68,10 +73,16 @@ type SpamDetectionConfig struct {
}

func NewSpamDetectionConfig() *SpamDetectionConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to return an error and let the parent context throw it so that the node shuts down properly

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 122 to 131
SyncEngineBatchRequestBaseProb float32 `mapstructure:"alsp-sync-engine-batch-request-base-prob"`

// SyncEngineRangeRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
// misbehavior report for a RangeRequest message. This is why the word "base" is used in the name of this field,
// since it's not the final probability and there are other factors that determine the final probability.
// The reason for this is that we want to increase the probability of creating a misbehavior report for a large range.
SyncEngineRangeRequestBaseProb float32 `mapstructure:"alsp-sync-engine-range-request-base-prob"`

// SyncEngineSyncRequestProb is the probability in [0,1] of creating a misbehavior report for a SyncRequest message.
SyncEngineSyncRequestProb float32 `mapstructure:"alsp-sync-engine-sync-request-prob"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest adding validation tags to make sure these are greater than 0

Suggested change
SyncEngineBatchRequestBaseProb float32 `mapstructure:"alsp-sync-engine-batch-request-base-prob"`
// SyncEngineRangeRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
// misbehavior report for a RangeRequest message. This is why the word "base" is used in the name of this field,
// since it's not the final probability and there are other factors that determine the final probability.
// The reason for this is that we want to increase the probability of creating a misbehavior report for a large range.
SyncEngineRangeRequestBaseProb float32 `mapstructure:"alsp-sync-engine-range-request-base-prob"`
// SyncEngineSyncRequestProb is the probability in [0,1] of creating a misbehavior report for a SyncRequest message.
SyncEngineSyncRequestProb float32 `mapstructure:"alsp-sync-engine-sync-request-prob"`
SyncEngineBatchRequestBaseProb float32 `validate:"gt=0" mapstructure:"alsp-sync-engine-batch-request-base-prob"`
// SyncEngineRangeRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
// misbehavior report for a RangeRequest message. This is why the word "base" is used in the name of this field,
// since it's not the final probability and there are other factors that determine the final probability.
// The reason for this is that we want to increase the probability of creating a misbehavior report for a large range.
SyncEngineRangeRequestBaseProb float32 `validate:"gt=0" mapstructure:"alsp-sync-engine-range-request-base-prob"`
// SyncEngineSyncRequestProb is the probability in [0,1] of creating a misbehavior report for a SyncRequest message.
SyncEngineSyncRequestProb float32 `validate:"gt=0" mapstructure:"alsp-sync-engine-sync-request-prob"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea. I made the validation enforce a range of values between 0 and 1.

26e817f

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, please consider encapsulating them into a sync engine-specific config type:

// AlspConfig is the config for the Application Layer Spam Prevention (ALSP) protocol.
type AlspConfig struct {
        //... Other Configs

	SyncEngine SyncEngineAlspConfig
}

type SyncEngineAlspConfig struct {
	// SyncEngineBatchRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
	// misbehavior report for a BatchRequest message. This is why the word "base" is used in the name of this field,
	// since it's not the final probability and there are other factors that determine the final probability.
	// The reason for this is that we want to increase the probability of creating a misbehavior report for a large batch.
	BatchRequestBaseProb float32 `validate:"range=0,1" mapstructure:"alsp-sync-engine-batch-request-base-prob"`

	// SyncEngineRangeRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
	// misbehavior report for a RangeRequest message. This is why the word "base" is used in the name of this field,
	// since it's not the final probability and there are other factors that determine the final probability.
	// The reason for this is that we want to increase the probability of creating a misbehavior report for a large range.
	RangeRequestBaseProb float32 `validate:"range=0,1" mapstructure:"alsp-sync-engine-range-request-base-prob"`

	// SyncEngineSyncRequestProb is the probability in [0,1] of creating a misbehavior report for a SyncRequest message.
	SyncRequestProb float32 `validate:"range=0,1" mapstructure:"alsp-sync-engine-sync-request-prob"`
}

Copy link
Contributor Author

@gomisha gomisha Oct 20, 2023

Choose a reason for hiding this comment

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

Great idea. Now the SyncEngine ALSP config is referenced list this:

batchRequestBaseProb: flowConfig.NetworkConfig.SyncEngine.SyncEngineBatchRequestBaseProb,
syncRequestProb:      flowConfig.NetworkConfig.SyncEngine.SyncEngineSyncRequestProb,
rangeRequestBaseProb: flowConfig.NetworkConfig.SyncEngine.SyncEngineRangeRequestBaseProb,

5a5439d

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shortened field names to this:

batchRequestBaseProb: flowConfig.NetworkConfig.SyncEngine.BatchRequestBaseProb,
syncRequestProb:      flowConfig.NetworkConfig.SyncEngine.SyncRequestProb,
rangeRequestBaseProb: flowConfig.NetworkConfig.SyncEngine.RangeRequestBaseProb,

590e81b

@gomisha gomisha changed the title [ALSP] Synchronization Engine spam detection flag support [ALSP] Synchronization Engine spam detection flag support, config/README.md updates Oct 20, 2023
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.

Except for one encapsulation comment, the rest looks good.

Comment on lines 122 to 131
SyncEngineBatchRequestBaseProb float32 `mapstructure:"alsp-sync-engine-batch-request-base-prob"`

// SyncEngineRangeRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
// misbehavior report for a RangeRequest message. This is why the word "base" is used in the name of this field,
// since it's not the final probability and there are other factors that determine the final probability.
// The reason for this is that we want to increase the probability of creating a misbehavior report for a large range.
SyncEngineRangeRequestBaseProb float32 `mapstructure:"alsp-sync-engine-range-request-base-prob"`

// SyncEngineSyncRequestProb is the probability in [0,1] of creating a misbehavior report for a SyncRequest message.
SyncEngineSyncRequestProb float32 `mapstructure:"alsp-sync-engine-sync-request-prob"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, please consider encapsulating them into a sync engine-specific config type:

// AlspConfig is the config for the Application Layer Spam Prevention (ALSP) protocol.
type AlspConfig struct {
        //... Other Configs

	SyncEngine SyncEngineAlspConfig
}

type SyncEngineAlspConfig struct {
	// SyncEngineBatchRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
	// misbehavior report for a BatchRequest message. This is why the word "base" is used in the name of this field,
	// since it's not the final probability and there are other factors that determine the final probability.
	// The reason for this is that we want to increase the probability of creating a misbehavior report for a large batch.
	BatchRequestBaseProb float32 `validate:"range=0,1" mapstructure:"alsp-sync-engine-batch-request-base-prob"`

	// SyncEngineRangeRequestBaseProb is the base probability in [0,1] that's used in creating the final probability of creating a
	// misbehavior report for a RangeRequest message. This is why the word "base" is used in the name of this field,
	// since it's not the final probability and there are other factors that determine the final probability.
	// The reason for this is that we want to increase the probability of creating a misbehavior report for a large range.
	RangeRequestBaseProb float32 `validate:"range=0,1" mapstructure:"alsp-sync-engine-range-request-base-prob"`

	// SyncEngineSyncRequestProb is the probability in [0,1] of creating a misbehavior report for a SyncRequest message.
	SyncRequestProb float32 `validate:"range=0,1" mapstructure:"alsp-sync-engine-sync-request-prob"`
}

@gomisha gomisha added this pull request to the merge queue Oct 23, 2023
Merged via the queue into master with commit e53460b Oct 23, 2023
36 checks passed
@gomisha gomisha deleted the misha/6812-alsp-sync-engine-spam-flags branch October 23, 2023 23:25
This pull request was closed.
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