| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Network.LibP2P.Protocol.GossipSub.Score
Description
GossipSub peer scoring (P1-P7) per docs/11-pubsub.md.
Score formula: Score(p) = TopicCap(Sum(t_i * (w1*P1 + w2*P2 + w3*P3 + w3b*P3b + w4*P4))) + w5*P5 + w6*P6 + w7*P7
All penalty parameters (P3, P3b, P4, P6, P7) use quadratic escalation: the score contribution is the square of the deficit/counter, mixed with a negative weight. This makes small deficits tolerable but large ones devastating.
Synopsis
- computeP1 :: TopicScoreParams -> TopicPeerState -> Double
- computeP2 :: TopicScoreParams -> TopicPeerState -> Double
- computeP3 :: TopicScoreParams -> TopicPeerState -> UTCTime -> Double
- computeP3b :: TopicPeerState -> Double
- computeP4 :: TopicPeerState -> Double
- computeP6 :: PeerScoreParams -> PeerState -> Map ByteString (Set PeerId) -> Double
- computeP7 :: PeerState -> Double
- computeScore :: PeerScoreParams -> PeerState -> Map ByteString (Set PeerId) -> UTCTime -> Double
- decayCounter :: Double -> Double -> Double
- decayPeerCounters :: PeerScoreParams -> PeerState -> PeerState
- recordFirstDelivery :: TopicScoreParams -> TopicPeerState -> TopicPeerState
- recordMeshDelivery :: TopicScoreParams -> TopicPeerState -> TopicPeerState
- recordInvalidMessage :: TopicPeerState -> TopicPeerState
- recordMeshFailure :: TopicScoreParams -> TopicPeerState -> TopicPeerState
- addP7Penalty :: PeerState -> PeerState
Individual score components
computeP1 :: TopicScoreParams -> TopicPeerState -> Double Source #
P1: Time in Mesh. Returns min(meshTime/quantum, cap). Only counts when peer is actually in mesh.
computeP2 :: TopicScoreParams -> TopicPeerState -> Double Source #
P2: First Message Deliveries. Returns min(counter, cap).
computeP3 :: TopicScoreParams -> TopicPeerState -> UTCTime -> Double Source #
P3: Mesh Message Deliveries. Returns deficit^2 when activated and below threshold. The weight (negative) is applied externally in computeScore.
computeP3b :: TopicPeerState -> Double Source #
P3b: Mesh Failure Penalty. Returns the stored penalty value (already squared at capture time).
computeP4 :: TopicPeerState -> Double Source #
P4: Invalid Messages. Returns counter^2.
computeP6 :: PeerScoreParams -> PeerState -> Map ByteString (Set PeerId) -> Double Source #
P6: IP Colocation Factor. Returns (count - threshold)^2 if count > threshold, else 0.
Aggregate score
computeScore :: PeerScoreParams -> PeerState -> Map ByteString (Set PeerId) -> UTCTime -> Double Source #
Compute full peer score per the formula in docs/11-pubsub.md. Takes explicit PeerId for the P5 application-specific callback.
Decay
decayPeerCounters :: PeerScoreParams -> PeerState -> PeerState Source #
Apply counter decay to all scoring counters in a PeerState.
Counter recording
recordFirstDelivery :: TopicScoreParams -> TopicPeerState -> TopicPeerState Source #
Record a first message delivery for a topic (P2 increment, capped).
recordMeshDelivery :: TopicScoreParams -> TopicPeerState -> TopicPeerState Source #
Record a mesh message delivery (P3 increment, capped).
recordInvalidMessage :: TopicPeerState -> TopicPeerState Source #
Record an invalid message delivery (P4 increment).
recordMeshFailure :: TopicScoreParams -> TopicPeerState -> TopicPeerState Source #
Record a mesh failure (P3b): capture deficit^2 at prune time. deficit = threshold - deliveries (clamped to >= 0).
addP7Penalty :: PeerState -> PeerState Source #
Increment P7 behavioral penalty counter by 1.