Skip to content

Commit

Permalink
chore(rln-relay): log levels for certain logs (#1986)
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc authored Sep 4, 2023
1 parent 4ed4145 commit 97a7c9d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions waku/waku_rln_relay/rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ proc validateMessage*(rlnPeer: WakuRLNRelay,
# calculate the gaps
gap = absDiff(epoch, msgEpoch)

debug "epoch info", currentEpoch = fromEpoch(epoch), msgEpoch = fromEpoch(msgEpoch)
trace "epoch info", currentEpoch = fromEpoch(epoch), msgEpoch = fromEpoch(msgEpoch)

# validate the epoch
if gap > MaxEpochGap:
Expand All @@ -208,7 +208,7 @@ proc validateMessage*(rlnPeer: WakuRLNRelay,

let rootValidationRes = rlnPeer.groupManager.validateRoot(proof.merkleRoot)
if not rootValidationRes:
debug "invalid message: provided root does not belong to acceptable window of roots", provided=proof.merkleRoot.inHex(), validRoots=rlnPeer.groupManager.validRoots.mapIt(it.inHex())
warn "invalid message: provided root does not belong to acceptable window of roots", provided=proof.merkleRoot.inHex(), validRoots=rlnPeer.groupManager.validRoots.mapIt(it.inHex())
waku_rln_invalid_messages_total.inc(labelValues=["invalid_root"])
return MessageValidationResult.Invalid

Expand All @@ -227,7 +227,7 @@ proc validateMessage*(rlnPeer: WakuRLNRelay,
return MessageValidationResult.Invalid
if not proofVerificationRes.value():
# invalid proof
debug "invalid message: invalid proof", payloadLen = msg.payload.len
warn "invalid message: invalid proof", payloadLen = msg.payload.len
waku_rln_invalid_messages_total.inc(labelValues=["invalid_proof"])
return MessageValidationResult.Invalid

Expand All @@ -240,11 +240,11 @@ proc validateMessage*(rlnPeer: WakuRLNRelay,
if hasDup.isErr():
waku_rln_errors_total.inc(labelValues=["duplicate_check"])
elif hasDup.value == true:
debug "invalid message: message is spam", payloadLen = msg.payload.len
trace "invalid message: message is spam", payloadLen = msg.payload.len
waku_rln_spam_messages_total.inc()
return MessageValidationResult.Spam

debug "message is valid", payloadLen = msg.payload.len
trace "message is valid", payloadLen = msg.payload.len
let rootIndex = rlnPeer.groupManager.indexOfRoot(proof.merkleRoot)
waku_rln_valid_messages_total.observe(rootIndex.toFloat())
return MessageValidationResult.Valid
Expand Down Expand Up @@ -314,9 +314,9 @@ proc generateRlnValidator*(wakuRlnRelay: WakuRLNRelay,
wakuRlnRelay.messageBucket.get().tryConsume(message.data.len):
return pubsub.ValidationResult.Accept
else:
info "message bandwidth limit exceeded, running rate limit proof validation"
trace "message bandwidth limit exceeded, running rate limit proof validation"
except OverflowDefect: # not a problem
debug "not enough bandwidth, running rate limit proof validation"
trace "not enough bandwidth, running rate limit proof validation"

let decodeRes = WakuMessage.decode(message.data)
if decodeRes.isOk():
Expand All @@ -341,15 +341,12 @@ proc generateRlnValidator*(wakuRlnRelay: WakuRLNRelay,
payload = string.fromBytes(wakumessage.payload)
case validationRes:
of Valid:
debug "message validity is verified, relaying:", contentTopic=wakumessage.contentTopic, epoch=epoch, timestamp=wakumessage.timestamp, payload=payload
trace "message validity is verified, relaying:", proof=proof, root=root, shareX=shareX, shareY=shareY, nullifier=nullifier
return pubsub.ValidationResult.Accept
of Invalid:
debug "message validity could not be verified, discarding:", contentTopic=wakumessage.contentTopic, epoch=epoch, timestamp=wakumessage.timestamp, payload=payload
trace "message validity could not be verified, discarding:", proof=proof, root=root, shareX=shareX, shareY=shareY, nullifier=nullifier
return pubsub.ValidationResult.Reject
of Spam:
debug "A spam message is found! yay! discarding:", contentTopic=wakumessage.contentTopic, epoch=epoch, timestamp=wakumessage.timestamp, payload=payload
trace "A spam message is found! yay! discarding:", proof=proof, root=root, shareX=shareX, shareY=shareY, nullifier=nullifier
if spamHandler.isSome():
let handler = spamHandler.get()
Expand Down Expand Up @@ -411,7 +408,6 @@ proc new*(T: type WakuRlnRelay,
## Mounts the rln-relay protocol on the node.
## The rln-relay protocol can be mounted in two modes: on-chain and off-chain.
## Returns an error if the rln-relay protocol could not be mounted.
debug "rln-relay input validation passed"
try:
let rlnRelay = await mount(conf, registrationHandler)
return ok(rlnRelay)
Expand Down

0 comments on commit 97a7c9d

Please sign in to comment.