Skip to content

Commit

Permalink
chore: more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc authored and stubbsta committed May 10, 2024
1 parent dde45c0 commit 33f49d9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion waku/waku_rln_relay/rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ proc hasDuplicate*(

# check if the epoch exists
let nullifier = proofMetadata.nullifier
debug "before: nullifierLog",
nl = rlnPeer.nullifierLog, epoch = fromEpoch(epoch), nullifier = inHex(nullifier)
if not rlnPeer.nullifierLog.hasKey(epoch):
return ok(false)
try:
Expand All @@ -142,18 +144,26 @@ proc updateLog*(
## Returns an error if it cannot update the log

# check if the epoch exists
debug "before: updateLog", nl = rlnPeer.nullifierLog, epoch = fromEpoch(epoch)
if not rlnPeer.nullifierLog.hasKeyOrPut(
epoch, {proofMetadata.nullifier: proofMetadata}.toTable()
):
debug "updated log", nl = rlnPeer.nullifierLog, epoch = fromEpoch(epoch)
return ok()
debug "before: updateLog, epoch exists",
nl = rlnPeer.nullifierLog, epoch = fromEpoch(epoch)

try:
# check if an identical record exists
if rlnPeer.nullifierLog[epoch].hasKeyOrPut(proofMetadata.nullifier, proofMetadata):
# the above condition could be `discarded` but it is kept for clarity, that slashing will
# be implemented here
# TODO: slashing logic
debug "duplicate message: slashing is not implemented yet",
epoch = fromEpoch(epoch), nullifier = inHex(proofMetadata.nullifier)
return ok()
debug "after: updateLog, no duplicate",
nl = rlnPeer.nullifierLog, epoch = fromEpoch(epoch)
return ok()
except KeyError:
return
Expand Down Expand Up @@ -274,6 +284,7 @@ proc validateMessageAndUpdateLog*(
## in future messages

let isValidMessage = rlnPeer.validateMessage(msg, timeOption)
debug "message validation result", isValidMessage = isValidMessage

let decodeRes = RateLimitProof.init(msg.proof)
if decodeRes.isErr():
Expand All @@ -287,6 +298,8 @@ proc validateMessageAndUpdateLog*(

# insert the message to the log (never errors)
discard rlnPeer.updateLog(msgProof.epoch, proofMetadataRes.get())
debug "message log updated",
epoch = fromEpoch(msgProof.epoch), nullifier = inHex(msgProof.nullifier)

return isValidMessage

Expand Down Expand Up @@ -325,11 +338,14 @@ proc clearNullifierLog(rlnPeer: WakuRlnRelay) =
# clear the first MaxEpochGap epochs of the nullifer log
# if more than MaxEpochGap epochs are in the log
# note: the epochs are ordered ascendingly
debug "clearing nullifier log",
count = rlnPeer.nullifierLog.len().uint, maxGap = rlnPeer.rlnMaxEpochGap
if rlnPeer.nullifierLog.len().uint < rlnPeer.rlnMaxEpochGap:
return

trace "clearing epochs from the nullifier log", count = rlnPeer.rlnMaxEpochGap
debug "clearing epochs from the nullifier log", count = rlnPeer.rlnMaxEpochGap
let epochsToClear = rlnPeer.nullifierLog.keys().toSeq()[0 ..< rlnPeer.rlnMaxEpochGap]
debug "epochs to clear", epochs = epochsToClear
for epoch in epochsToClear:
rlnPeer.nullifierLog.del(epoch)

Expand Down

0 comments on commit 33f49d9

Please sign in to comment.