small cleanups from tcp-limits2 (#446)

This commit is contained in:
Dmitriy Ryajov 2020-11-23 15:02:23 -06:00 committed by GitHub
parent 1d16d22f5f
commit 034a1e8b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 20 deletions

View File

@ -216,6 +216,6 @@ proc init*(
when chronicles.enabledLogLevel == LogLevel.TRACE:
chann.name = if chann.name.len > 0: chann.name else: $chann.oid
trace "Created new lpchannel", chann, id, initiator
trace "Created new lpchannel", s = chann, id, initiator
return chann

View File

@ -117,7 +117,7 @@ method init*(f: FloodSub) =
await f.handleConn(conn, proto)
except CancelledError:
# This is top-level procedure which will work as separate task, so it
# do not need to propogate CancelledError.
# do not need to propagate CancelledError.
trace "Unexpected cancellation in floodsub handler", conn
except CatchableError as exc:
trace "FloodSub handler leaks an error", exc = exc.msg, conn

View File

@ -836,7 +836,8 @@ proc heartbeat(g: GossipSub) {.async.} =
except CancelledError as exc:
raise exc
except CatchableError as exc:
warn "exception ocurred in gossipsub heartbeat", exc = exc.msg, trace = exc.getStackTrace()
warn "exception ocurred in gossipsub heartbeat", exc = exc.msg,
trace = exc.getStackTrace()
for trigger in g.heartbeatEvents:
trace "firing heartbeat event", instance = cast[int](g)

View File

@ -129,7 +129,7 @@ proc handle*(p: PubSubPeer, conn: Connection) {.async.} =
await conn.close()
except CancelledError:
# This is top-level procedure which will work as separate task, so it
# do not need to propogate CancelledError.
# do not need to propagate CancelledError.
trace "Unexpected cancellation in PubSubPeer.handle"
except CatchableError as exc:
trace "Exception occurred in PubSubPeer.handle",
@ -193,6 +193,13 @@ proc sendImpl(conn: Connection, encoded: seq[byte]) {.async.} =
await conn.close() # This will clean up the send connection
template sendMetrics(msg: RPCMsg): untyped =
when defined(libp2p_expensive_metrics):
for x in msg.messages:
for t in x.topicIDs:
# metrics
libp2p_pubsub_sent_messages.inc(labelValues = [$p.peerId, t])
proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool) =
doAssert(not isNil(p), "pubsubpeer nil!")
@ -209,13 +216,15 @@ proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool) =
# some forms of valid but redundantly encoded protobufs with unknown or
# duplicated fields
let encoded = if p.hasObservers():
var mm = msg
# trigger send hooks
var mm = msg # hooks can modify the message
p.sendObservers(mm)
sendMetrics(mm)
encodeRpcMsg(mm, anonymize)
else:
# If there are no send hooks, we redundantly re-encode the message to
# protobuf for every peer - this could easily be improved!
sendMetrics(msg)
encodeRpcMsg(msg, anonymize)
if encoded.len <= 0:
@ -226,12 +235,6 @@ proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool) =
# connection to the spawned send task
asyncSpawn sendImpl(conn, encoded)
when defined(libp2p_expensive_metrics):
for x in msg.messages:
for t in x.topicIDs:
# metrics
libp2p_pubsub_sent_messages.inc(labelValues = [$p.peerId, t])
proc newPubSubPeer*(peerId: PeerID,
getConn: GetConn,
onEvent: OnEvent,