chore: asyncSpwan trackRoots

This commit is contained in:
darshankabariya 2025-04-09 02:36:31 +05:30
parent 251844dc53
commit da629f4861
3 changed files with 28 additions and 27 deletions

View File

@ -165,7 +165,7 @@ nimbus-build-system-nimble-dir:
.PHONY: librln
LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
LIBRLN_VERSION := v0.5.1
LIBRLN_VERSION := v0.7.0
ifeq ($(detected_OS),Windows)
LIBRLN_FILE := rln.lib

View File

@ -188,39 +188,39 @@ proc updateRoots*(g: OnchainGroupManager): Future[bool] {.async.} =
discard g.validRoots.popFirst()
g.validRoots.addLast(merkleRoot)
debug "~~~~~~~~~~~~~ Detected new Merkle root ~~~~~~~~~~~~~~~~",
debug "------ Detected new Merkle root -------",
root = merkleRoot.toHex, totalRoots = g.validRoots.len
return true
else:
debug "~~~~~~~~~~~~~ No new Merkle root ~~~~~~~~~~~~~~~~",
debug "------ No new Merkle root ------",
root = merkleRoot.toHex, totalRoots = g.validRoots.len
return false
# proc trackRootChanges*(g: OnchainGroupManager): Future[void] {.async.} =
# ## Continuously track changes to the Merkle root
# initializedGuard(g)
#
# let ethRpc = g.ethRpc.get()
# let wakuRlnContract = g.wakuRlnContract.get()
#
# # Set up the polling interval - more frequent to catch roots
# const rpcDelay = 5.seconds
#
# info "Starting to track Merkle root changes"
#
# while true:
# debug "starting to update roots"
# let rootUpdated = await g.updateRoots()
#
# if rootUpdated:
# let proofResult = await g.fetchMerkleProofElements()
# if proofResult.isErr():
# error "Failed to fetch Merkle proof", error = proofResult.error
# g.merkleProofCache = proofResult.get()
#
# debug "sleeping for 5 seconds"
# await sleepAsync(rpcDelay)
proc trackRootChanges*(g: OnchainGroupManager) {.async.} =
## Continuously track changes to the Merkle root
initializedGuard(g)
let ethRpc = g.ethRpc.get()
let wakuRlnContract = g.wakuRlnContract.get()
# Set up the polling interval - more frequent to catch roots
const rpcDelay = 5.seconds
info "------ Starting to track Merkle root changes ------",
while true:
debug "------ starting to update roots ------",
let rootUpdated = await g.updateRoots()
if rootUpdated:
let proofResult = await g.fetchMerkleProofElements()
if proofResult.isErr():
error "Failed to fetch Merkle proof", error = proofResult.error
g.merkleProofCache = proofResult.get()
debug "sleeping for 5 seconds"
await sleepAsync(rpcDelay)
method atomicBatch*(
g: OnchainGroupManager,

View File

@ -463,6 +463,7 @@ proc mount(
membershipIndex: conf.rlnRelayCredIndex,
onFatalErrorAction: conf.onFatalErrorAction,
)
asyncSpawn trackRootChanges(cast[OnchainGroupManager](groupManager))
# Initialize the groupManager
(await groupManager.init()).isOkOr: