github.com/ethereum-optimism/optimism@v1.7.2/op-node/p2p/peer_scores.go (about)

     1  package p2p
     2  
     3  import (
     4  	log "github.com/ethereum/go-ethereum/log"
     5  	pubsub "github.com/libp2p/go-libp2p-pubsub"
     6  )
     7  
     8  // ConfigurePeerScoring configures the peer scoring parameters for the pubsub
     9  func ConfigurePeerScoring(gossipConf GossipSetupConfigurables, scorer Scorer, log log.Logger) []pubsub.Option {
    10  	// If we want to completely disable scoring config here, we can use the [peerScoringParams]
    11  	// to return early without returning any [pubsub.Option].
    12  	scoreParams := gossipConf.PeerScoringParams()
    13  	opts := []pubsub.Option{}
    14  	if scoreParams != nil {
    15  		peerScoreThresholds := NewPeerScoreThresholds()
    16  		// Create copy of params before modifying the AppSpecificScore
    17  		params := scoreParams.PeerScoring
    18  		params.AppSpecificScore = scorer.ApplicationScore
    19  		opts = []pubsub.Option{
    20  			pubsub.WithPeerScore(&params, &peerScoreThresholds),
    21  			pubsub.WithPeerScoreInspect(scorer.SnapshotHook(), peerScoreInspectFrequency),
    22  		}
    23  	} else {
    24  		log.Info("Peer scoring disabled")
    25  	}
    26  	return opts
    27  }