erigon-pulse/cl/sentinel/libp2p_settings.go
a 436493350e
Sentinel refactor (#8296)
1. changes sentinel to use an http-like interface

2. moves hexutil, crypto/blake2b, metrics packages to erigon-lib
2023-10-22 01:17:18 +02:00

67 lines
2.2 KiB
Go

package sentinel
import (
"math"
"time"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
)
// determines the decay rate from the provided time period till
// the decayToZero value. Ex: ( 1 -> 0.01)
func (s *Sentinel) scoreDecay(totalDurationDecay time.Duration) float64 {
numOfTimes := totalDurationDecay / s.oneSlotDuration()
return math.Pow(decayToZero, 1/float64(numOfTimes))
}
func (s *Sentinel) pubsubOptions() []pubsub.Option {
thresholds := &pubsub.PeerScoreThresholds{
GossipThreshold: -4000,
PublishThreshold: -8000,
GraylistThreshold: -16000,
AcceptPXThreshold: 100,
OpportunisticGraftThreshold: 5,
}
scoreParams := &pubsub.PeerScoreParams{
Topics: make(map[string]*pubsub.TopicScoreParams),
TopicScoreCap: 32.72,
AppSpecificScore: func(p peer.ID) float64 {
return 0
},
AppSpecificWeight: 1,
IPColocationFactorWeight: -35.11,
IPColocationFactorThreshold: 10,
IPColocationFactorWhitelist: nil,
BehaviourPenaltyWeight: -15.92,
BehaviourPenaltyThreshold: 6,
BehaviourPenaltyDecay: s.scoreDecay(10 * s.oneEpochDuration()), // 10 epochs
DecayInterval: s.oneSlotDuration(),
DecayToZero: decayToZero,
RetainScore: 100 * s.oneEpochDuration(), // Retain for 100 epochs
}
pubsubQueueSize := 600
psOpts := []pubsub.Option{
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign),
pubsub.WithMessageIdFn(s.msgId),
pubsub.WithNoAuthor(),
pubsub.WithPeerOutboundQueueSize(pubsubQueueSize),
pubsub.WithMaxMessageSize(int(s.cfg.NetworkConfig.GossipMaxSizeBellatrix)),
pubsub.WithValidateQueueSize(pubsubQueueSize),
pubsub.WithPeerScore(scoreParams, thresholds),
pubsub.WithGossipSubParams(pubsubGossipParam()),
}
return psOpts
}
// creates a custom gossipsub parameter set.
func pubsubGossipParam() pubsub.GossipSubParams {
gParams := pubsub.DefaultGossipSubParams()
gParams.Dlo = gossipSubDlo
gParams.D = gossipSubD
gParams.HeartbeatInterval = gossipSubHeartbeatInterval
gParams.HistoryLength = gossipSubMcacheLen
gParams.HistoryGossip = gossipSubMcacheGossip
return gParams
}