-
Notifications
You must be signed in to change notification settings - Fork 54
gs1.1 peer score #83
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
Merged
Merged
gs1.1 peer score #83
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cddee52
chore: add peer score machinery
wemeetagain 55c3d0b
chore: increase test timeouts
wemeetagain 37d7020
chore: tweak test timeouts
wemeetagain 2293dc4
chore: split score params/thresholds files
wemeetagain 98beab9
chore: default constructors score params/thresholds
wemeetagain 88480ec
chore: fix peerScore test
wemeetagain a7d08a9
Apply suggestions from code review
wemeetagain 3ccbfa8
chore: default params/thresholds as objects
wemeetagain 53e7a0a
chore: add fn comments
wemeetagain 2663dcb
chore: fix PeerScore#deliverMessage
wemeetagain eea879f
chore: tweak PeerScore start/stop
wemeetagain 31224a6
chore: peerScore: use string instead of peer id
wemeetagain f17b2c6
chore: AddressBook => ConnectionManager
wemeetagain a6c4de4
chore: add err-code
wemeetagain 7206a9d
chore: sync IP update, clear data on stop
wemeetagain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: split score params/thresholds files
- Loading branch information
commit 2293dc4884966b3e18c0ab2949393ae5b4ba9fb6
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| const { expect } = require('chai') | ||
| const { | ||
| createPeerScoreThresholds, validatePeerScoreThresholds, | ||
| } = require('../src/score') | ||
|
|
||
| describe('PeerScoreThresholds validation', () => { | ||
| it('should throw on invalid PeerScoreThresholds', () => { | ||
| expect(() => validatePeerScoreThresholds( | ||
| createPeerScoreThresholds({ | ||
| gossipThreshold: 1 | ||
| }) | ||
| )).to.throw | ||
| expect(() => validatePeerScoreThresholds( | ||
| createPeerScoreThresholds({ | ||
| publishThreshold: 1 | ||
| }) | ||
| )).to.throw | ||
| expect(() => validatePeerScoreThresholds( | ||
| createPeerScoreThresholds({ | ||
| gossipThreshold: -1, | ||
| publishThreshold: 0 | ||
| }) | ||
| )).to.throw | ||
| expect(() => validatePeerScoreThresholds( | ||
| createPeerScoreThresholds({ | ||
| gossipThreshold: -1, | ||
| publishThreshold: -2 | ||
| }) | ||
| )).to.throw | ||
| expect(() => validatePeerScoreThresholds( | ||
| createPeerScoreThresholds({ | ||
| acceptPXThreshold: -1 | ||
| }) | ||
| )).to.throw | ||
| expect(() => validatePeerScoreThresholds( | ||
| createPeerScoreThresholds({ | ||
| opportunisticGraftThreshold: -1 | ||
| }) | ||
| )).to.throw | ||
| }) | ||
| it('should not throw on valid PeerScoreThresholds', () => { | ||
| expect(() => validatePeerScoreThresholds( | ||
| createPeerScoreThresholds({ | ||
| gossipThreshold: -1, | ||
| publishThreshold: -2, | ||
| graylistThreshold: -3, | ||
| acceptPXThreshold: 1, | ||
| opportunisticGraftThreshold: 2 | ||
| }) | ||
| )).to.not.throw | ||
| }) | ||
| }) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| export * from './scoreParams' | ||
| export * from './peerStats' | ||
| export * from './peerScoreParams' | ||
| export * from './peerScoreThresholds' | ||
| export * from './peerScore' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| export interface PeerScoreThresholds { | ||
| /** | ||
| * gossipThreshold is the score threshold below which gossip propagation is supressed; | ||
| * should be negative. | ||
| */ | ||
| gossipThreshold: number | ||
|
|
||
| /** | ||
| * publishThreshold is the score threshold below which we shouldn't publish when using flood | ||
| * publishing (also applies to fanout and floodsub peers); should be negative and <= GossipThreshold. | ||
| */ | ||
| publishThreshold: number | ||
|
|
||
| /** | ||
| * graylistThreshold is the score threshold below which message processing is supressed altogether, | ||
| * implementing an effective graylist according to peer score; should be negative and <= PublisThreshold. | ||
| */ | ||
| graylistThreshold: number | ||
|
|
||
| /** | ||
| * acceptPXThreshold is the score threshold below which PX will be ignored; this should be positive | ||
| * and limited to scores attainable by bootstrappers and other trusted nodes. | ||
| */ | ||
| acceptPXThreshold: number | ||
|
|
||
| /** | ||
| * opportunisticGraftThreshold is the median mesh score threshold before triggering opportunistic | ||
| * grafting; this should have a small positive value. | ||
| */ | ||
| opportunisticGraftThreshold: number | ||
| } | ||
|
|
||
| export function createPeerScoreThresholds (p: Partial<PeerScoreThresholds>): PeerScoreThresholds { | ||
| return { | ||
| gossipThreshold: 0, | ||
| publishThreshold: 0, | ||
| graylistThreshold: 0, | ||
| acceptPXThreshold: 0, | ||
| opportunisticGraftThreshold: 0, | ||
| ...p | ||
| } | ||
| } | ||
|
|
||
| export function validatePeerScoreThresholds (p: PeerScoreThresholds): void { | ||
| if (p.gossipThreshold > 0) { | ||
| throw new Error('invalid gossip threshold; it must be <= 0') | ||
| } | ||
| if (p.publishThreshold > 0 || p.publishThreshold > p.gossipThreshold) { | ||
| throw new Error('invalid publish threshold; it must be <= 0 and <= gossip threshold') | ||
| } | ||
| if (p.graylistThreshold > 0 || p.graylistThreshold > p.publishThreshold) { | ||
| throw new Error('invalid graylist threshold; it must be <= 0 and <= publish threshold') | ||
| } | ||
| if (p.acceptPXThreshold < 0) { | ||
| throw new Error('invalid accept PX threshold; it must be >= 0') | ||
| } | ||
| if (p.opportunisticGraftThreshold < 0) { | ||
| throw new Error('invalid opportunistic grafting threshold; it must be >= 0') | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const DefaultDecayInterval = 1000 | ||
| const DefaultDecayToZero = 0.01 | ||
|
|
||
| /** | ||
| * ScoreParameterDecay computes the decay factor for a parameter, assuming the DecayInterval is 1s | ||
| * and that the value decays to zero if it drops below 0.01 | ||
| */ | ||
| export function scoreParameterDecay (decay: number): number { | ||
| return scoreParameterDecayWithBase(decay, DefaultDecayInterval, DefaultDecayToZero) | ||
| } | ||
|
|
||
| /** | ||
| * ScoreParameterDecay computes the decay factor for a parameter using base as the DecayInterval | ||
| */ | ||
| export function scoreParameterDecayWithBase (decay: number, base: number, decayToZero: number): number { | ||
| // the decay is linear, so after n ticks the value is factor^n | ||
| // so factor^n = decayToZero => factor = decayToZero^(1/n) | ||
| const ticks = decay / base | ||
| return decayToZero ** (1 / ticks) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.