mirror of https://github.com/status-im/nim-eth.git
Improve the discv5 initialization logs (#552)
- Unify the debug log and info log into one. Removing the redundant information - Log the custom ENR fields more pretty - Make the JSON format logging more pretty for several types
This commit is contained in:
parent
86b37bf72e
commit
70b83a4efb
|
@ -13,6 +13,7 @@
|
|||
import
|
||||
std/[strutils, macros, algorithm, options],
|
||||
nimcrypto/[keccak, utils], stew/shims/net, stew/[base64, results],
|
||||
chronicles,
|
||||
".."/../[rlp, keys]
|
||||
|
||||
export options, results, keys
|
||||
|
@ -489,6 +490,9 @@ proc `$`(f: Field): string =
|
|||
of kList:
|
||||
"(Raw RLP list) " & "0x" & f.listRaw.toHex
|
||||
|
||||
func `$`*(fp: FieldPair): string =
|
||||
fp[0] & ":" & $fp[1]
|
||||
|
||||
proc `$`*(r: Record): string =
|
||||
result = "("
|
||||
result &= $r.seqNum
|
||||
|
@ -526,3 +530,5 @@ proc read*(rlp: var Rlp, T: typedesc[Record]):
|
|||
|
||||
proc append*(rlpWriter: var RlpWriter, value: Record) =
|
||||
rlpWriter.appendRawBytes(value.raw)
|
||||
|
||||
chronicles.formatIt(seq[FieldPair]): $it
|
||||
|
|
|
@ -104,7 +104,6 @@ func shortLog*(id: NodeId): string =
|
|||
result.add("*")
|
||||
for i in (len(sid) - 6)..sid.high:
|
||||
result.add(sid[i])
|
||||
chronicles.formatIt(NodeId): shortLog(it)
|
||||
|
||||
func hash*(a: Address): hashes.Hash =
|
||||
let res = a.ip.hash !& a.port.hash
|
||||
|
@ -121,7 +120,6 @@ func shortLog*(n: Node): string =
|
|||
shortLog(n.id) & ":unaddressable"
|
||||
else:
|
||||
shortLog(n.id) & ":" & $n.address.get()
|
||||
chronicles.formatIt(Node): shortLog(it)
|
||||
|
||||
func shortLog*(nodes: seq[Node]): string =
|
||||
result = "["
|
||||
|
@ -135,4 +133,8 @@ func shortLog*(nodes: seq[Node]): string =
|
|||
result.add(shortLog(n))
|
||||
|
||||
result.add("]")
|
||||
|
||||
chronicles.formatIt(NodeId): shortLog(it)
|
||||
chronicles.formatIt(Address): $it
|
||||
chronicles.formatIt(Node): shortLog(it)
|
||||
chronicles.formatIt(seq[Node]): shortLog(it)
|
||||
|
|
|
@ -173,6 +173,9 @@ const
|
|||
responseTimeout: defaultResponseTimeout
|
||||
)
|
||||
|
||||
chronicles.formatIt(Option[Port]): $it
|
||||
chronicles.formatIt(Option[ValidIpAddress]): $it
|
||||
|
||||
proc addNode*(d: Protocol, node: Node): bool =
|
||||
## Add `Node` to discovery routing table.
|
||||
##
|
||||
|
@ -967,7 +970,7 @@ proc newProtocol*(
|
|||
# Anyhow, nim-beacon-chain would also require some changes to support port
|
||||
# remapping through NAT and this API is also subject to change once we
|
||||
# introduce support for ipv4 + ipv6 binding/listening.
|
||||
let extraFields = mapIt(localEnrFields, toFieldPair(it[0], it[1]))
|
||||
let customEnrFields = mapIt(localEnrFields, toFieldPair(it[0], it[1]))
|
||||
# TODO:
|
||||
# - Defect as is now or return a result for enr errors?
|
||||
# - In case incorrect key, allow for new enr based on new key (new node id)?
|
||||
|
@ -975,18 +978,14 @@ proc newProtocol*(
|
|||
if previousRecord.isSome():
|
||||
record = previousRecord.get()
|
||||
record.update(privKey, enrIp, enrTcpPort, enrUdpPort,
|
||||
extraFields).expect("Record within size limits and correct key")
|
||||
customEnrFields).expect("Record within size limits and correct key")
|
||||
else:
|
||||
record = enr.Record.init(1, privKey, enrIp, enrTcpPort, enrUdpPort,
|
||||
extraFields).expect("Record within size limits")
|
||||
customEnrFields).expect("Record within size limits")
|
||||
|
||||
debug "Initializing discovery v5",
|
||||
enrIp, enrTcpPort, enrUdpPort, enrAutoUpdate,
|
||||
bootstrapEnrs = bootstrapRecords, localEnrFields,
|
||||
bindPort, bindIp
|
||||
|
||||
info "ENR initialized", ip = enrIp, tcp = enrTcpPort, udp = enrUdpPort,
|
||||
seqNum = record.seqNum, uri = toURI(record)
|
||||
info "Discovery ENR initialized", enrAutoUpdate, seqNum = record.seqNum,
|
||||
ip = enrIp, tcpPort = enrTcpPort, udpPort = enrUdpPort,
|
||||
customEnrFields, uri = toURI(record)
|
||||
if enrIp.isNone():
|
||||
if enrAutoUpdate:
|
||||
notice "No external IP provided for the ENR, this node will not be " &
|
||||
|
|
Loading…
Reference in New Issue