Fluffy: Log nodeId when receiving offers (#2856)

* Log nodeId when receiving offers.
This commit is contained in:
bhartnett 2024-11-21 20:17:38 +08:00 committed by GitHub
parent b671499fdc
commit 508ce79cdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 12 deletions

View File

@ -340,7 +340,10 @@ proc validateContent(
n.validateHistoricalSummaries(summariesWithProof)
proc validateContent(
n: BeaconNetwork, contentKeys: ContentKeysList, contentItems: seq[seq[byte]]
n: BeaconNetwork,
srcNodeId: Opt[NodeId],
contentKeys: ContentKeysList,
contentItems: seq[seq[byte]],
): Future[bool] {.async: (raises: [CancelledError]).} =
# content passed here can have less items then contentKeys, but not more.
for i, contentItem in contentItems:
@ -350,16 +353,16 @@ proc validateContent(
if validation.isOk():
let contentIdOpt = n.portalProtocol.toContentId(contentKey)
if contentIdOpt.isNone():
error "Received offered content with invalid content key", contentKey
error "Received offered content with invalid content key", srcNodeId, contentKey
return false
let contentId = contentIdOpt.get()
n.portalProtocol.storeContent(contentKey, contentId, contentItem)
debug "Received offered content validated successfully", contentKey
debug "Received offered content validated successfully", srcNodeId, contentKey
else:
debug "Received offered content failed validation",
contentKey, error = validation.error
srcNodeId, contentKey, error = validation.error
return false
return true
@ -432,7 +435,7 @@ proc processContentLoop(n: BeaconNetwork) {.async: (raises: []).} =
# dropped and not gossiped around.
# TODO: Differentiate between failures due to invalid data and failures
# due to missing network data for validation.
if await n.validateContent(contentKeys, contentItems):
if await n.validateContent(srcNodeId, contentKeys, contentItems):
asyncSpawn n.portalProtocol.randomGossipDiscardPeers(
srcNodeId, contentKeys, contentItems
)

View File

@ -359,7 +359,10 @@ proc new*(
)
proc validateContent(
n: HistoryNetwork, contentKeys: ContentKeysList, contentItems: seq[seq[byte]]
n: HistoryNetwork,
srcNodeId: Opt[NodeId],
contentKeys: ContentKeysList,
contentItems: seq[seq[byte]],
): Future[bool] {.async: (raises: [CancelledError]).} =
# content passed here can have less items then contentKeys, but not more.
for i, contentItem in contentItems:
@ -367,14 +370,15 @@ proc validateContent(
let res = await n.validateContent(contentItem, contentKey)
if res.isOk():
let contentId = n.portalProtocol.toContentId(contentKey).valueOr:
warn "Received offered content with invalid content key", contentKey
warn "Received offered content with invalid content key", srcNodeId, contentKey
return false
n.portalProtocol.storeContent(contentKey, contentId, contentItem)
debug "Received offered content validated successfully", contentKey
debug "Received offered content validated successfully", srcNodeId, contentKey
else:
debug "Received offered content failed validation", contentKey, error = res.error
debug "Received offered content failed validation",
srcNodeId, contentKey, error = res.error
return false
return true
@ -388,7 +392,7 @@ proc processContentLoop(n: HistoryNetwork) {.async: (raises: []).} =
# dropped and not gossiped around.
# TODO: Differentiate between failures due to invalid data and failures
# due to missing network data for validation.
if await n.validateContent(contentKeys, contentItems):
if await n.validateContent(srcNodeId, contentKeys, contentItems):
asyncSpawn n.portalProtocol.neighborhoodGossipDiscardPeers(
srcNodeId, contentKeys, contentItems
)

View File

@ -226,11 +226,12 @@ proc processContentLoop(n: StateNetwork) {.async: (raises: []).} =
if offerRes.isOk():
state_network_offers_success.inc(labelValues = [$n.portalProtocol.protocolId])
debug "Received offered content validated successfully", contentKeyBytes
debug "Received offered content validated successfully",
srcNodeId, contentKeyBytes
else:
state_network_offers_failed.inc(labelValues = [$n.portalProtocol.protocolId])
error "Received offered content failed validation",
contentKeyBytes, error = offerRes.error()
srcNodeId, contentKeyBytes, error = offerRes.error()
except CancelledError:
trace "processContentLoop canceled"