Commit 117fd621 authored by Andreas Bigger's avatar Andreas Bigger

feat: peer scoring config

parent f22dac93
package p2p
import (
"bufio"
"crypto/rand"
"encoding/hex"
"fmt"
......@@ -52,8 +51,7 @@ func Pub2PeerID(r io.Reader) (string, error) {
}
func readHexData(r io.Reader) ([]byte, error) {
reader := bufio.NewReader(os.Stdin)
data, err := reader.ReadString('\n')
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
......
......@@ -74,7 +74,7 @@ func (s *rpcServer) Start() error {
// The CORS and VHosts arguments below must be set in order for
// other services to connect to the opnode. VHosts in particular
// defaults to localhost, which will prevent containers from
// calling into the opnode with an "invalid host" error.
// calling into the opnode without an "invalid host" error.
nodeHandler := node.NewHTTPHandlerStack(srv, []string{"*"}, []string{"*"}, nil)
mux := http.NewServeMux()
......
......@@ -151,6 +151,8 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, cfg *rollup.Config, gossi
return nil, err
}
params := BuildGlobalGossipParams(cfg)
peerScoreParams := NewPeerScoreParams()
peerScoreThresholds := NewPeerScoreThresholds()
gossipOpts := []pubsub.Option{
pubsub.WithMaxMessageSize(maxGossipSize),
pubsub.WithMessageIdFn(BuildMsgIdFn(cfg)),
......@@ -165,6 +167,7 @@ func NewGossipSub(p2pCtx context.Context, h host.Host, cfg *rollup.Config, gossi
pubsub.WithBlacklist(denyList),
pubsub.WithGossipSubParams(params),
pubsub.WithEventTracer(&gossipTracer{m: m}),
pubsub.WithPeerScore(&peerScoreParams, &peerScoreThresholds),
pubsub.WithPeerScoreInspect(BuildPeerScoreInspector(m), peerScoreInspectFrequency),
}
gossipOpts = append(gossipOpts, gossipConf.ConfigureGossip(&params)...)
......
package p2p
import (
"math"
"time"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
)
// AppScoring scores peers based on application-specific metrics.
func AppScoring(p peer.ID) float64 {
return 0
}
// NewPeerScoreParams returns a default [pubsub.PeerScoreParams].
// See [PeerScoreParams] for detailed documentation.
//
// [PeerScoreParams]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreParams
func NewPeerScoreParams() pubsub.PeerScoreParams {
return pubsub.PeerScoreParams{
SkipAtomicValidation: false,
Topics: make(map[string]*pubsub.TopicScoreParams),
TopicScoreCap: 100, // Aggregate topic score cap (0 for no cap).
AppSpecificScore: AppScoring,
AppSpecificWeight: 1,
IPColocationFactorWeight: -1,
IPColocationFactorThreshold: 1,
BehaviourPenaltyWeight: -1,
BehaviourPenaltyDecay: 0.999,
DecayInterval: 24 * time.Hour,
DecayToZero: 0.01,
RetainScore: math.MaxInt64,
SeenMsgTTL: 0, // Defaults to global TimeCacheDuration when 0
}
}
// NewPeerScoreThresholds returns a default [pubsub.PeerScoreThresholds].
// See [PeerScoreThresholds] for detailed documentation.
//
// [PeerScoreThresholds]: https://pkg.go.dev/github.com/libp2p/go-libp2p-pubsub@v0.8.1#PeerScoreThresholds
func NewPeerScoreThresholds() pubsub.PeerScoreThresholds {
return pubsub.PeerScoreThresholds{
SkipAtomicValidation: false,
GossipThreshold: -10,
PublishThreshold: -40,
GraylistThreshold: -40,
AcceptPXThreshold: 20,
OpportunisticGraftThreshold: 0.05,
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment