From 1649c32325f0630b8318580288db53fe8aa428bf Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 31 Jul 2020 10:15:21 +0300 Subject: [PATCH] pubsub: only trace message for the blocks topic --- node/modules/lp2p/pubsub.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/node/modules/lp2p/pubsub.go b/node/modules/lp2p/pubsub.go index ac23f56a8..cd5b24fe4 100644 --- a/node/modules/lp2p/pubsub.go +++ b/node/modules/lp2p/pubsub.go @@ -301,7 +301,7 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) { return nil, err } - trw := newTracerWrapper(tr) + trw := newTracerWrapper(tr, build.BlocksTopic(in.Nn)) options = append(options, pubsub.WithEventTracer(trw)) } @@ -317,12 +317,27 @@ func HashMsgId(m *pubsub_pb.Message) string { return string(hash[:]) } -func newTracerWrapper(tr pubsub.EventTracer) pubsub.EventTracer { - return &tracerWrapper{tr: tr} +func newTracerWrapper(tr pubsub.EventTracer, topics ...string) pubsub.EventTracer { + topicsMap := make(map[string]struct{}) + for _, topic := range topics { + topicsMap[topic] = struct{}{} + } + return &tracerWrapper{tr: tr, topics: topicsMap} } type tracerWrapper struct { - tr pubsub.EventTracer + tr pubsub.EventTracer + topics map[string]struct{} +} + +func (trw *tracerWrapper) traceMessage(topics []string) bool { + for _, topic := range topics { + _, ok := trw.topics[topic] + if ok { + return true + } + } + return false } func (trw *tracerWrapper) Trace(evt *pubsub_pb.TraceEvent) { @@ -330,12 +345,18 @@ func (trw *tracerWrapper) Trace(evt *pubsub_pb.TraceEvent) { // JOIN/LEAVE/GRAFT/PRUNE/PUBLISH/DELIVER. This significantly reduces bandwidth usage and still // collects enough data to recover the state of the mesh and compute message delivery latency // distributions. + // Furthermore, we only trace message publication and deliveries for specified topics + // (here just the blocks topic). // TODO: hook all events into local metrics for inspection through the dashboard switch evt.GetType() { case pubsub_pb.TraceEvent_PUBLISH_MESSAGE: - trw.tr.Trace(evt) + if trw.traceMessage(evt.GetPublishMessage().Topics) { + trw.tr.Trace(evt) + } case pubsub_pb.TraceEvent_DELIVER_MESSAGE: - trw.tr.Trace(evt) + if trw.traceMessage(evt.GetDeliverMessage().Topics) { + trw.tr.Trace(evt) + } case pubsub_pb.TraceEvent_JOIN: trw.tr.Trace(evt) case pubsub_pb.TraceEvent_LEAVE: