mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-03-15 00:53:11 +00:00
chore: trackMerkleRootchanges
This commit is contained in:
parent
ab95aef0b0
commit
33299660d9
@ -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,
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user