Skip to content

Commit 82dff06

Browse files
authored
Portal client: Create metric to track successful and failed offer validations for all sub-networks (#3352)
1 parent 164405c commit 82dff06

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

portal/network/beacon/beacon_network.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import
1111
results,
1212
chronos,
1313
chronicles,
14+
metrics,
1415
eth/p2p/discoveryv5/[protocol, enr],
1516
beacon_chain/spec/forks,
1617
beacon_chain/gossip_processing/light_client_processor,
@@ -455,8 +456,13 @@ proc contentQueueWorker(n: BeaconNetwork) {.async: (raises: []).} =
455456
# TODO: Differentiate between failures due to invalid data and failures
456457
# due to missing network data for validation.
457458
if await n.validateContent(srcNodeId, contentKeys, contentItems):
459+
portal_offer_validation_successful.inc(
460+
labelValues = [$n.portalProtocol.protocolId]
461+
)
458462
discard
459463
await n.portalProtocol.randomGossip(srcNodeId, contentKeys, contentItems)
464+
else:
465+
portal_offer_validation_failed.inc(labelValues = [$n.portalProtocol.protocolId])
460466
except CancelledError:
461467
trace "contentQueueWorker canceled"
462468

portal/network/history/history_network.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import
1111
results,
1212
chronos,
1313
chronicles,
14+
metrics,
1415
eth/trie/ordered_trie,
1516
eth/common/[hashes, headers_rlp, blocks_rlp, receipts_rlp, transactions_rlp],
1617
eth/p2p/discoveryv5/[protocol, enr],
@@ -430,9 +431,15 @@ proc contentQueueWorker(n: HistoryNetwork) {.async: (raises: []).} =
430431
# TODO: Differentiate between failures due to invalid data and failures
431432
# due to missing network data for validation.
432433
if await n.validateContent(srcNodeId, contentKeys, contentItems):
434+
portal_offer_validation_successful.inc(
435+
labelValues = [$n.portalProtocol.protocolId]
436+
)
437+
433438
discard await n.portalProtocol.neighborhoodGossip(
434439
srcNodeId, contentKeys, contentItems
435440
)
441+
else:
442+
portal_offer_validation_failed.inc(labelValues = [$n.portalProtocol.protocolId])
436443
except CancelledError:
437444
trace "contentQueueWorker canceled"
438445

portal/network/state/state_network.nim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ export results, state_content, hashes
2626
logScope:
2727
topics = "portal_state"
2828

29-
declareCounter state_network_offers_success,
30-
"Portal state network offers successfully validated", labels = ["protocol_id"]
31-
declareCounter state_network_offers_failed,
32-
"Portal state network offers which failed validation", labels = ["protocol_id"]
33-
3429
const pingExtensionCapabilities = {CapabilitiesType, BasicRadiusType}
3530

3631
type StateNetwork* = ref object
@@ -249,17 +244,22 @@ proc contentQueueWorker(n: StateNetwork) {.async: (raises: []).} =
249244
)
250245

251246
if offerRes.isOk():
252-
state_network_offers_success.inc(labelValues = [$n.portalProtocol.protocolId])
247+
portal_offer_validation_successful.inc(
248+
labelValues = [$n.portalProtocol.protocolId]
249+
)
253250
debug "Received offered content validated successfully",
254251
srcNodeId, contentKeyBytes
255252
else:
253+
portal_offer_validation_failed.inc(
254+
labelValues = [$n.portalProtocol.protocolId]
255+
)
256+
error "Received offered content failed validation",
257+
srcNodeId, contentKeyBytes, error = offerRes.error()
258+
256259
if srcNodeId.isSome():
257260
n.portalProtocol.banNode(
258261
srcNodeId.get(), NodeBanDurationOfferFailedValidation
259262
)
260-
state_network_offers_failed.inc(labelValues = [$n.portalProtocol.protocolId])
261-
error "Received offered content failed validation",
262-
srcNodeId, contentKeyBytes, error = offerRes.error()
263263

264264
# The content validation failed so drop the remaining content (if any) from
265265
# this offer, because the remainly content is also likely to fail validation.

portal/network/wire/portal_protocol.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ declareHistogram portal_offer_log_distance,
126126
labels = ["protocol_id"],
127127
buckets = distanceBuckets
128128

129+
declarePublicCounter portal_offer_validation_successful,
130+
"Portal sub-network offers successfully validated", labels = ["protocol_id"]
131+
declarePublicCounter portal_offer_validation_failed,
132+
"Portal sub-network offers which failed validation", labels = ["protocol_id"]
133+
129134
logScope:
130135
topics = "portal_wire"
131136

@@ -328,7 +333,7 @@ proc banNode*(p: PortalProtocol, nodeId: NodeId, period: chronos.Duration) =
328333
proc isBanned*(p: PortalProtocol, nodeId: NodeId): bool =
329334
p.config.disableBanNodes == false and p.routingTable.isBanned(nodeId)
330335

331-
func `$`(id: PortalProtocolId): string =
336+
func `$`*(id: PortalProtocolId): string =
332337
id.toHex()
333338

334339
func fromNodeStatus(T: type NodeAddResult, status: NodeStatus): T =

0 commit comments

Comments
 (0)