diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index 7f9661873..c646ee3cc 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -14,6 +14,7 @@ import libp2p/crypto/crypto import ../../tools/rln_keystore_generator/rln_keystore_generator, + ../../tools/rln_db_inspector/rln_db_inspector, ../../waku/common/logging, ../../waku/factory/external_config, ./networks_config, @@ -86,6 +87,8 @@ when isMainModule: case conf.cmd of generateRlnKeystore: doRlnKeystoreGenerator(conf) + of inspectRlnDb: + doInspectRlnDb(conf) of noCommand: # The Waku Network config (cluster-id=1) if conf.clusterId == 1: diff --git a/docs/tutorial/rln-db-inspector.md b/docs/tutorial/rln-db-inspector.md new file mode 100644 index 000000000..397d8a378 --- /dev/null +++ b/docs/tutorial/rln-db-inspector.md @@ -0,0 +1,36 @@ +# rln-db-inspector + +This document describes how to run and use the `rln-db-inspector` tool. +It is meant to be used to debug and fetch the metadata stored in the RLN tree db. + +## Pre-requisites + +1. An existing RLN tree db + +## Usage + +1. First, we compile the binary + + ```bash + make -j16 wakunode2 + ``` + This command will fetch the rln static library and link it automatically. + + +2. Define the arguments you wish to use + + ```bash + export RLN_TREE_DB_PATH="xxx" + ``` + +3. Run the db inspector + + ```bash + ./build/wakunode2 inspectRlnDb \ + --rln-relay-tree-path:$RLN_TREE_DB_PATH + ``` + + What this does is - + a. loads the tree db from the path provided + b. Logs out the metadata, including, number of leaves set, past 5 merkle roots, last synced block number + diff --git a/tools/rln_db_inspector/README.md b/tools/rln_db_inspector/README.md new file mode 100644 index 000000000..11f5352ca --- /dev/null +++ b/tools/rln_db_inspector/README.md @@ -0,0 +1,3 @@ +# rln_db_inspector + +Documentation on running the `rln-db-inspector` can be found [here](../../docs/tutorial/rln-db-inspector.md) \ No newline at end of file diff --git a/tools/rln_db_inspector/external_config.nim b/tools/rln_db_inspector/external_config.nim deleted file mode 100644 index e6d37484e..000000000 --- a/tools/rln_db_inspector/external_config.nim +++ /dev/null @@ -1,47 +0,0 @@ -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()) diff --git a/tools/rln_db_inspector/nim.cfg b/tools/rln_db_inspector/nim.cfg deleted file mode 100644 index f3bae1590..000000000 --- a/tools/rln_db_inspector/nim.cfg +++ /dev/null @@ -1,3 +0,0 @@ --d:chronicles_line_numbers --d:chronicles_runtime_filtering=on -#-d:"chronicles_enabled_topics=GossipSub:TRACE,WakuRelay:TRACE" diff --git a/tools/rln_db_inspector/rln_db_inspector.nim b/tools/rln_db_inspector/rln_db_inspector.nim index d7e076d14..de17fd12b 100644 --- a/tools/rln_db_inspector/rln_db_inspector.nim +++ b/tools/rln_db_inspector/rln_db_inspector.nim @@ -16,18 +16,13 @@ import logScope: topics = "rln_db_inspector" -when isMainModule: - {.pop.} +proc doInspectRlnDb*(conf: WakuNodeConf) = # 1. load configuration - let conf = RlnDbInspectorConf.loadConfig().valueOr: - error "failure while loading the configuration", error - quit(1) - trace "configuration", conf = $conf # 2. initialize rlnInstance let rlnInstance = createRLNInstance(d=20, - tree_path = conf.rlnRelayTreePath).valueOr: + tree_path = conf.treePath).valueOr: error "failure while creating RLN instance", error quit(1) diff --git a/waku/factory/external_config.nim b/waku/factory/external_config.nim index 514bb09c2..d4040c4f1 100644 --- a/waku/factory/external_config.nim +++ b/waku/factory/external_config.nim @@ -41,6 +41,7 @@ type EthRpcUrl = distinct string type StartUpCommand* = enum noCommand # default, runs waku generateRlnKeystore # generates a new RLN keystore + inspectRlnDb # Inspects a given RLN tree db, providing essential db stats type WakuNodeConf* = object @@ -103,6 +104,13 @@ type command defaultValue: noCommand }: StartUpCommand + of inspectRlnDb: + # have to change the name here since it counts as a duplicate, within noCommand + treePath* {. + desc: "Path to the RLN merkle tree sled db (https://github.com/spacejam/sled)", + defaultValue: "" + name: "rln-relay-tree-path" .}: string + of generateRlnKeystore: execute* {. desc: "Runs the registration function on-chain. By default, a dry-run will occur",