add contract root cache size as constant and function use fix

This commit is contained in:
stubbsta 2026-06-04 09:22:16 +02:00
parent 343f9cb325
commit 324d69c928
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View File

@ -7,6 +7,9 @@ import ../waku_keystore
# Acceptable roots for merkle root validation of incoming messages
const AcceptableRootWindowSize* = 50
#Size if RLN contract root cache
const RlnContractRootCacheSize* = 5
# RLN membership key and index files path
const RlnCredentialsFilename* = "rlnCredentials.txt"

View File

@ -167,7 +167,9 @@ proc updateRoots*(g: OnchainGroupManager): Future[bool] {.async.} =
return false
proc updateRecentRoots*(g: OnchainGroupManager): Future[bool] {.async.} =
let bytes = (await g.fetchMerkleRoot()).valueOr:
## Fetch recent roots from the contract roots cache and update the validRoots deque, ensuring we maintain a window of acceptable roots.
## Contract returns array if uint256 roots, newest first, zero-padded to the cache size (e.g. 5).
let bytes = (await g.fetchMerkleRootsCache()).valueOr:
error "Failed to fetch current Merkle root", error = error
return false
@ -176,7 +178,7 @@ proc updateRecentRoots*(g: OnchainGroupManager): Future[bool] {.async.} =
return false
let chunkCount = bytes.len div 32
if chunkCount != 5:
if chunkCount != RlnContractRootCacheSize:
warn "Unexpected number of recent roots returned; proceeding anyway",
count = chunkCount