mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-06 01:29:26 +00:00
chore: update bug updateRoots function
This commit is contained in:
parent
50a0e01ebb
commit
2e4b7210b8
@ -181,24 +181,21 @@ proc updateRoots*(g: OnchainGroupManager): Future[bool] {.async.} =
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
let merkleRoot = toMerkleNode(rootRes.get())
|
let merkleRoot = toMerkleNode(rootRes.get())
|
||||||
if g.validRoots.len > 0 and g.validRoots[g.validRoots.len - 1] != merkleRoot:
|
if g.validRoots.len == 0:
|
||||||
let overflowCount = g.validRoots.len - AcceptableRootWindowSize + 1
|
g.validRoots.addLast(merkleRoot)
|
||||||
if overflowCount > 0:
|
return true
|
||||||
for i in 0 ..< overflowCount:
|
|
||||||
discard g.validRoots.popFirst()
|
if g.validRoots[g.validRoots.len - 1] != merkleRoot:
|
||||||
|
var overflow = g.validRoots.len - AcceptableRootWindowSize + 1
|
||||||
|
while overflow > 0:
|
||||||
|
discard g.validRoots.popFirst()
|
||||||
|
overflow = overflow - 1
|
||||||
g.validRoots.addLast(merkleRoot)
|
g.validRoots.addLast(merkleRoot)
|
||||||
debug "------ Detected new Merkle root -------",
|
|
||||||
root = merkleRoot.toHex, totalRoots = g.validRoots.len
|
|
||||||
return true
|
return true
|
||||||
else:
|
|
||||||
debug "------ No new Merkle root ------",
|
|
||||||
root = merkleRoot.toHex, totalRoots = g.validRoots.len
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc trackRootChanges*(g: OnchainGroupManager) {.async.} =
|
proc trackRootChanges*(g: OnchainGroupManager) {.async.} =
|
||||||
|
|
||||||
let ethRpc = g.ethRpc.get()
|
let ethRpc = g.ethRpc.get()
|
||||||
let wakuRlnContract = g.wakuRlnContract.get()
|
let wakuRlnContract = g.wakuRlnContract.get()
|
||||||
|
|
||||||
@ -208,7 +205,7 @@ proc trackRootChanges*(g: OnchainGroupManager) {.async.} =
|
|||||||
info "------ Starting to track Merkle root changes ------"
|
info "------ Starting to track Merkle root changes ------"
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
debug "------ starting to update roots ------"
|
debug "------ updating roots ------"
|
||||||
let rootUpdated = await g.updateRoots()
|
let rootUpdated = await g.updateRoots()
|
||||||
|
|
||||||
if rootUpdated:
|
if rootUpdated:
|
||||||
@ -217,7 +214,9 @@ proc trackRootChanges*(g: OnchainGroupManager) {.async.} =
|
|||||||
error "Failed to fetch Merkle proof", error = proofResult.error
|
error "Failed to fetch Merkle proof", error = proofResult.error
|
||||||
g.merkleProofCache = proofResult.get()
|
g.merkleProofCache = proofResult.get()
|
||||||
|
|
||||||
debug "sleeping for 5 seconds"
|
debug "------ current roots ------",
|
||||||
|
roots = g.validRoots.mapIt(it.toHex).join(", "), totalRoots = g.validRoots.len
|
||||||
|
|
||||||
await sleepAsync(rpcDelay)
|
await sleepAsync(rpcDelay)
|
||||||
|
|
||||||
method atomicBatch*(
|
method atomicBatch*(
|
||||||
|
|||||||
@ -193,7 +193,7 @@ proc validateMessage*(
|
|||||||
## `timeOption` indicates Unix epoch time (fractional part holds sub-seconds)
|
## `timeOption` indicates Unix epoch time (fractional part holds sub-seconds)
|
||||||
## if `timeOption` is supplied, then the current epoch is calculated based on that
|
## if `timeOption` is supplied, then the current epoch is calculated based on that
|
||||||
|
|
||||||
debug "calling validateMessage from rln_relay", msg = msg
|
debug "calling validateMessage from rln_relay", msg_len = msg.payload.len
|
||||||
|
|
||||||
let decodeRes = RateLimitProof.init(msg.proof)
|
let decodeRes = RateLimitProof.init(msg.proof)
|
||||||
if decodeRes.isErr():
|
if decodeRes.isErr():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user