-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
b991682
commit ec42e2c
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters