feat: rln-keystore-generator is now a subcommand (#2189)

This commit is contained in:
Aaryamann Challani 2023-11-09 15:18:39 +05:30 committed by GitHub
parent 6dd2806359
commit 3498a84600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 463 additions and 523 deletions

View File

@ -30,18 +30,16 @@ type ProtectedTopic* = object
topic*: string
key*: secp256k1.SkPublicKey
type StartUpCommand* = enum
noCommand # default, runs waku
generateRlnKeystore # generates a new RLN keystore
type
WakuNodeConf* = object
configFile* {.
desc: "Loads configuration from a TOML file (cmd-line parameters take precedence)"
name: "config-file" }: Option[InputFile]
## Application-level configuration
protectedTopics* {.
desc: "Topics and its public key to be used for message validation, topic:pubkey. Argument may be repeated."
defaultValue: newSeq[ProtectedTopic](0)
name: "protected-topic" .}: seq[ProtectedTopic]
## Log configuration
logLevel* {.
desc: "Sets the log level for process. Supported levels: TRACE, DEBUG, INFO, NOTICE, WARN, ERROR or FATAL",
@ -53,6 +51,49 @@ type
defaultValue: logging.LogFormat.TEXT,
name: "log-format" .}: logging.LogFormat
rlnRelayCredPath* {.
desc: "The path for peristing rln-relay credential",
defaultValue: "",
name: "rln-relay-cred-path" }: string
rlnRelayEthClientAddress* {.
desc: "WebSocket address of an Ethereum testnet client e.g., ws://localhost:8540/",
defaultValue: "ws://localhost:8540/",
name: "rln-relay-eth-client-address" }: string
rlnRelayEthContractAddress* {.
desc: "Address of membership contract on an Ethereum testnet",
defaultValue: "",
name: "rln-relay-eth-contract-address" }: string
rlnRelayCredPassword* {.
desc: "Password for encrypting RLN credentials",
defaultValue: "",
name: "rln-relay-cred-password" }: string
rlnRelayEthPrivateKey* {.
desc: "Private key for broadcasting transactions",
defaultValue: "",
name: "rln-relay-eth-private-key" }: string
case cmd* {.
command
defaultValue: noCommand }: StartUpCommand
of generateRlnKeystore:
execute* {.
desc: "Runs the registration function on-chain. By default, a dry-run will occur",
defaultValue: false,
name: "execute" .}: bool
of noCommand:
## Application-level configuration
protectedTopics* {.
desc: "Topics and its public key to be used for message validation, topic:pubkey. Argument may be repeated."
defaultValue: newSeq[ProtectedTopic](0)
name: "protected-topic" .}: seq[ProtectedTopic]
## General node config
clusterId* {.
desc: "Cluster id that the node is running in. Node in a different cluster id is disconnected."
@ -149,11 +190,6 @@ type
defaultValue: false
name: "rln-relay" }: bool
rlnRelayCredPath* {.
desc: "The path for peristing rln-relay credential",
defaultValue: ""
name: "rln-relay-cred-path" }: string
rlnRelayCredIndex* {.
desc: "the index of the onchain commitment to use",
name: "rln-relay-membership-index" }: Option[uint]
@ -173,21 +209,6 @@ type
defaultValue: ""
name: "rln-relay-id-commitment-key" }: string
rlnRelayEthClientAddress* {.
desc: "WebSocket address of an Ethereum testnet client e.g., ws://localhost:8540/",
defaultValue: "ws://localhost:8540/"
name: "rln-relay-eth-client-address" }: string
rlnRelayEthContractAddress* {.
desc: "Address of membership contract on an Ethereum testnet",
defaultValue: ""
name: "rln-relay-eth-contract-address" }: string
rlnRelayCredPassword* {.
desc: "Password for encrypting RLN credentials",
defaultValue: ""
name: "rln-relay-cred-password" }: string
rlnRelayTreePath* {.
desc: "Path to the RLN merkle tree sled db (https://github.com/spacejam/sled)",
defaultValue: ""

View File

@ -13,6 +13,7 @@ import
system/ansi_c,
libp2p/crypto/crypto
import
../../tools/rln_keystore_generator/rln_keystore_generator,
../../waku/common/logging,
./external_config,
./app
@ -49,7 +50,10 @@ when isMainModule:
logging.setupLogLevel(conf.logLevel)
logging.setupLogFormat(conf.logFormat, color)
case conf.cmd:
of generateRlnKeystore:
doRlnKeystoreGenerator(conf)
of noCommand:
var wakunode2 = App.init(rng, conf)
##############

View File

@ -22,6 +22,7 @@ import
proc defaultTestWakuNodeConf*(): WakuNodeConf =
WakuNodeConf(
cmd: noCommand,
tcpPort: Port(60000),
websocketPort: Port(8000),
listenAddress: ValidIpAddress.init("0.0.0.0"),

View File

@ -1,79 +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
RlnKeystoreGeneratorConf* = object
configFile* {.
desc: "Loads configuration from a TOML file (cmd-line parameters take precedence)",
name: "config-file" }: Option[InputFile]
execute* {.
desc: "Runs the registration function on-chain. By default, a dry-run will occur",
defaultValue: false,
name: "execute" .}: bool
## General node config
rlnRelayCredPath* {.
desc: "The path for peristing rln-relay credential",
defaultValue: "",
name: "rln-relay-cred-path" }: string
rlnRelayEthClientAddress* {.
desc: "WebSocket address of an Ethereum testnet client e.g., ws://localhost:8540/",
defaultValue: "ws://localhost:8540/",
name: "rln-relay-eth-client-address" }: string
rlnRelayEthContractAddress* {.
desc: "Address of membership contract on an Ethereum testnet",
defaultValue: "",
name: "rln-relay-eth-contract-address" }: string
rlnRelayCredPassword* {.
desc: "Password for encrypting RLN credentials",
defaultValue: "",
name: "rln-relay-cred-password" }: string
rlnRelayEthPrivateKey* {.
desc: "Private key for broadcasting transactions",
defaultValue: "",
name: "rln-relay-eth-private-key" }: string
proc loadConfig*(T: type RlnKeystoreGeneratorConf): Result[T, string] =
try:
let conf = RlnKeystoreGeneratorConf.load()
if conf.rlnRelayCredPath == "":
return err("--rln-relay-cred-path must be set")
if conf.rlnRelayEthContractAddress == "":
return err("--rln-relay-eth-contract-address must be set")
if conf.rlnRelayCredPassword == "":
return err("--rln-relay-cred-password must be set")
if conf.rlnRelayEthPrivateKey == "":
return err("--rln-relay-eth-private-key must be set")
ok(conf)
except CatchableError:
err(getCurrentExceptionMsg())
except Exception:
err(getCurrentExceptionMsg())

View File

@ -1,3 +0,0 @@
-d:chronicles_line_numbers
-d:chronicles_runtime_filtering=on
#-d:"chronicles_enabled_topics=GossipSub:TRACE,WakuRelay:TRACE"

View File

@ -13,21 +13,13 @@ import
../../waku/waku_rln_relay/rln,
../../waku/waku_rln_relay/conversion_utils,
../../waku/waku_rln_relay/group_manager/on_chain,
./external_config
../../apps/wakunode2/external_config
logScope:
topics = "rln_keystore_generator"
when isMainModule:
{.pop.}
proc doRlnKeystoreGenerator*(conf: WakuNodeConf) =
# 1. load configuration
let confRes = RlnKeystoreGeneratorConf.loadConfig()
if confRes.isErr():
error "failure while loading the configuration", error=confRes.error
quit(1)
let conf = confRes.get()
trace "configuration", conf = $conf
# 2. initialize rlnInstance
@ -102,5 +94,9 @@ when isMainModule:
info "credentials persisted", path = conf.rlnRelayCredPath
try:
waitFor groupManager.stop()
except CatchableError:
error "failure while stopping OnchainGroupManager", error=getCurrentExceptionMsg()
quit(0) # 0 because we already registered on-chain
quit(0)