From 741818ee675bcc709546c15214cedd3e11288dd7 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 31 Jul 2020 10:05:39 +0300 Subject: [PATCH 1/3] gomod: update go-libp2p-pubsub@feat/trace-topics --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f8c0130a1..870cc56d6 100644 --- a/go.mod +++ b/go.mod @@ -87,7 +87,7 @@ require ( github.com/libp2p/go-libp2p-mplex v0.2.4 github.com/libp2p/go-libp2p-peer v0.2.0 github.com/libp2p/go-libp2p-peerstore v0.2.6 - github.com/libp2p/go-libp2p-pubsub v0.3.3 + github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731070132-15504d8e8e4a github.com/libp2p/go-libp2p-quic-transport v0.7.1 github.com/libp2p/go-libp2p-record v0.1.3 github.com/libp2p/go-libp2p-routing-helpers v0.2.3 diff --git a/go.sum b/go.sum index 36d866647..1f206a41e 100644 --- a/go.sum +++ b/go.sum @@ -883,6 +883,8 @@ github.com/libp2p/go-libp2p-pubsub v0.1.1/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uz github.com/libp2p/go-libp2p-pubsub v0.3.2-0.20200527132641-c0712c6e92cf/go.mod h1:TxPOBuo1FPdsTjFnv+FGZbNbWYsp74Culx+4ViQpato= github.com/libp2p/go-libp2p-pubsub v0.3.3 h1:/AzOAmjDc+IJWybEzhYj1UaV1HErqmo4v3pQVepbgi8= github.com/libp2p/go-libp2p-pubsub v0.3.3/go.mod h1:DTMSVmZZfXodB/pvdTGrY2eHPZ9W2ev7hzTH83OKHrI= +github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731070132-15504d8e8e4a h1:QkNz5XZ83aEWXuL2a+UFhFH3ADf1LDYlCOPZXUI+wSs= +github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731070132-15504d8e8e4a/go.mod h1:DTMSVmZZfXodB/pvdTGrY2eHPZ9W2ev7hzTH83OKHrI= github.com/libp2p/go-libp2p-quic-transport v0.1.1/go.mod h1:wqG/jzhF3Pu2NrhJEvE+IE0NTHNXslOPn9JQzyCAxzU= github.com/libp2p/go-libp2p-quic-transport v0.5.0 h1:BUN1lgYNUrtv4WLLQ5rQmC9MCJ6uEXusezGvYRNoJXE= github.com/libp2p/go-libp2p-quic-transport v0.5.0/go.mod h1:IEcuC5MLxvZ5KuHKjRu+dr3LjCT1Be3rcD/4d8JrX8M= From 1649c32325f0630b8318580288db53fe8aa428bf Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 31 Jul 2020 10:15:21 +0300 Subject: [PATCH 2/3] 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: From 886e2e57dc313af6b0f68d42f632af62818c675e Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 31 Jul 2020 19:17:09 +0300 Subject: [PATCH 3/3] gomod: update go-libp2p-pubsub@master --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 870cc56d6..b6e38fc2d 100644 --- a/go.mod +++ b/go.mod @@ -87,7 +87,7 @@ require ( github.com/libp2p/go-libp2p-mplex v0.2.4 github.com/libp2p/go-libp2p-peer v0.2.0 github.com/libp2p/go-libp2p-peerstore v0.2.6 - github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731070132-15504d8e8e4a + github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731161531-2b5243c72f0d github.com/libp2p/go-libp2p-quic-transport v0.7.1 github.com/libp2p/go-libp2p-record v0.1.3 github.com/libp2p/go-libp2p-routing-helpers v0.2.3 diff --git a/go.sum b/go.sum index 1f206a41e..41c8dd237 100644 --- a/go.sum +++ b/go.sum @@ -881,10 +881,8 @@ github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1 github.com/libp2p/go-libp2p-protocol v0.1.0/go.mod h1:KQPHpAabB57XQxGrXCNvbL6UEXfQqUgC/1adR2Xtflk= github.com/libp2p/go-libp2p-pubsub v0.1.1/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uzw0t1Bp9R1znpR/Q= github.com/libp2p/go-libp2p-pubsub v0.3.2-0.20200527132641-c0712c6e92cf/go.mod h1:TxPOBuo1FPdsTjFnv+FGZbNbWYsp74Culx+4ViQpato= -github.com/libp2p/go-libp2p-pubsub v0.3.3 h1:/AzOAmjDc+IJWybEzhYj1UaV1HErqmo4v3pQVepbgi8= -github.com/libp2p/go-libp2p-pubsub v0.3.3/go.mod h1:DTMSVmZZfXodB/pvdTGrY2eHPZ9W2ev7hzTH83OKHrI= -github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731070132-15504d8e8e4a h1:QkNz5XZ83aEWXuL2a+UFhFH3ADf1LDYlCOPZXUI+wSs= -github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731070132-15504d8e8e4a/go.mod h1:DTMSVmZZfXodB/pvdTGrY2eHPZ9W2ev7hzTH83OKHrI= +github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731161531-2b5243c72f0d h1:1kfMc74C1DZGh97VJpA5efPXWU3tmdRF/wKYbFYya/4= +github.com/libp2p/go-libp2p-pubsub v0.3.4-0.20200731161531-2b5243c72f0d/go.mod h1:DTMSVmZZfXodB/pvdTGrY2eHPZ9W2ev7hzTH83OKHrI= github.com/libp2p/go-libp2p-quic-transport v0.1.1/go.mod h1:wqG/jzhF3Pu2NrhJEvE+IE0NTHNXslOPn9JQzyCAxzU= github.com/libp2p/go-libp2p-quic-transport v0.5.0 h1:BUN1lgYNUrtv4WLLQ5rQmC9MCJ6uEXusezGvYRNoJXE= github.com/libp2p/go-libp2p-quic-transport v0.5.0/go.mod h1:IEcuC5MLxvZ5KuHKjRu+dr3LjCT1Be3rcD/4d8JrX8M=