mirror of https://github.com/waku-org/nwaku.git
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:
parent
93e09b8b77
commit
dba84248f1
|
@ -201,6 +201,11 @@ type
|
||||||
defaultValue: ""
|
defaultValue: ""
|
||||||
name: "rln-relay-cred-password" }: string
|
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* {.
|
staticnodes* {.
|
||||||
desc: "Peer multiaddr to directly connect with. Argument may be repeated."
|
desc: "Peer multiaddr to directly connect with. Argument may be repeated."
|
||||||
name: "staticnode" }: seq[string]
|
name: "staticnode" }: seq[string]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit c2d386cb749f551541bb34c4386a3849485356f9
|
Subproject commit 9cc86e526ee0b34b20e4110dc3e4fded03a046d2
|
|
@ -28,17 +28,7 @@ const
|
||||||
HashHexSize* = int(HashBitSize/4)
|
HashHexSize* = int(HashBitSize/4)
|
||||||
|
|
||||||
const
|
const
|
||||||
# The relative folder where the circuit, proving and verification key for RLN can be found
|
DefaultRlnTreePath* = "rln_tree.db"
|
||||||
# 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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
# temporary variables to test waku-rln-relay performance in the static group mode
|
# temporary variables to test waku-rln-relay performance in the static group mode
|
||||||
const
|
const
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import
|
||||||
|
std/json
|
||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
options,
|
options,
|
||||||
|
@ -51,30 +53,69 @@ proc membershipKeyGen*(ctxPtr: ptr RLN): RlnRelayResult[IdentityCredential] =
|
||||||
|
|
||||||
return ok(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
|
## generates an instance of RLN
|
||||||
## An RLN instance supports both zkSNARKs logics and Merkle tree data structure and operations
|
## An RLN instance supports both zkSNARKs logics and Merkle tree data structure and operations
|
||||||
## d indicates the depth of Merkle tree
|
## d indicates the depth of Merkle tree
|
||||||
|
## tree_path indicates the path of the Merkle tree
|
||||||
## Returns an error if the instance creation fails
|
## 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
|
var
|
||||||
rlnInstance: ptr RLN
|
rlnInstance: ptr RLN
|
||||||
merkleDepth: csize_t = uint(d)
|
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
|
# 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
|
# check whether the circuit parameters are generated successfully
|
||||||
if (res == false):
|
if (res == false):
|
||||||
debug "error in parameters generation"
|
debug "error in parameters generation"
|
||||||
return err("error in parameters generation")
|
return err("error in parameters generation")
|
||||||
return ok(rlnInstance)
|
return ok(rlnInstance)
|
||||||
|
|
||||||
proc createRLNInstance*(d: int = MerkleTreeDepth): RLNResult =
|
proc createRLNInstance*(d = MerkleTreeDepth,
|
||||||
|
tree_path = DefaultRlnTreePath): RLNResult =
|
||||||
## Wraps the rln instance creation for metrics
|
## Wraps the rln instance creation for metrics
|
||||||
## Returns an error if the instance creation fails
|
## Returns an error if the instance creation fails
|
||||||
var res: RLNResult
|
var res: RLNResult
|
||||||
waku_rln_instance_creation_duration_seconds.nanosecondTime:
|
waku_rln_instance_creation_duration_seconds.nanosecondTime:
|
||||||
res = createRLNInstanceLocal(d)
|
res = createRLNInstanceLocal(d, tree_path)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
proc sha256*(data: openArray[byte]): RlnRelayResult[MerkleNode] =
|
proc sha256*(data: openArray[byte]): RlnRelayResult[MerkleNode] =
|
||||||
|
|
|
@ -40,6 +40,7 @@ type WakuRlnConfig* = object
|
||||||
rlnRelayEthAccountAddress*: string
|
rlnRelayEthAccountAddress*: string
|
||||||
rlnRelayCredPath*: string
|
rlnRelayCredPath*: string
|
||||||
rlnRelayCredentialsPassword*: string
|
rlnRelayCredentialsPassword*: string
|
||||||
|
rlnRelayTreePath*: string
|
||||||
|
|
||||||
proc createMembershipList*(rln: ptr RLN, n: int): RlnRelayResult[(
|
proc createMembershipList*(rln: ptr RLN, n: int): RlnRelayResult[(
|
||||||
seq[RawMembershipCredentials], string
|
seq[RawMembershipCredentials], string
|
||||||
|
@ -338,7 +339,7 @@ proc mount(conf: WakuRlnConfig,
|
||||||
credentials: MembershipCredentials
|
credentials: MembershipCredentials
|
||||||
persistCredentials = false
|
persistCredentials = false
|
||||||
# create an RLN instance
|
# create an RLN instance
|
||||||
let rlnInstanceRes = createRLNInstance()
|
let rlnInstanceRes = createRLNInstance(tree_path = conf.rlnRelayTreePath)
|
||||||
if rlnInstanceRes.isErr():
|
if rlnInstanceRes.isErr():
|
||||||
raise newException(CatchableError, "RLN instance creation failed")
|
raise newException(CatchableError, "RLN instance creation failed")
|
||||||
let rlnInstance = rlnInstanceRes.get()
|
let rlnInstance = rlnInstanceRes.get()
|
||||||
|
|
Loading…
Reference in New Issue