From 8d8f62bf679128aa6bb5bb7f9b61ecf30ce174d3 Mon Sep 17 00:00:00 2001 From: bhartnett <51288821+bhartnett@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:17:16 +0800 Subject: [PATCH] Fluffy: Improve logging and add offer metrics to status logs. (#2802) * Set offer processing logs to debug level and add offer counts to state network. * Use metrics instead of int counters and remove from logs. * More logging improvements. Make decoding and validation failures use error log level. * Add protocol_id to metrics. --- fluffy/network/beacon/beacon_network.nim | 2 +- fluffy/network/history/history_network.nim | 2 +- fluffy/network/state/state_network.nim | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fluffy/network/beacon/beacon_network.nim b/fluffy/network/beacon/beacon_network.nim index c397c1f98..9e8c289d6 100644 --- a/fluffy/network/beacon/beacon_network.nim +++ b/fluffy/network/beacon/beacon_network.nim @@ -355,7 +355,7 @@ proc validateContent( let contentId = contentIdOpt.get() n.portalProtocol.storeContent(contentKey, contentId, contentItem) - info "Received offered content validated successfully", contentKey + debug "Received offered content validated successfully", contentKey else: error "Received offered content failed validation", contentKey, error = validation.error diff --git a/fluffy/network/history/history_network.nim b/fluffy/network/history/history_network.nim index 76d8ca6e5..0a9d59114 100644 --- a/fluffy/network/history/history_network.nim +++ b/fluffy/network/history/history_network.nim @@ -705,7 +705,7 @@ proc validateContent( n.portalProtocol.storeContent(contentKey, contentId, contentItem) - info "Received offered content validated successfully", contentKey + debug "Received offered content validated successfully", contentKey else: error "Received offered content failed validation", contentKey return false diff --git a/fluffy/network/state/state_network.nim b/fluffy/network/state/state_network.nim index 5211751a6..5ed2fac9d 100644 --- a/fluffy/network/state/state_network.nim +++ b/fluffy/network/state/state_network.nim @@ -11,6 +11,7 @@ import results, chronos, chronicles, + metrics, eth/common/hashes, eth/p2p/discoveryv5/[protocol, enr], ../../database/content_db, @@ -25,6 +26,11 @@ export results, state_content, hashes logScope: topics = "portal_state" +declareCounter state_network_offers_success, + "Portal state network offers successfully validated", labels = ["protocol_id"] +declareCounter state_network_offers_failed, + "Portal state network offers which failed validation", labels = ["protocol_id"] + type StateNetwork* = ref object portalProtocol*: PortalProtocol contentQueue*: AsyncQueue[(Opt[NodeId], ContentKeysList, seq[seq[byte]])] @@ -84,8 +90,7 @@ proc getContent( if maybeLocalContent.isSome(): let contentValue = V.decode(maybeLocalContent.get()).valueOr: - error "Unable to decode state local content value" - return Opt.none(V) + raiseAssert("Unable to decode state local content value") info "Fetched state local content value" return Opt.some(contentValue) @@ -100,11 +105,11 @@ proc getContent( contentValueBytes = contentLookupResult.content let contentValue = V.decode(contentValueBytes).valueOr: - warn "Unable to decode state content value from content lookup" + error "Unable to decode state content value from content lookup" continue validateRetrieval(key, contentValue).isOkOr: - warn "Validation of retrieved state content failed" + error "Validation of retrieved state content failed" continue info "Fetched valid state content from the network" @@ -178,7 +183,6 @@ proc processOffer*( n.portalProtocol.storeContent( contentKeyBytes, contentId, contentValue.toRetrievalValue().encode() ) - debug "Offered content validated successfully", contentKeyBytes await gossipOffer( n.portalProtocol, maybeSrcNodeId, contentKeyBytes, contentValueBytes @@ -218,10 +222,13 @@ proc processContentLoop(n: StateNetwork) {.async: (raises: []).} = srcNodeId, contentKeyBytes, contentBytes, contentKey.contractCodeKey, ContractCodeOffer, ) + if offerRes.isOk(): - info "Offered content processed successfully", contentKeyBytes + state_network_offers_success.inc(labelValues = [$n.portalProtocol.protocolId]) + debug "Received offered content validated successfully", contentKeyBytes else: - error "Offered content processing failed", + state_network_offers_failed.inc(labelValues = [$n.portalProtocol.protocolId]) + error "Received offered content failed validation", contentKeyBytes, error = offerRes.error() except CancelledError: trace "processContentLoop canceled"