From f2832aaa488f98f2856cc6294ce2d63da45e333b Mon Sep 17 00:00:00 2001 From: DarshanBPatel Date: Fri, 13 Dec 2024 02:30:57 +0530 Subject: [PATCH] chore: update according to review --- waku/waku_rln_relay/protocol_metrics.nim | 4 ++++ waku/waku_rln_relay/rln_relay.nim | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/waku/waku_rln_relay/protocol_metrics.nim b/waku/waku_rln_relay/protocol_metrics.nim index 04c3930b5e..11c4feddcc 100644 --- a/waku/waku_rln_relay/protocol_metrics.nim +++ b/waku/waku_rln_relay/protocol_metrics.nim @@ -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() = @@ -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 @@ -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 diff --git a/waku/waku_rln_relay/rln_relay.nim b/waku/waku_rln_relay/rln_relay.nim index bc2fb0c686..ee6d91b9bd 100644 --- a/waku/waku_rln_relay/rln_relay.nim +++ b/waku/waku_rln_relay/rln_relay.nim @@ -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 @@ -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*( @@ -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)