chore(rln-relay): pass in the path to the tree db (#1782)

* chore(rln-relay): pass in the path to the tree db

* fix(rln-relay): address visibility

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

* fix(rln-relay): make db used more explicit

* fix(rln-relay): reduce visibility

---------

Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com>
This commit is contained in:
Aaryamann Challani 2023-06-08 17:22:21 +05:30 committed by GitHub
parent 93e09b8b77
commit dba84248f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 18 deletions

View File

@ -201,6 +201,11 @@ type
defaultValue: ""
name: "rln-relay-cred-password" }: string
rlnRelayTreePath* {.
desc: "Path to the RLN merkle tree sled db (https://github.com/spacejam/sled)",
defaultValue: ""
name: "rln-relay-tree-path" }: string
staticnodes* {.
desc: "Peer multiaddr to directly connect with. Argument may be repeated."
name: "staticnode" }: seq[string]

2
vendor/zerokit vendored

@ -1 +1 @@
Subproject commit c2d386cb749f551541bb34c4386a3849485356f9
Subproject commit 9cc86e526ee0b34b20e4110dc3e4fded03a046d2

View File

@ -28,17 +28,7 @@ const
HashHexSize* = int(HashBitSize/4)
const
# The relative folder where the circuit, proving and verification key for RLN can be found
# Note that resources has to be compiled with respect to the above MerkleTreeDepth
RlnConfig* = $(%* {
"resources_folder": "tree_height_" & $MerkleTreeDepth & "/",
"tree_config": {
"cache_capacity": 15_000,
"mode": "high_throughput",
"compression": false,
"flush_interval": 12_000
}
})
DefaultRlnTreePath* = "rln_tree.db"
# temporary variables to test waku-rln-relay performance in the static group mode
const

View File

@ -1,3 +1,5 @@
import
std/json
import
chronicles,
options,
@ -51,30 +53,69 @@ proc membershipKeyGen*(ctxPtr: ptr RLN): RlnRelayResult[IdentityCredential] =
return ok(identityCredential)
proc createRLNInstanceLocal*(d: int = MerkleTreeDepth): RLNResult =
type RlnTreeConfig = ref object of RootObj
cache_capacity: int
mode: string
compression: bool
flush_interval: int
path: string
type RlnConfig = ref object of RootObj
resources_folder: string
tree_config: RlnTreeConfig
proc `%`(c: RlnConfig): JsonNode =
## wrapper around the generic JObject constructor.
## We don't need to have a separate proc for the tree_config field
let tree_config = %{ "cache_capacity": %c.tree_config.cache_capacity,
"mode": %c.tree_config.mode,
"compression": %c.tree_config.compression,
"flush_interval": %c.tree_config.flush_interval,
"path": %c.tree_config.path }
return %[("resources_folder", %c.resources_folder),
("tree_config", %tree_config)]
proc createRLNInstanceLocal(d = MerkleTreeDepth,
tree_path = DefaultRlnTreePath): RLNResult =
## generates an instance of RLN
## An RLN instance supports both zkSNARKs logics and Merkle tree data structure and operations
## d indicates the depth of Merkle tree
## tree_path indicates the path of the Merkle tree
## Returns an error if the instance creation fails
let rln_config = RlnConfig(
resources_folder: "tree_height_" & $d & "/",
tree_config: RlnTreeConfig(
cache_capacity: 15_000,
mode: "high_throughput",
compression: false,
flush_interval: 12_000,
path: if tree_path != "": tree_path else: DefaultRlnTreePath
)
)
var serialized_rln_config = $(%rln_config)
var
rlnInstance: ptr RLN
merkleDepth: csize_t = uint(d)
resourcesPathBuffer = RlnConfig.toOpenArrayByte(0, RlnConfig.high).toBuffer()
configBuffer = serialized_rln_config.toOpenArrayByte(0, serialized_rln_config.high).toBuffer()
# create an instance of RLN
let res = new_circuit(merkleDepth, addr resourcesPathBuffer, addr rlnInstance)
let res = new_circuit(merkleDepth, addr configBuffer, addr rlnInstance)
# check whether the circuit parameters are generated successfully
if (res == false):
debug "error in parameters generation"
return err("error in parameters generation")
return ok(rlnInstance)
proc createRLNInstance*(d: int = MerkleTreeDepth): RLNResult =
proc createRLNInstance*(d = MerkleTreeDepth,
tree_path = DefaultRlnTreePath): RLNResult =
## Wraps the rln instance creation for metrics
## Returns an error if the instance creation fails
var res: RLNResult
waku_rln_instance_creation_duration_seconds.nanosecondTime:
res = createRLNInstanceLocal(d)
res = createRLNInstanceLocal(d, tree_path)
return res
proc sha256*(data: openArray[byte]): RlnRelayResult[MerkleNode] =

View File

@ -40,6 +40,7 @@ type WakuRlnConfig* = object
rlnRelayEthAccountAddress*: string
rlnRelayCredPath*: string
rlnRelayCredentialsPassword*: string
rlnRelayTreePath*: string
proc createMembershipList*(rln: ptr RLN, n: int): RlnRelayResult[(
seq[RawMembershipCredentials], string
@ -338,7 +339,7 @@ proc mount(conf: WakuRlnConfig,
credentials: MembershipCredentials
persistCredentials = false
# create an RLN instance
let rlnInstanceRes = createRLNInstance()
let rlnInstanceRes = createRLNInstance(tree_path = conf.rlnRelayTreePath)
if rlnInstanceRes.isErr():
raise newException(CatchableError, "RLN instance creation failed")
let rlnInstance = rlnInstanceRes.get()