Skip to content

Commit

Permalink
feat(rln_db_inspector): create rln_db_inspector tool (#1999)
Browse files Browse the repository at this point in the history
* feat(rln_db_inspector): create rln_db_inspector tool

* Apply suggestions from code review

Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com>

---------

Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com>
  • Loading branch information
rymnc and Ivansete-status authored Sep 7, 2023
1 parent b991682 commit ec42e2c
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ rln-keystore-generator: | build deps librln-experimental
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim rln_keystore_generator $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims

rln-db-inspector: | build deps librln-experimental
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim rln_db_inspector $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims

chat2bridge: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim chat2bridge $(NIM_PARAMS) waku.nims
Expand Down
47 changes: 47 additions & 0 deletions tools/rln_db_inspector/external_config.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}

import
stew/results,
chronos,
confutils,
confutils/defs,
confutils/toml/defs as confTomlDefs,
confutils/toml/std/net as confTomlNet,
libp2p/crypto/crypto,
libp2p/crypto/secp,
libp2p/multiaddress,
secp256k1
import
../../waku/common/confutils/envvar/defs as confEnvvarDefs,
../../waku/common/confutils/envvar/std/net as confEnvvarNet

export
confTomlDefs,
confTomlNet,
confEnvvarDefs,
confEnvvarNet

type
RlnDbInspectorConf* = object
configFile* {.
desc: "Loads configuration from a TOML file (cmd-line parameters take precedence)",
name: "config-file" }: Option[InputFile]

## General node config
rlnRelayTreePath* {.
desc: "The path to the rln-relay tree",
defaultValue: "",
name: "rln-relay-tree-path" }: string


proc loadConfig*(T: type RlnDbInspectorConf): Result[T, string] =
try:
let conf = RlnDbInspectorConf.load()
if conf.rlnRelayTreePath == "":
return err("--rln-relay-tree-path must be set")
ok(conf)
except CatchableError, Exception:
err(getCurrentExceptionMsg())
3 changes: 3 additions & 0 deletions tools/rln_db_inspector/nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-d:chronicles_line_numbers
-d:chronicles_runtime_filtering=on
#-d:"chronicles_enabled_topics=GossipSub:TRACE,WakuRelay:TRACE"
50 changes: 50 additions & 0 deletions tools/rln_db_inspector/rln_db_inspector.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}

import
chronicles,
sequtils,
stew/[results]

import
../../waku/waku_rln_relay/rln,
../../waku/waku_rln_relay/conversion_utils,
./external_config

logScope:
topics = "rln_db_inspector"

when isMainModule:
{.pop.}
# 1. load configuration
let conf = RlnDbInspectorConf.loadConfig().isOkOr:
error "failure while loading the configuration", error=confRes.error
quit(1)

trace "configuration", conf = $conf

# 2. initialize rlnInstance
let rlnInstanceRes = createRLNInstance(d=20,
tree_path = conf.rlnRelayTreePath)
if rlnInstanceRes.isErr():
error "failure while creating RLN instance", error=rlnInstanceRes.error
quit(1)

let rlnInstance = rlnInstanceRes.get()

# 3. get metadata
let metadataGetRes = rlnInstance.getMetadata()
if metadataGetRes.isErr():
error "failure while getting RLN metadata", error=metadataGetRes.error
quit(1)

let metadata = metadataGetRes.get()

info "RLN metadata", lastProcessedBlock = metadata.lastProcessedBlock,
chainId = metadata.chainId,
contractAddress = metadata.contractAddress,
validRoots = metadata.validRoots.mapIt(it.inHex())

quit(0)
4 changes: 4 additions & 0 deletions waku.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ task rln_keystore_generator, "Build the rln keystore generator":
let name = "rln_keystore_generator"
buildBinary name, "tools/rln_keystore_generator/"

task rln_db_inspector, "Build the rln db inspector":
let name = "rln_db_inspector"
buildBinary name, "tools/rln_db_inspector/"

task test, "Build & run Waku tests":
test "all_tests_waku"

Expand Down

0 comments on commit ec42e2c

Please sign in to comment.