fix(rln-relay): tree race condition upon initialization (#1807)

This commit is contained in:
Aaryamann Challani 2023-06-19 13:46:05 +05:30 committed by GitHub
parent 045f07c616
commit f8e270fbe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 26 deletions

View File

@ -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,
@ -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()

View File

@ -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()

View File

@ -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,
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()
@ -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()

View File

@ -1,7 +1,7 @@
{.used.}
import
std/sequtils,
std/[sequtils, tempfiles],
stew/byteutils,
stew/shims/net as stewNet,
testutils/unittests,
@ -52,6 +52,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 1.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
))
await node1.start()
@ -63,6 +64,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 2.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_2"),
))
await node2.start()
@ -74,6 +76,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 3.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_3"),
))
await node3.start()
@ -138,6 +141,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 1.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_4"),
))
await node1.start()
@ -149,6 +153,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 2.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_5"),
))
await node2.start()
@ -160,6 +165,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 3.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_6"),
))
await node3.start()
@ -241,6 +247,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 1.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_7"),
))
await node1.start()
@ -253,6 +260,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 2.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_8"),
))
await node2.start()
@ -265,6 +273,7 @@ procSuite "WakuNode - RLN relay":
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
rlnRelayContentTopic: contentTopic,
rlnRelayCredIndex: 3.uint,
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_9"),
))
await node3.start()