Add configuration in pubsub to trace locally to json file

This commit is contained in:
Matija Petrunic 2021-09-15 13:40:54 +02:00
parent d5a4b0637a
commit 8e6a01de6d
2 changed files with 17 additions and 4 deletions

View File

@ -309,6 +309,7 @@ type Pubsub struct {
DirectPeers []string DirectPeers []string
IPColocationWhitelist []string IPColocationWhitelist []string
RemoteTracer string RemoteTracer string
JsonTracerFile string
} }
type Chainstore struct { type Chainstore struct {

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net" "net"
"os"
"time" "time"
host "github.com/libp2p/go-libp2p-core/host" host "github.com/libp2p/go-libp2p-core/host"
@ -21,6 +22,7 @@ import (
"github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/modules/helpers" "github.com/filecoin-project/lotus/node/modules/helpers"
"github.com/filecoin-project/lotus/node/modules/tracer"
) )
func init() { func init() {
@ -55,10 +57,10 @@ type PeerScoreTracker interface {
type peerScoreTracker struct { type peerScoreTracker struct {
sk *dtypes.ScoreKeeper sk *dtypes.ScoreKeeper
lt LotusTracer lt tracer.LotusTracer
} }
func newPeerScoreTracker(lt LotusTracer, sk *dtypes.ScoreKeeper) PeerScoreTracker { func newPeerScoreTracker(lt tracer.LotusTracer, sk *dtypes.ScoreKeeper) PeerScoreTracker {
return &peerScoreTracker{ return &peerScoreTracker{
sk: sk, sk: sk,
lt: lt, lt: lt,
@ -67,7 +69,7 @@ func newPeerScoreTracker(lt LotusTracer, sk *dtypes.ScoreKeeper) PeerScoreTracke
func (pst *peerScoreTracker) UpdatePeerScore(scores map[peer.ID]*pubsub.PeerScoreSnapshot) { func (pst *peerScoreTracker) UpdatePeerScore(scores map[peer.ID]*pubsub.PeerScoreSnapshot) {
if pst.lt != nil { if pst.lt != nil {
pst.lt.TracePeerScore(scores) pst.lt.PeerScores(scores)
} }
pst.sk.Update(scores) pst.sk.Update(scores)
@ -364,6 +366,17 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
pubsub.NewAllowlistSubscriptionFilter(allowTopics...), pubsub.NewAllowlistSubscriptionFilter(allowTopics...),
100))) 100)))
var lt tracer.LotusTracer
if in.Cfg.JsonTracerFile != "" {
out, err := os.OpenFile(in.Cfg.JsonTracerFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660)
if err != nil {
return nil, err
}
jsonTransport := tracer.NewJsonTracerTransport(out)
lt = tracer.NewLotusTracer(jsonTransport, in.Host.ID())
}
// tracer // tracer
if in.Cfg.RemoteTracer != "" { if in.Cfg.RemoteTracer != "" {
a, err := ma.NewMultiaddr(in.Cfg.RemoteTracer) a, err := ma.NewMultiaddr(in.Cfg.RemoteTracer)
@ -381,7 +394,6 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
return nil, err return nil, err
} }
lt := newLotusTracer(tr)
pst := newPeerScoreTracker(lt, in.Sk) pst := newPeerScoreTracker(lt, in.Sk)
trw := newTracerWrapper(tr, lt, build.BlocksTopic(in.Nn)) trw := newTracerWrapper(tr, lt, build.BlocksTopic(in.Nn))