Skip to content

Commit

Permalink
Fluffy: Improve logging and add offer metrics to status logs. (#2802)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bhartnett authored Oct 30, 2024
1 parent e038a38 commit 8d8f62b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fluffy/network/beacon/beacon_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fluffy/network/history/history_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions fluffy/network/state/state_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import
results,
chronos,
chronicles,
metrics,
eth/common/hashes,
eth/p2p/discoveryv5/[protocol, enr],
../../database/content_db,
Expand All @@ -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]])]
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 8d8f62b

Please sign in to comment.