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

add behaviour penalty threshold #377

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions score.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,11 @@ func (ps *peerScore) score(p peer.ID) float64 {
score += p6 * ps.params.IPColocationFactorWeight

// P7: behavioural pattern penalty
p7 := pstats.behaviourPenalty * pstats.behaviourPenalty
score += p7 * ps.params.BehaviourPenaltyWeight
if pstats.behaviourPenalty > ps.params.BehaviourPenaltyThreshold {
excess := pstats.behaviourPenalty - ps.params.BehaviourPenaltyThreshold
p7 := excess * excess
score += p7 * ps.params.BehaviourPenaltyWeight
}

return score
}
Expand Down
8 changes: 6 additions & 2 deletions score_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ type PeerScoreParams struct {
// - attempting to re-graft before the prune backoff time has elapsed.
// - not following up in IWANT requests for messages advertised with IHAVE.
//
// The value of the parameter is the square of the counter, which decays with BehaviourPenaltyDecay.
// The value of the parameter is the square of the counter over the threshold, which decays with
// BehaviourPenaltyDecay.
// The weight of the parameter MUST be negative (or zero to disable).
BehaviourPenaltyWeight, BehaviourPenaltyDecay float64
BehaviourPenaltyWeight, BehaviourPenaltyThreshold, BehaviourPenaltyDecay float64

// the decay interval for parameter counters.
DecayInterval time.Duration
Expand Down Expand Up @@ -179,6 +180,9 @@ func (p *PeerScoreParams) validate() error {
if p.BehaviourPenaltyWeight != 0 && (p.BehaviourPenaltyDecay <= 0 || p.BehaviourPenaltyDecay >= 1) {
return fmt.Errorf("invalid BehaviourPenaltyDecay; must be between 0 and 1")
}
if p.BehaviourPenaltyThreshold < 0 {
return fmt.Errorf("invalid BehaviourPenaltyThreshold; must be >= 0")
}

// check the decay parameters
if p.DecayInterval < time.Second {
Expand Down