simplify libp2p logging (#1605)

and a few other small logging fixes
This commit is contained in:
Jacek Sieka 2020-09-06 10:39:25 +02:00 committed by Mamy Ratsimbazafy
parent 5a55ca8f47
commit 625e0912de
7 changed files with 11 additions and 12 deletions

View File

@ -90,4 +90,4 @@ type
ValidatorPool* = object ValidatorPool* = object
validators*: Table[ValidatorPubKey, AttachedValidator] validators*: Table[ValidatorPubKey, AttachedValidator]
proc shortLog*(v: AttachedValidator): string = shortLog(v.pubKey) func shortLog*(v: AttachedValidator): string = shortLog(v.pubKey)

View File

@ -197,13 +197,13 @@ type
template validator_keys*(e: EpochRef): untyped = e.validator_key_store[1][] template validator_keys*(e: EpochRef): untyped = e.validator_key_store[1][]
proc shortLog*(v: BlockSlot): string = func shortLog*(v: BlockSlot): string =
if v.blck.slot == v.slot: if v.blck.slot == v.slot:
&"{v.blck.root.data.toOpenArray(0, 3).toHex()}:{v.blck.slot}" &"{v.blck.root.data.toOpenArray(0, 3).toHex()}:{v.blck.slot}"
else: # There was a gap - log it else: # There was a gap - log it
&"{v.blck.root.data.toOpenArray(0, 3).toHex()}:{v.blck.slot}@{v.slot}" &"{v.blck.root.data.toOpenArray(0, 3).toHex()}:{v.blck.slot}@{v.slot}"
proc shortLog*(v: BlockRef): string = func shortLog*(v: BlockRef): string =
if v == nil: if v == nil:
"BlockRef(nil)" "BlockRef(nil)"
else: else:

View File

@ -17,7 +17,7 @@ import
libp2p/protocols/secure/[secure, secio], libp2p/protocols/secure/[secure, secio],
libp2p/protocols/pubsub/[pubsub, floodsub, gossipsub, rpc/message, rpc/messages], libp2p/protocols/pubsub/[pubsub, floodsub, gossipsub, rpc/message, rpc/messages],
libp2p/transports/tcptransport, libp2p/transports/tcptransport,
libp2p/stream/lpstream, libp2p/stream/connection,
eth/[keys, async_utils], eth/p2p/p2p_protocol_dsl, eth/[keys, async_utils], eth/p2p/p2p_protocol_dsl,
eth/net/nat, eth/p2p/discoveryv5/[enr, node], eth/net/nat, eth/p2p/discoveryv5/[enr, node],
# Beacon node modules # Beacon node modules
@ -26,7 +26,7 @@ import
peer_pool, spec/[datatypes, network], ./time peer_pool, spec/[datatypes, network], ./time
export export
version, multiaddress, peer_pool, peerinfo, p2pProtocol, version, multiaddress, peer_pool, peerinfo, p2pProtocol, connection,
libp2p_json_serialization, ssz_serialization, results libp2p_json_serialization, ssz_serialization, results
logScope: logScope:
@ -266,9 +266,8 @@ when libp2p_pki_schemes != "secp256k1":
template libp2pProtocol*(name: string, version: int) {.pragma.} template libp2pProtocol*(name: string, version: int) {.pragma.}
template `$`*(peer: Peer): string = id(peer.info) func shortLog*(peer: Peer): string = shortLog(peer.info.peerId)
chronicles.formatIt(Peer): $it chronicles.formatIt(Peer): shortLog(it)
chronicles.formatIt(PeerID): $it
template remote*(peer: Peer): untyped = template remote*(peer: Peer): untyped =
peer.info.peerId peer.info.peerId

View File

@ -2,7 +2,7 @@ import libp2p/daemon/daemonapi, json_serialization
export json_serialization export json_serialization
proc writeValue*(writer: var JsonWriter, value: PeerID) {.inline.} = proc writeValue*(writer: var JsonWriter, value: PeerID) {.inline.} =
writer.writeValue value.pretty writer.writeValue $value
proc readValue*(reader: var JsonReader, value: var PeerID) {.inline.} = proc readValue*(reader: var JsonReader, value: var PeerID) {.inline.} =
let res = PeerID.init reader.readValue(string) let res = PeerID.init reader.readValue(string)

View File

@ -121,7 +121,7 @@ proc readChunkPayload(conn: Connection, peer: Peer,
uint64(10 + size)) uint64(10 + size))
return ok SSZ.decode(data.get(), MsgType) return ok SSZ.decode(data.get(), MsgType)
else: else:
debug "Snappy decompression/read failed", msg = $data.error, conn = $conn debug "Snappy decompression/read failed", msg = $data.error, conn
return neterr InvalidSnappyBytes return neterr InvalidSnappyBytes
proc readResponseChunk(conn: Connection, peer: Peer, proc readResponseChunk(conn: Connection, peer: Peer,

View File

@ -125,7 +125,7 @@ func asEth2Digest*(x: BlockHash): Eth2Digest =
template asBlockHash(x: Eth2Digest): BlockHash = template asBlockHash(x: Eth2Digest): BlockHash =
BlockHash(x.data) BlockHash(x.data)
func shortLog(b: Eth1Block): string = func shortLog*(b: Eth1Block): string =
&"{b.number}:{shortLog b.voteData.block_hash}" &"{b.number}:{shortLog b.voteData.block_hash}"
func getDepositsInRange(eth1Chain: Eth1Chain, func getDepositsInRange(eth1Chain: Eth1Chain,

View File

@ -45,7 +45,7 @@ type
BlockRootsList* = List[Eth2Digest, Limit MAX_REQUEST_BLOCKS] BlockRootsList* = List[Eth2Digest, Limit MAX_REQUEST_BLOCKS]
proc shortLog*(s: StatusMsg): auto = func shortLog*(s: StatusMsg): auto =
( (
forkDigest: s.forkDigest, forkDigest: s.forkDigest,
finalizedRoot: shortLog(s.finalizedRoot), finalizedRoot: shortLog(s.finalizedRoot),