mirror of https://github.com/waku-org/nwaku.git
feat(rln_db_inspector): create rln_db_inspector tool (#1999)
* 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>
This commit is contained in:
parent
b991682b28
commit
ec42e2c758
4
Makefile
4
Makefile
|
@ -191,6 +191,10 @@ rln-keystore-generator: | build deps librln-experimental
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
$(ENV_SCRIPT) nim rln_keystore_generator $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims
|
$(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
|
chat2bridge: | build deps
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
$(ENV_SCRIPT) nim chat2bridge $(NIM_PARAMS) waku.nims
|
$(ENV_SCRIPT) nim chat2bridge $(NIM_PARAMS) waku.nims
|
||||||
|
|
|
@ -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())
|
|
@ -0,0 +1,3 @@
|
||||||
|
-d:chronicles_line_numbers
|
||||||
|
-d:chronicles_runtime_filtering=on
|
||||||
|
#-d:"chronicles_enabled_topics=GossipSub:TRACE,WakuRelay:TRACE"
|
|
@ -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)
|
|
@ -74,6 +74,10 @@ task rln_keystore_generator, "Build the rln keystore generator":
|
||||||
let name = "rln_keystore_generator"
|
let name = "rln_keystore_generator"
|
||||||
buildBinary name, "tools/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":
|
task test, "Build & run Waku tests":
|
||||||
test "all_tests_waku"
|
test "all_tests_waku"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue