Skip to main content
Peer scoring is a critical mechanism in Kona’s P2P network that evaluates the behavior and reliability of peers. By assigning scores to peers based on their performance, the network can prioritize connections with well-behaved peers and disconnect from malicious or poorly performing ones, ensuring overall network health and resilience. This guide demonstrates how to configure peer scoring in Kona’s P2P stack, including basic setup, advanced configurations, and monitoring strategies.

Understanding Peer Scoring

Peer scoring in Kona evaluates peers based on multiple factors:
  • Message Delivery: How reliably peers deliver messages
  • Mesh Participation: Active participation in gossipsub mesh
  • Invalid Messages: Penalties for invalid or malformed messages
  • IP Colocation: Penalties for multiple peers from the same IP
  • Behavior Patterns: General peer behavior and responsiveness
Peer scoring helps maintain network quality by identifying and removing peers that:
  • Fail to deliver messages reliably
  • Send invalid or spam messages
  • Exhibit malicious behavior patterns
  • Have poor network connectivity

Peer Score Levels

Kona supports two peer scoring levels:

Score Calculation Parameters

The scoring system uses several key parameters:

Basic Configuration

Using CLI Flags

Configure peer scoring via command-line flags:

Programmatic Configuration

Configure peer scoring in code:

Advanced Configuration

Topic Scoring Parameters

Configure topic-specific scoring based on block time:
Topic scoring is being phased out in the OP Stack. It’s disabled by default and should only be enabled for backwards compatibility or debugging purposes.Use the --p2p.topic-scoring flag to enable if needed.

Gossipsub Mesh Parameters

Fine-tune gossipsub mesh parameters for optimal performance:

Peer Score Thresholds

Configure thresholds that determine peer treatment:

Complete Example

Here’s a comprehensive example configuring P2P with peer scoring:

CLI Configuration Examples

Development Setup

Minimal scoring for local development:

Production Setup

Full peer scoring with monitoring:

High-Security Setup

Strict scoring with aggressive banning:

Monitoring Peer Scores

Kona inspects peer scores every 15 seconds and can automatically ban poorly performing peers:
Peer scores and banning events are recorded in metrics. Monitor these metrics to understand your node’s peer health:
  • kona_gossip_peer_scores: Histogram of peer scores
  • kona_gossip_banned_peers: Counter of banned peers
  • kona_gossip_peer_connection_duration_seconds: Connection durations

Best Practices

  1. Start with Light Scoring: Use PeerScoreLevel::Light for most deployments
  2. Monitor Before Banning: Run without banning initially to understand score distributions
  3. Adjust Thresholds Gradually: Start with default -100 threshold and adjust based on observations
  4. Consider Network Conditions: Increase ban duration in hostile environments
  5. Balance Security and Connectivity: Overly aggressive scoring can isolate your node
  6. Disable Topic Scoring: Unless specifically needed for compatibility
  7. Use Metrics: Monitor peer scores and ban events to tune configuration