Skip to content

feat: implement peer grief (de-prioritization) mechanism for the PeeStore#3786

Draft
fcecin wants to merge 1 commit into
masterfrom
feat/peer-prio
Draft

feat: implement peer grief (de-prioritization) mechanism for the PeeStore#3786
fcecin wants to merge 1 commit into
masterfrom
feat/peer-prio

Conversation

@fcecin
Copy link
Copy Markdown
Contributor

@fcecin fcecin commented Mar 28, 2026

Description

This PR adds a grief points (penalty points) tracker to peers in the PeerStore.

When selecting service peers for dialing, peers are separated into timed buckets, and buckets are shuffled internally. Buckets are wide enough to allow for randomness while gradually de-prioritizing peers that get pushed into deeper buckets.

Peers move back into better buckets over time in a lazy fashion, without requiring timers to recompute grief scores and reconfigure buckets. Peers that accumulate too many grief points are excluded from selection entirely until they cool down sufficiently back into the buckets that are considered for selection.

Any behavior from a remote peer that causes grief to the local peer, but isn't grounds for terminating a connection, can invoke PeerManager.griefPeer(peer, amount) to add penalty points to that peer.

Changes

  • Add GriefBook to PeerStore tracking per-peer grief scores with lazy cooldown
  • GriefData tuple stores score and cooldown timestamp; cooldown decays 1 point per GriefCooldownInterval (1 minute)
  • Add griefScore and griefCooldownTime fields to RemotePeerInfo
  • Add resolveGriefScore, griefPeer, getGriefScore procs on PeerStore
  • Add PeerManager.griefPeer helper for use from protocol clients
  • Replace shuffle() with sortByGriefScore in selectPeers and connectToRelayPeers
  • Bucket-based sorting (GriefBucketSize = 5): peers within the same bucket are shuffled randomly, preserving load distribution
  • Peers beyond MaxGriefBucket (bucket 3, score > 15) are excluded from selection entirely
  • Wire grief scoring into LightPush, Filter, Store, and PeerExchange clients
  • Fix pre-existing bug in PX test "Request fails gracefully": mount PeerExchangeClient so request() isn't called on a nil object
  • Add 13 unit tests for grief score infrastructure (cooldown, accumulation, remainder preservation, per-peer independence, etc.)
  • Add 6 tests for grief-based peer selection (bucket ordering, within-bucket shuffling, max bucket exclusion, etc.)

Issue

iterates #3784

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 28, 2026

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:3786

Built from 1896c92

Base automatically changed from feat/edge-sub-mgmt to master March 30, 2026 11:30
@fcecin
Copy link
Copy Markdown
Contributor Author

fcecin commented Mar 30, 2026

Rebased to latest master so now the diff (Files changed tab) makes sense.

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.

1 participant