chore: trackMerkleRootchanges

This commit is contained in:
darshankabariya 2025-04-08 15:15:37 +05:30
parent ab95aef0b0
commit 33299660d9
2 changed files with 28 additions and 26 deletions

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): 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)
method atomicBatch*(
g: OnchainGroupManager,

View File

@ -468,6 +468,8 @@ proc mount(
onFatalErrorAction: conf.onFatalErrorAction,
)
asyncSpawn trackRootChanges(OnchainGroupManager(groupManager))
# Initialize the groupManager
(await groupManager.init()).isOkOr:
return err("could not initialize the group manager: " & $error)