mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-04 06:53:12 +00:00
* bump_dependencies.md: add nim-results dependency * change imports stew/results to results * switching to Nim 2.0.8 * waku.nimble: reflect the requirement nim 1.6.0 to 2.0.8 Adding --mm:refc as nim 2.0 enables a new garbage collector that we're not yet ready to support * adapt waku code to Nim 2.0 * gcsafe adaptations because Nim 2.0 is more strict
65 lines
1.7 KiB
Nim
65 lines
1.7 KiB
Nim
when (NimMajor, NimMinor) < (1, 4):
|
|
{.push raises: [Defect].}
|
|
else:
|
|
{.push raises: [].}
|
|
|
|
import chronicles, sequtils, results
|
|
|
|
import
|
|
waku/[waku_rln_relay/rln, waku_rln_relay/conversion_utils, factory/external_config]
|
|
|
|
logScope:
|
|
topics = "rln_db_inspector"
|
|
|
|
proc doInspectRlnDb*(conf: WakuNodeConf) =
|
|
# 1. load configuration
|
|
trace "configuration", conf = $conf
|
|
|
|
# 2. initialize rlnInstance
|
|
let rlnInstance = createRLNInstance(d = 20, tree_path = conf.treePath).valueOr:
|
|
error "failure while creating RLN instance", error
|
|
quit(1)
|
|
|
|
# 3. get metadata
|
|
let metadataOpt = rlnInstance.getMetadata().valueOr:
|
|
error "failure while getting RLN metadata", error
|
|
quit(1)
|
|
|
|
if metadataOpt.isNone():
|
|
error "RLN metadata does not exist"
|
|
quit(1)
|
|
let metadata = metadataOpt.get()
|
|
|
|
info "RLN metadata",
|
|
lastProcessedBlock = metadata.lastProcessedBlock,
|
|
chainId = metadata.chainId,
|
|
contractAddress = metadata.contractAddress,
|
|
validRoots = metadata.validRoots.mapIt(it.inHex())
|
|
|
|
var index: uint = 0
|
|
var hits: uint = 0
|
|
var zeroLeafIndices: seq[uint] = @[]
|
|
var assumeEmptyAfter: uint = 10
|
|
while true:
|
|
let leaf = rlnInstance.getMember(index).valueOr:
|
|
error "failure while getting RLN leaf", error
|
|
quit(1)
|
|
|
|
if leaf.inHex() == "0000000000000000000000000000000000000000000000000000000000000000":
|
|
zeroLeafIndices.add(index)
|
|
hits = hits + 1
|
|
else:
|
|
hits = 0
|
|
|
|
if hits > assumeEmptyAfter:
|
|
info "reached end of RLN tree", index = index - assumeEmptyAfter
|
|
# remove zeroLeafIndices that are not at the end of the tree
|
|
zeroLeafIndices = zeroLeafIndices.filterIt(it < index - assumeEmptyAfter)
|
|
break
|
|
|
|
index = index + 1
|
|
|
|
info "zero leaf indices", zeroLeafIndices
|
|
|
|
quit(0)
|