From 4a98a8af5a6b33e2c01ff34321c0127386037f79 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:09:31 +0900 Subject: [PATCH] gossip pruning fixes related to #371 (#385) * gossip pruning fixes related to #371 * better trace for grafted/pruned * shorted azure testing again --- libp2p.nimble | 2 -- libp2p/protocols/pubsub/gossipsub.nim | 7 ++++--- libp2p/protocols/pubsub/pubsubpeer.nim | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libp2p.nimble b/libp2p.nimble index f95e9252b..1393867db 100644 --- a/libp2p.nimble +++ b/libp2p.nimble @@ -59,8 +59,6 @@ task testpubsub_slim, "Runs pubsub tests": runTest("pubsub/testgossipinternal", sign = false, verify = false, moreoptions = "-d:pubsub_internal_testing") runTest("pubsub/testpubsub") runTest("pubsub/testpubsub", sign = false, verify = false, moreoptions = "-d:libp2p_pubsub_anonymize=true") - runTest("pubsub/testgossipinternal10", sign = false, verify = false, moreoptions = "-d:pubsub_internal_testing") - runTest("pubsub/testpubsub", moreoptions = "-d:fallback_gossipsub_10") task testfilter, "Run PKI filter test": runTest("testpkifilter", diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 7a60ef4fb..1122d5bfa 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -304,7 +304,7 @@ proc grafted(g: GossipSub, p: PubSubPeer, topic: string) = stats.topicInfos[topic] = info assert(g.peerStats[p].topicInfos[topic].inMesh == true) - trace "grafted", p + trace "grafted", peer=p, topic do: g.onNewPeer(p) g.grafted(p, topic) @@ -329,7 +329,7 @@ proc pruned(g: GossipSub, p: PubSubPeer, topic: string) = # mgetOrPut does not work, so we gotta do this without referencing stats.topicInfos[topic] = info - trace "pruned", p + trace "pruned", peer=p, topic proc peerExchangeList(g: GossipSub, topic: string): seq[PeerInfoMsg] = var peers = g.gossipsub.getOrDefault(topic, initHashSet[PubSubPeer]()).toSeq() @@ -367,7 +367,8 @@ method onPubSubPeerEvent*(p: GossipSub, peer: PubsubPeer, event: PubSubPeerEvent # If a send connection is lost, it's better to remove peer from the mesh - # if it gets reestablished, the peer will be readded to the mesh, and if it # doesn't, well.. then we hope the peer is going away! - for _, peers in p.mesh.mpairs(): + for topic, peers in p.mesh.mpairs(): + p.pruned(peer, topic) peers.excl(peer) for _, peers in p.fanout.mpairs(): peers.excl(peer) diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index a3ed50685..9f5d70903 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -227,7 +227,7 @@ proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool) = asyncSpawn sendImpl(conn, encoded) when defined(libp2p_expensive_metrics): - for x in mm.messages: + for x in msg.messages: for t in x.topicIDs: # metrics libp2p_pubsub_sent_messages.inc(labelValues = [$p.peerId, t])