Skip to content

Commit

Permalink
chore: update according to review
Browse files Browse the repository at this point in the history
  • Loading branch information
darshankabariya committed Dec 12, 2024
1 parent f2bb352 commit f2832aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions waku/waku_rln_relay/protocol_metrics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ proc getRlnMetricsLogger*(): RLNMetricsLogger =
var cumulativeValidMessages = 0.float64
var cumulativeProofsVerified = 0.float64
var cumulativeProofsGenerated = 0.float64
var cumulativeProofsRemaining = 100.float64

when defined(metrics):
logMetrics = proc() =
Expand All @@ -103,6 +104,8 @@ proc getRlnMetricsLogger*(): RLNMetricsLogger =
)
let freshProofsGeneratedCount =
parseAndAccumulate(waku_rln_total_generated_proofs, cumulativeProofsGenerated)
let freshProofsRemainingCount =
parseAndAccumulate(waku_rln_remaining_proofs_per_epoch, cumulativeProofsRemaining)

info "Total messages", count = freshMsgCount
info "Total spam messages", count = freshSpamCount
Expand All @@ -111,4 +114,5 @@ proc getRlnMetricsLogger*(): RLNMetricsLogger =
info "Total errors", count = freshErrorCount
info "Total proofs verified", count = freshProofsVerifiedCount
info "Total proofs generated", count = freshProofsGeneratedCount
info "Total proofs remaining", count = freshProofsRemainingCount
return logMetrics
9 changes: 6 additions & 3 deletions waku/waku_rln_relay/rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ proc calcEpoch*(rlnPeer: WakuRLNRelay, t: float64): Epoch =
let e = uint64(t / rlnPeer.rlnEpochSizeSec.float64)
return toEpoch(e)

proc nextEpochTime*(rlnPeer: WakuRLNRelay, t: float64): float64 =
proc nextEpoch*(rlnPeer: WakuRLNRelay, t: float64): float64 =
# Calculates the next epoch time from the given time `t`.
let currentEpoch = rlnPeer.calcEpoch(t)
var timePtr = t
Expand Down Expand Up @@ -125,6 +125,7 @@ proc stop*(rlnPeer: WakuRLNRelay) {.async: (raises: [Exception]).} =

# stop the group sync, and flush data to tree db
info "stopping rln-relay"
await rlnPeer.epochMonitorFuture.cancelAndWait()
await rlnPeer.groupManager.stop()

proc hasDuplicate*(
Expand Down Expand Up @@ -416,15 +417,17 @@ proc generateRlnValidator*(
return validator

proc monitorEpochs(wakuRlnRelay: WakuRLNRelay): Future[void] {.async.} =
let nextEpochTime = wakuRlnRelay.nextEpoch(epochTime())
await sleepAsync(int((nextEpochTime - epochTime()) * 1000))

while true:
try:
waku_rln_remaining_proofs_per_epoch.set(
wakuRlnRelay.groupManager.userMessageLimit.get().float64
)
let nextEpochTime = wakuRlnRelay.nextEpochTime(epochTime())
await sleepAsync(int((nextEpochTime - epochTime()) * 1000))
except CatchableError:
error "Error in epoch monitoring", error = getCurrentExceptionMsg()
await sleepAsync(int(wakuRlnRelay.rlnEpochSizeSec * 1000))

proc mount(
conf: WakuRlnConfig, registrationHandler = none(RegistrationHandler)
Expand Down

0 comments on commit f2832aa

Please sign in to comment.