Skip to content

Commit

Permalink
fix(rln-relay): tree race condition upon initialization (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc authored Jun 19, 2023
1 parent 045f07c commit f8e270f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
4 changes: 2 additions & 2 deletions tests/v2/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ else:
{.push raises: [].}

import
std/[options, osproc, streams, strutils],
std/[options, osproc, streams, strutils, tempfiles],
stew/[results, byteutils],
stew/shims/net as stewNet,
testutils/unittests,
Expand Down Expand Up @@ -157,7 +157,7 @@ proc stopGanache(runGanache: Process) {.used.} =
error "Ganache daemon termination failed: ", err = getCurrentExceptionMsg()

proc setup(signer = true): Future[OnchainGroupManager] {.async.} =
let rlnInstanceRes = createRlnInstance()
let rlnInstanceRes = createRlnInstance(tree_path = genTempPath("rln_tree", "group_manager_onchain"))
require:
rlnInstanceRes.isOk()

Expand Down
2 changes: 1 addition & 1 deletion tests/v2/waku_rln_relay/test_rln_group_manager_static.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ proc generateCredentials(rlnInstance: ptr RLN, n: int): seq[IdentityCredential]

suite "Static group manager":
setup:
let rlnInstanceRes = createRlnInstance(tree_path = genTempPath("rln_tree", "static"))
let rlnInstanceRes = createRlnInstance(tree_path = genTempPath("rln_tree", "group_manager_static"))
require:
rlnInstanceRes.isOk()

Expand Down
47 changes: 25 additions & 22 deletions tests/v2/waku_rln_relay/test_waku_rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{.used.}

import
std/[options, os, sequtils, times],
std/[options, os, sequtils, times, tempfiles],
stew/byteutils,
stew/shims/net as stewNet,
testutils/unittests,
Expand All @@ -21,13 +21,16 @@ import
const RlnRelayPubsubTopic = "waku/2/rlnrelay/proto"
const RlnRelayContentTopic = "waku/2/rlnrelay/proto"

proc createRLNInstanceWrapper(): RLNResult =
return createRlnInstance(tree_path = genTempPath("rln_tree", "waku_rln_relay"))

suite "Waku rln relay":

test "key_gen Nim Wrappers":
let
merkleDepth: csize_t = 20

let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand All @@ -49,7 +52,7 @@ suite "Waku rln relay":

test "membership Key Generation":
# create an RLN instance
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand All @@ -73,7 +76,7 @@ suite "Waku rln relay":

test "getRoot Nim binding":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand Down Expand Up @@ -106,7 +109,7 @@ suite "Waku rln relay":
rootHex1 == rootHex2
test "getMerkleRoot utils":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -129,7 +132,7 @@ suite "Waku rln relay":

test "update_next_member Nim Wrapper":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -149,7 +152,7 @@ suite "Waku rln relay":

test "getMember Nim wrapper":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand Down Expand Up @@ -182,7 +185,7 @@ suite "Waku rln relay":

test "delete_member Nim wrapper":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
# generate an identity credential
Expand All @@ -200,7 +203,7 @@ suite "Waku rln relay":

test "insertMembers rln utils":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -213,7 +216,7 @@ suite "Waku rln relay":

test "insertMember rln utils":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -226,7 +229,7 @@ suite "Waku rln relay":

test "removeMember rln utils":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -240,7 +243,7 @@ suite "Waku rln relay":

test "setMetadata rln utils":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -249,7 +252,7 @@ suite "Waku rln relay":

test "getMetadata rln utils":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -270,7 +273,7 @@ suite "Waku rln relay":

test "Merkle tree consistency check between deletion and insertion":
# create an RLN instance
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand Down Expand Up @@ -346,7 +349,7 @@ suite "Waku rln relay":

test "Merkle tree consistency check between deletion and insertion using rln utils":
# create an RLN instance
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand Down Expand Up @@ -401,7 +404,7 @@ suite "Waku rln relay":

test "hash Nim Wrappers":
# create an RLN instance
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand Down Expand Up @@ -432,7 +435,7 @@ suite "Waku rln relay":

test "sha256 hash utils":
# create an RLN instance
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -449,7 +452,7 @@ suite "Waku rln relay":

test "poseidon hash utils":
# create an RLN instance
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand All @@ -467,7 +470,7 @@ suite "Waku rln relay":
hashRes.get().inHex()

test "create a list of membership keys and construct a Merkle tree based on the list":
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand Down Expand Up @@ -500,7 +503,7 @@ suite "Waku rln relay":
# extract the id commitments
let groupIDCommitments = groupIdCredentials.mapIt(it.idCommitment)
# calculate the Merkle tree root out of the extracted id commitments
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
Expand Down Expand Up @@ -708,7 +711,7 @@ suite "Waku rln relay":

test "toIDCommitment and toUInt256":
# create an instance of rln
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand All @@ -732,7 +735,7 @@ suite "Waku rln relay":

test "Read/Write RLN credentials":
# create an RLN instance
let rlnInstance = createRLNInstance()
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()

Expand Down
11 changes: 10 additions & 1 deletion tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{.used.}

import
std/sequtils,
std/[sequtils, tempfiles],
stew/byteutils,
stew/shims/net as stewNet,
testutils/unittests,
Expand Down Expand Up @@ -52,6 +52,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 1.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
))

await node1.start()
Expand All @@ -63,6 +64,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 2.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_2"),
))

await node2.start()
Expand All @@ -74,6 +76,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 3.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_3"),
))

await node3.start()
Expand Down Expand Up @@ -138,6 +141,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 1.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_4"),
))

await node1.start()
Expand All @@ -149,6 +153,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 2.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_5"),
))

await node2.start()
Expand All @@ -160,6 +165,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 3.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_6"),
))

await node3.start()
Expand Down Expand Up @@ -241,6 +247,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 1.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_7"),
))

await node1.start()
Expand All @@ -253,6 +260,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 2.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_8"),
))

await node2.start()
Expand All @@ -265,6 +273,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 3.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_9"),
))

await node3.start()
Expand Down

0 comments on commit f8e270f

Please sign in to comment.