-
Notifications
You must be signed in to change notification settings - Fork 587
feat: peer scoring #20047
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
base: next
Are you sure you want to change the base?
feat: peer scoring #20047
Conversation
bfe83fc to
4a23ba3
Compare
| | `tx` | Unpredictable | N/A | P3/P3b disabled | | ||
| | `block_proposal` | N-1 | 3 slots | N = blocks per slot (MBPS mode) | | ||
| | `checkpoint_proposal` | 1 | 5 slots | One per slot | | ||
| | `checkpoint_attestation` | C (~48) | 2 slots | C = committee size | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this expectation be too high? I'm just thinking if a percentage of validators are non-responsive then we would penalize honest peers through no fault of their own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are just the numbers expressing the ideal scenario - more on penalization for under-delivery can be found here: https://github.com/AztecProtocol/aztec-packages/blob/feature/peer-scoring/yarn-project/p2p/src/services/gossipsub/README.md#how-p3-handles-under-delivery
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the main impact for underdelivering peers is the will be pruned from the mesh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And one more remark: to actually get penalized for under-delivery the score for the topic need to be below the threshold: https://github.com/AztecProtocol/aztec-packages/blob/feature/peer-scoring/yarn-project/p2p/src/services/gossipsub/README.md#threshold-calculation
Currently that is 30% of expected score that is calculated over 5 slots.
yarn-project/p2p/src/config.ts
Outdated
| 'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.', | ||
| ...booleanConfigHelper(false), | ||
| }, | ||
| blockDurationMs: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be duplicated here. Can this env var mapping be moved from SequencerClientConfig to SequencerConfig (in stdlib) and then Pick<> into this config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
fc701ef to
6ef0c21
Compare
3f01630 to
ebb9b04
Compare
19ac2c7 to
f7c6e8e
Compare
alexghr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I'll let @PhilWindle to do the final approval
yarn-project/archiver/src/factory.ts
Outdated
| @@ -100,6 +100,7 @@ export async function createArchiver( | |||
| slotDuration, | |||
| ethereumSlotDuration, | |||
| proofSubmissionEpochs: Number(proofSubmissionEpochs), | |||
| targetCommitteeSize: config.aztecTargetCommitteeSize, | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be read from the rollup. See above code block
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, genesisArchiveRoot, slashingProposerAddress] =
await Promise.all([
rollup.getL1StartBlock(),
rollup.getL1GenesisTime(),
rollup.getProofSubmissionEpochs(),
rollup.getGenesisArchiveTreeRoot(),
rollup.getSlashingProposerAddress(),
] as const);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! fixed
f7c6e8e to
a3b04c4
Compare
a3b04c4 to
1041ec6
Compare
Gossipsub Peer Scoring
Summary
This PR implements comprehensive gossipsub peer scoring improvements for the Aztec P2P network:
Motivation
Previously, all gossipsub topics used identical hardcoded scoring parameters. This doesn't account for the vastly different message frequencies across topics:
Additionally, the gossipsub thresholds were borrowed from Lighthouse (Ethereum beacon chain) and were too lax for our scoring system. A banned peer (app score -100) only contributed -1000 to gossipsub, far above the -4000 gossipThreshold, so banned peers still received gossip.
Changes
New Shared Module:
@aztec/stdlib/timetableCreated a shared timetable constants module that both
p2pandsequencer-clientimport from:CHECKPOINT_INITIALIZATION_TIME(1s)CHECKPOINT_ASSEMBLE_TIME(1s)DEFAULT_P2P_PROPAGATION_TIME(2s)DEFAULT_L1_PUBLISHING_TIME(12s)MIN_EXECUTION_TIME(2s)calculateMaxBlocksPerSlot()- shared calculation for blocks per slotAdded
targetCommitteeSizetoL1RollupConstantsThe committee size is needed to calculate expected attestation rates. Added to:
L1RollupConstantstype and schemaEpochCache.create()to fetch from rollup contractEpochCacheInterface.getL1Constants()methodNew Topic Scoring Module:
@aztec/p2p/services/gossipsub/topic_score_params.tsImplements dynamic scoring parameter calculation with balanced P1/P2/P3 configuration following Lodestar's approach:
txblock_proposalcheckpoint_proposalcheckpoint_attestationKey features:
Tightened Gossipsub Thresholds
Updated
scoring.tswith thresholds aligned to application-level scoring:The 1:2:4 ratio follows Lodestar's approach and gossipsub spec recommendations.
Application Score Weight
Verified
appSpecificWeight = 10creates perfect alignment:Added documentation in
libp2p_service.tsexplaining this alignment.Application Penalties
The existing penalties are well-designed and unchanged:
Added documentation in
peer_scoring.tsexplaining the alignment with gossipsub thresholds.How the Systems Work Together
Score Flow
Peer State Alignment
Topic Score Contribution
Topic scores are balanced for mesh pruning while allowing recovery from network issues:
Key insight: P3 max (-34) > P1+P2 max (+33), so non-contributors are always pruned regardless of how long they've been in mesh.
After pruning: P3b = -102 total, which is well above gossipThreshold (-500), so network issues don't cause disconnection.
Example Scenarios
Technical Details
Decay Calculation
Counters decay to ~1% over the decay window:
Convergence and Threshold
Steady-state counter value and conservative threshold:
Blocks Per Slot
Calculated from timetable constants (same formula used by sequencer):
Files Changed
New Files
yarn-project/stdlib/src/timetable/index.ts- Shared timetable constantsyarn-project/stdlib/src/config/sequencer-config.ts- Shared sequencer config mappings (e.g.,blockDurationMs)yarn-project/p2p/src/services/gossipsub/topic_score_params.ts- Topic scoring logicyarn-project/p2p/src/services/gossipsub/topic_score_params.test.ts- Unit tests for scoring paramsyarn-project/p2p/src/services/gossipsub/index.ts- Module exportsyarn-project/p2p/src/services/gossipsub/README.md- DocumentationModified Files
yarn-project/stdlib/src/epoch-helpers/index.ts- AddedtargetCommitteeSizeyarn-project/stdlib/package.json- Added timetable exportyarn-project/epoch-cache/src/epoch_cache.ts- Fetch committee size, addgetL1Constants()yarn-project/p2p/src/config.ts- AddedblockDurationMsto P2P config viaPick<SequencerConfig, 'blockDurationMs'>(uses shared mapping from@aztec/stdlib/config)yarn-project/p2p/src/services/libp2p/libp2p_service.ts- Use dynamic topic params, passblockDurationMsfrom config, added appSpecificWeight documentationyarn-project/p2p/src/services/gossipsub/scoring.ts- Updated thresholds with documentationyarn-project/p2p/src/services/peer-manager/peer_scoring.ts- Added alignment documentationyarn-project/sequencer-client/src/config.ts- Import timetable constants and shared sequencer config mappings from stdlibyarn-project/sequencer-client/src/sequencer/timetable.ts- Import from stdlibyarn-project/archiver/src/factory.ts- IncludetargetCommitteeSizetargetCommitteeSizeandgetL1ConstantsmocksTesting
topic_score_params.ts(46 tests) verify:calculateBlocksPerSlot- single block mode and MBPS modegetDecayWindowSlots- frequency-based decay window selectioncomputeDecay- mathematical correctness (decays to ~1% over window)computeConvergence- geometric series formulacomputeThreshold- conservative threshold calculationgetExpectedMessagesPerSlot- per-topic expected ratesTopicScoreParamsFactory- shared value computation, per-topic paramsDocumentation
Added comprehensive README at
yarn-project/p2p/src/services/gossipsub/README.mdcovering:Fixes A-265