Skip to content

Commit

Permalink
Merge pull request #4704 from onflow/misha/6812-alsp-sync-engine-batc…
Browse files Browse the repository at this point in the history
…h-request-spam

[ALSP] Synchronization Engine `BatchRequest` spam detection (Permissionless-related engine level spam detection)
  • Loading branch information
gomisha authored Oct 12, 2023
2 parents c5b6911 + 0d1fda2 commit 7845139
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.51
version: v1.54
args: -v --build-tags relic
working-directory: ${{ matrix.dir }}
# https://github.com/golangci/golangci-lint-action/issues/244
Expand Down
19 changes: 15 additions & 4 deletions engine/common/synchronization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,30 @@ func WithScanInterval(interval time.Duration) OptionFunc {
}
}

// spamProbabilityMultiplier is used to convert probability factor to an integer as well as a maximum value - 1
// spamProbabilityMultiplier is used to convert probability factor to an integer as well as a maximum value for the
// random number that can be generated by the random number generator.
const spamProbabilityMultiplier = 1001
const spamProbabilityMultiplier = 1000

// SpamDetectionConfig contains configuration parameters for spam detection for different message types.
// The probability of creating a misbehavior report for a message of a given type is calculated differently for different
// message types.
// MisbehaviourReports are generated for two reasons:
// 1. A malformed message will always produce a MisbehaviourReport, to notify ALSP of *unambiguous* spam.
// 2. A correctly formed message may produce a MisbehaviourReport probabilistically, to notify ALSP of *ambiguous* spam.
// This effectively tracks the load associated with a particular sender, for this engine, and, on average,
// reports message load proportionally as misbehaviour to ALSP.
type SpamDetectionConfig struct {

// syncRequestProb is the probability of creating a misbehavior report for a SyncRequest message.
// batchRequestBaseProb 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

// syncRequestProb is the probability in [0,1] of creating a misbehavior report for a SyncRequest message.
syncRequestProb float32

// rangeRequestBaseProb is the base probability that's used in creating the final probability of creating a
// rangeRequestBaseProb 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.
Expand Down
Loading

0 comments on commit 7845139

Please sign in to comment.