Skip to content

Commit 508ce79

Browse files
authored
Fluffy: Log nodeId when receiving offers (#2856)
* Log nodeId when receiving offers.
1 parent b671499 commit 508ce79

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

fluffy/network/beacon/beacon_network.nim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ proc validateContent(
340340
n.validateHistoricalSummaries(summariesWithProof)
341341

342342
proc validateContent(
343-
n: BeaconNetwork, contentKeys: ContentKeysList, contentItems: seq[seq[byte]]
343+
n: BeaconNetwork,
344+
srcNodeId: Opt[NodeId],
345+
contentKeys: ContentKeysList,
346+
contentItems: seq[seq[byte]],
344347
): Future[bool] {.async: (raises: [CancelledError]).} =
345348
# content passed here can have less items then contentKeys, but not more.
346349
for i, contentItem in contentItems:
@@ -350,16 +353,16 @@ proc validateContent(
350353
if validation.isOk():
351354
let contentIdOpt = n.portalProtocol.toContentId(contentKey)
352355
if contentIdOpt.isNone():
353-
error "Received offered content with invalid content key", contentKey
356+
error "Received offered content with invalid content key", srcNodeId, contentKey
354357
return false
355358

356359
let contentId = contentIdOpt.get()
357360
n.portalProtocol.storeContent(contentKey, contentId, contentItem)
358361

359-
debug "Received offered content validated successfully", contentKey
362+
debug "Received offered content validated successfully", srcNodeId, contentKey
360363
else:
361364
debug "Received offered content failed validation",
362-
contentKey, error = validation.error
365+
srcNodeId, contentKey, error = validation.error
363366
return false
364367

365368
return true
@@ -432,7 +435,7 @@ proc processContentLoop(n: BeaconNetwork) {.async: (raises: []).} =
432435
# dropped and not gossiped around.
433436
# TODO: Differentiate between failures due to invalid data and failures
434437
# due to missing network data for validation.
435-
if await n.validateContent(contentKeys, contentItems):
438+
if await n.validateContent(srcNodeId, contentKeys, contentItems):
436439
asyncSpawn n.portalProtocol.randomGossipDiscardPeers(
437440
srcNodeId, contentKeys, contentItems
438441
)

fluffy/network/history/history_network.nim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,22 +359,26 @@ proc new*(
359359
)
360360

361361
proc validateContent(
362-
n: HistoryNetwork, contentKeys: ContentKeysList, contentItems: seq[seq[byte]]
362+
n: HistoryNetwork,
363+
srcNodeId: Opt[NodeId],
364+
contentKeys: ContentKeysList,
365+
contentItems: seq[seq[byte]],
363366
): Future[bool] {.async: (raises: [CancelledError]).} =
364367
# content passed here can have less items then contentKeys, but not more.
365368
for i, contentItem in contentItems:
366369
let contentKey = contentKeys[i]
367370
let res = await n.validateContent(contentItem, contentKey)
368371
if res.isOk():
369372
let contentId = n.portalProtocol.toContentId(contentKey).valueOr:
370-
warn "Received offered content with invalid content key", contentKey
373+
warn "Received offered content with invalid content key", srcNodeId, contentKey
371374
return false
372375

373376
n.portalProtocol.storeContent(contentKey, contentId, contentItem)
374377

375-
debug "Received offered content validated successfully", contentKey
378+
debug "Received offered content validated successfully", srcNodeId, contentKey
376379
else:
377-
debug "Received offered content failed validation", contentKey, error = res.error
380+
debug "Received offered content failed validation",
381+
srcNodeId, contentKey, error = res.error
378382
return false
379383

380384
return true
@@ -388,7 +392,7 @@ proc processContentLoop(n: HistoryNetwork) {.async: (raises: []).} =
388392
# dropped and not gossiped around.
389393
# TODO: Differentiate between failures due to invalid data and failures
390394
# due to missing network data for validation.
391-
if await n.validateContent(contentKeys, contentItems):
395+
if await n.validateContent(srcNodeId, contentKeys, contentItems):
392396
asyncSpawn n.portalProtocol.neighborhoodGossipDiscardPeers(
393397
srcNodeId, contentKeys, contentItems
394398
)

fluffy/network/state/state_network.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,12 @@ proc processContentLoop(n: StateNetwork) {.async: (raises: []).} =
226226

227227
if offerRes.isOk():
228228
state_network_offers_success.inc(labelValues = [$n.portalProtocol.protocolId])
229-
debug "Received offered content validated successfully", contentKeyBytes
229+
debug "Received offered content validated successfully",
230+
srcNodeId, contentKeyBytes
230231
else:
231232
state_network_offers_failed.inc(labelValues = [$n.portalProtocol.protocolId])
232233
error "Received offered content failed validation",
233-
contentKeyBytes, error = offerRes.error()
234+
srcNodeId, contentKeyBytes, error = offerRes.error()
234235
except CancelledError:
235236
trace "processContentLoop canceled"
236237

0 commit comments

Comments
 (0)