Adjust some portal wire and history network (error) logging (#2965)

This commit is contained in:
Kim De Mey 2024-12-21 20:22:16 +07:00 committed by GitHub
parent 473da69043
commit 7112a19d6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 10 deletions

View File

@ -142,11 +142,12 @@ proc getVerifiedBlockHeader*(
for i in 0 ..< (1 + n.contentRequestRetries):
let
headerContent = (await n.portalProtocol.contentLookup(contentKey, contentId)).valueOr:
warn "Failed fetching block header with proof from the network"
debug "Failed fetching block header with proof from the network"
return Opt.none(Header)
header = validateCanonicalHeaderBytes(headerContent.content, id, n.accumulator).valueOr:
warn "Validation of block header failed", error = error
warn "Validation of block header failed",
error = error, node = headerContent.receivedFrom.record.toURI()
continue
debug "Fetched valid block header from the network"
@ -186,11 +187,12 @@ proc getBlockBody*(
for i in 0 ..< (1 + n.contentRequestRetries):
let
bodyContent = (await n.portalProtocol.contentLookup(contentKey, contentId)).valueOr:
warn "Failed fetching block body from the network"
debug "Failed fetching block body from the network"
return Opt.none(BlockBody)
body = validateBlockBodyBytes(bodyContent.content, header).valueOr:
warn "Validation of block body failed", error
warn "Validation of block body failed",
error, node = bodyContent.receivedFrom.record.toURI()
continue
debug "Fetched block body from the network"
@ -217,7 +219,7 @@ proc getBlock*(
# also the original type into the network.
let
header = (await n.getVerifiedBlockHeader(id)).valueOr:
warn "Failed to get header when getting block", id
debug "Failed to get header when getting block", id
return Opt.none(Block)
hash =
when id is Hash32:
@ -225,7 +227,7 @@ proc getBlock*(
else:
header.rlpHash()
body = (await n.getBlockBody(hash, header)).valueOr:
warn "Failed to get body when getting block", hash
debug "Failed to get body when getting block", hash
return Opt.none(Block)
Opt.some((header, body))
@ -261,10 +263,11 @@ proc getReceipts*(
for i in 0 ..< (1 + n.contentRequestRetries):
let
receiptsContent = (await n.portalProtocol.contentLookup(contentKey, contentId)).valueOr:
warn "Failed fetching receipts from the network"
debug "Failed fetching receipts from the network"
return Opt.none(seq[Receipt])
receipts = validateReceiptsBytes(receiptsContent.content, header.receiptsRoot).valueOr:
warn "Validation of receipts failed", error
warn "Validation of receipts failed",
error, node = receiptsContent.receivedFrom.record.toURI()
continue
debug "Fetched receipts from the network"

View File

@ -205,6 +205,7 @@ type
ContentLookupResult* = object
content*: seq[byte]
utpTransfer*: bool
receivedFrom*: Node
# List of nodes which do not have requested content, and for which
# content is in their range
nodesInterestedInContent*: seq[Node]
@ -238,11 +239,13 @@ func init*(
T: type ContentLookupResult,
content: seq[byte],
utpTransfer: bool,
receivedFrom: Node,
nodesInterestedInContent: seq[Node],
): T =
ContentLookupResult(
content: content,
utpTransfer: utpTransfer,
receivedFrom: receivedFrom,
nodesInterestedInContent: nodesInterestedInContent,
)
@ -890,7 +893,8 @@ proc offer(
if m.contentKeys.len() != contentKeysLen:
# TODO:
# When there is such system, the peer should get scored negatively here.
error "Accepted content key bitlist has invalid size"
error "Accepted content key bitlist has invalid size",
bitListLen = m.contentKeys.len(), contentKeysLen
return err("Accepted content key bitlist has invalid size")
let acceptedKeysAmount = m.contentKeys.countOnes()
@ -1232,7 +1236,7 @@ proc contentLookup*(
)
return Opt.some(
ContentLookupResult.init(
content.content, content.utpTransfer, nodesWithoutContent
content.content, content.utpTransfer, content.src, nodesWithoutContent
)
)
else: