mirror of https://github.com/waku-org/nwaku.git
chore(rln-relay): refactor mounting procedure (#1457)
* chore(rln-relay): refactor mounting procedure * fix(rln-relay): tests * fix(rln-relay|chat2): update mounting proc in chat2, fix args to mountRlnRelay * fix(rln-relay): remove stale todo
This commit is contained in:
parent
2915b19dbd
commit
33e9d8b9b2
|
@ -565,13 +565,13 @@ proc processInput(rfd: AsyncFD) {.async.} =
|
||||||
rlnRelayCredentialsPassword: conf.rlnRelayCredentialsPassword
|
rlnRelayCredentialsPassword: conf.rlnRelayCredentialsPassword
|
||||||
)
|
)
|
||||||
|
|
||||||
let res = await node.mountRlnRelay(conf=rlnConf, spamHandler = some(spamHandler), registrationHandler = some(registrationHandler))
|
await node.mountRlnRelay(rlnConf,
|
||||||
if res.isErr():
|
spamHandler=some(spamHandler),
|
||||||
echo "failed to mount rln-relay: " & res.error()
|
registrationHandler=some(registrationHandler))
|
||||||
else:
|
|
||||||
echo "your membership index is: ", node.wakuRlnRelay.membershipIndex
|
echo "your membership index is: ", node.wakuRlnRelay.membershipIndex
|
||||||
echo "your rln identity key is: ", node.wakuRlnRelay.membershipKeyPair.idKey.inHex()
|
echo "your rln identity key is: ", node.wakuRlnRelay.membershipKeyPair.idKey.inHex()
|
||||||
echo "your rln identity commitment key is: ", node.wakuRlnRelay.membershipKeyPair.idCommitment.inHex()
|
echo "your rln identity commitment key is: ", node.wakuRlnRelay.membershipKeyPair.idCommitment.inHex()
|
||||||
|
|
||||||
if conf.metricsLogging:
|
if conf.metricsLogging:
|
||||||
startMetricsLog()
|
startMetricsLog()
|
||||||
|
|
|
@ -371,9 +371,7 @@ proc setupProtocols(node: WakuNode, conf: WakuNodeConf,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let res = await node.mountRlnRelay(rlnConf)
|
await node.mountRlnRelay(rlnConf)
|
||||||
if res.isErr():
|
|
||||||
return err("failed to mount waku RLN relay protocol: " & res.error)
|
|
||||||
except:
|
except:
|
||||||
return err("failed to mount waku RLN relay protocol: " & getCurrentExceptionMsg())
|
return err("failed to mount waku RLN relay protocol: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ procSuite "Waku rln relay":
|
||||||
|
|
||||||
# -------- mount rln-relay in the off-chain mode
|
# -------- mount rln-relay in the off-chain mode
|
||||||
await node.mountRelay(@[RlnRelayPubsubTopic])
|
await node.mountRelay(@[RlnRelayPubsubTopic])
|
||||||
let mountRes = node.mountRlnRelayStatic(group = groupIDCommitments,
|
let mountRes = node.wakuRelay.mountRlnRelayStatic(group = groupIDCommitments,
|
||||||
memKeyPair = groupKeyPairs[index],
|
memKeyPair = groupKeyPairs[index],
|
||||||
memIndex = index,
|
memIndex = index,
|
||||||
pubsubTopic = RlnRelayPubsubTopic,
|
pubsubTopic = RlnRelayPubsubTopic,
|
||||||
|
@ -64,8 +64,13 @@ procSuite "Waku rln relay":
|
||||||
require:
|
require:
|
||||||
mountRes.isOk()
|
mountRes.isOk()
|
||||||
|
|
||||||
|
let wakuRlnRelay = mountRes.get()
|
||||||
|
|
||||||
# get the root of Merkle tree which is constructed inside the mountRlnRelay proc
|
# get the root of Merkle tree which is constructed inside the mountRlnRelay proc
|
||||||
let calculatedRoot = node.wakuRlnRelay.rlnInstance.getMerkleRoot().value().inHex
|
let calculatedRootRes = wakuRlnRelay.rlnInstance.getMerkleRoot()
|
||||||
|
require:
|
||||||
|
calculatedRootRes.isOk()
|
||||||
|
let calculatedRoot = calculatedRootRes.get().inHex()
|
||||||
debug "calculated root by mountRlnRelay", calculatedRoot
|
debug "calculated root by mountRlnRelay", calculatedRoot
|
||||||
|
|
||||||
# this part checks whether the Merkle tree is constructed correctly inside the mountRlnRelay proc
|
# this part checks whether the Merkle tree is constructed correctly inside the mountRlnRelay proc
|
||||||
|
|
|
@ -8,10 +8,7 @@ import
|
||||||
stew/byteutils, stew/shims/net as stewNet,
|
stew/byteutils, stew/shims/net as stewNet,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
../../waku/v2/protocol/waku_rln_relay/[utils,
|
../../waku/v2/protocol/waku_rln_relay,
|
||||||
constants,
|
|
||||||
protocol_types,
|
|
||||||
rln_relay_contract],
|
|
||||||
../../waku/v2/node/waku_node,
|
../../waku/v2/node/waku_node,
|
||||||
../test_helpers,
|
../test_helpers,
|
||||||
./test_utils
|
./test_utils
|
||||||
|
@ -209,11 +206,11 @@ procSuite "Waku-rln-relay":
|
||||||
let fut = newFuture[void]()
|
let fut = newFuture[void]()
|
||||||
let s = await contractObj.subscribe(MemberRegistered, %*{"fromBlock": "0x0",
|
let s = await contractObj.subscribe(MemberRegistered, %*{"fromBlock": "0x0",
|
||||||
"address": contractAddress}) do(
|
"address": contractAddress}) do(
|
||||||
pubkey: Uint256, index: Uint256){.raises: [Defect], gcsafe.}:
|
idCommitment: Uint256, index: Uint256){.raises: [Defect], gcsafe.}:
|
||||||
try:
|
try:
|
||||||
debug "onRegister", pubkey = pubkey, index = index
|
debug "onRegister", idCommitment = idCommitment, index = index
|
||||||
require:
|
require:
|
||||||
pubkey == pk
|
idCommitment == pk
|
||||||
fut.complete()
|
fut.complete()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
# chronos still raises exceptions which inherit directly from Exception
|
# chronos still raises exceptions which inherit directly from Exception
|
||||||
|
@ -287,9 +284,9 @@ procSuite "Waku-rln-relay":
|
||||||
events[futIndex].complete()
|
events[futIndex].complete()
|
||||||
futIndex += 1
|
futIndex += 1
|
||||||
let index = members[0].index
|
let index = members[0].index
|
||||||
let isSuccessful = rlnPeer.rlnInstance.insertMembers(index, members.mapIt(it.idComm))
|
let insertRes = rlnPeer.insertMembers(index, members.mapIt(it.idComm))
|
||||||
check:
|
check:
|
||||||
isSuccessful
|
insertRes.isOk()
|
||||||
return ok()
|
return ok()
|
||||||
|
|
||||||
# mount the handler for listening to the contract events
|
# mount the handler for listening to the contract events
|
||||||
|
@ -308,7 +305,7 @@ procSuite "Waku-rln-relay":
|
||||||
debug "a member is registered", tx2 = tx2
|
debug "a member is registered", tx2 = tx2
|
||||||
|
|
||||||
# wait for the events to be processed
|
# wait for the events to be processed
|
||||||
await all(events)
|
await allFutures(events)
|
||||||
|
|
||||||
# release resources -----------------------
|
# release resources -----------------------
|
||||||
await web3.close()
|
await web3.close()
|
||||||
|
@ -432,7 +429,8 @@ procSuite "Waku-rln-relay":
|
||||||
# test ------------------------------
|
# test ------------------------------
|
||||||
# start rln-relay
|
# start rln-relay
|
||||||
await node.mountRelay(@[RlnRelayPubsubTopic])
|
await node.mountRelay(@[RlnRelayPubsubTopic])
|
||||||
let mountRes = node.mountRlnRelayStatic(group = group,
|
let mountRes = mountRlnRelayStatic(wakuRelay = node.wakuRelay,
|
||||||
|
group = group,
|
||||||
memKeyPair = keyPair,
|
memKeyPair = keyPair,
|
||||||
memIndex = index,
|
memIndex = index,
|
||||||
pubsubTopic = RlnRelayPubsubTopic,
|
pubsubTopic = RlnRelayPubsubTopic,
|
||||||
|
@ -441,7 +439,9 @@ procSuite "Waku-rln-relay":
|
||||||
require:
|
require:
|
||||||
mountRes.isOk()
|
mountRes.isOk()
|
||||||
|
|
||||||
let calculatedRoot = node.wakuRlnRelay.rlnInstance.getMerkleRoot().value().inHex
|
let wakuRlnRelay = mountRes.get()
|
||||||
|
|
||||||
|
let calculatedRoot = wakuRlnRelay.rlnInstance.getMerkleRoot().value().inHex()
|
||||||
debug "calculated root ", calculatedRoot
|
debug "calculated root ", calculatedRoot
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
@ -522,7 +522,8 @@ procSuite "Waku-rln-relay":
|
||||||
# test ------------------------------
|
# test ------------------------------
|
||||||
# start rln-relay
|
# start rln-relay
|
||||||
await node.mountRelay(@[RlnRelayPubsubTopic])
|
await node.mountRelay(@[RlnRelayPubsubTopic])
|
||||||
discard await node.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
let mountRes = await mountRlnRelayDynamic(wakuRelay = node.wakuRelay,
|
||||||
|
ethClientAddr = EthClient,
|
||||||
ethAccountAddress = some(ethacc),
|
ethAccountAddress = some(ethacc),
|
||||||
ethAccountPrivKeyOpt = some(ethPrivKey),
|
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||||
memContractAddr = contractAddress,
|
memContractAddr = contractAddress,
|
||||||
|
@ -530,12 +531,17 @@ procSuite "Waku-rln-relay":
|
||||||
memIndex = some(MembershipIndex(0)),
|
memIndex = some(MembershipIndex(0)),
|
||||||
pubsubTopic = RlnRelayPubsubTopic,
|
pubsubTopic = RlnRelayPubsubTopic,
|
||||||
contentTopic = RlnRelayContentTopic)
|
contentTopic = RlnRelayContentTopic)
|
||||||
|
|
||||||
|
require:
|
||||||
|
mountRes.isOk()
|
||||||
|
|
||||||
|
let wakuRlnRelay = mountRes.get()
|
||||||
|
|
||||||
await sleepAsync(2000) # wait for the event to reach the group handler
|
await sleepAsync(2000.milliseconds()) # wait for the event to reach the group handler
|
||||||
|
|
||||||
# rln pks are inserted into the rln peer's Merkle tree and the resulting root
|
# rln pks are inserted into the rln peer's Merkle tree and the resulting root
|
||||||
# is expected to be the same as the calculatedRoot i.e., the one calculated outside of the mountRlnRelayDynamic proc
|
# is expected to be the same as the calculatedRoot i.e., the one calculated outside of the mountRlnRelayDynamic proc
|
||||||
let calculatedRoot = node.wakuRlnRelay.rlnInstance.getMerkleRoot().value().inHex
|
let calculatedRoot = wakuRlnRelay.rlnInstance.getMerkleRoot().value().inHex
|
||||||
debug "calculated root ", calculatedRoot=calculatedRoot
|
debug "calculated root ", calculatedRoot=calculatedRoot
|
||||||
debug "expected root ", expectedRoot=expectedRoot
|
debug "expected root ", expectedRoot=expectedRoot
|
||||||
|
|
||||||
|
@ -575,7 +581,8 @@ procSuite "Waku-rln-relay":
|
||||||
|
|
||||||
# start rln-relay on the first node, leave rln-relay credentials empty
|
# start rln-relay on the first node, leave rln-relay credentials empty
|
||||||
await node.mountRelay(@[RlnRelayPubsubTopic])
|
await node.mountRelay(@[RlnRelayPubsubTopic])
|
||||||
discard await node.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
let mountRes = await mountRlnRelayDynamic(wakuRelay=node.wakuRelay,
|
||||||
|
ethClientAddr = EthClient,
|
||||||
ethAccountAddress = some(ethacc),
|
ethAccountAddress = some(ethacc),
|
||||||
ethAccountPrivKeyOpt = some(ethPrivKey),
|
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||||
memContractAddr = contractAddress,
|
memContractAddr = contractAddress,
|
||||||
|
@ -583,12 +590,16 @@ procSuite "Waku-rln-relay":
|
||||||
memIndex = none(MembershipIndex),
|
memIndex = none(MembershipIndex),
|
||||||
pubsubTopic = RlnRelayPubsubTopic,
|
pubsubTopic = RlnRelayPubsubTopic,
|
||||||
contentTopic = RlnRelayContentTopic)
|
contentTopic = RlnRelayContentTopic)
|
||||||
|
|
||||||
|
|
||||||
|
require:
|
||||||
|
mountRes.isOk()
|
||||||
|
|
||||||
|
let wakuRlnRelay = mountRes.get()
|
||||||
|
|
||||||
# start rln-relay on the second node, leave rln-relay credentials empty
|
# start rln-relay on the second node, leave rln-relay credentials empty
|
||||||
await node2.mountRelay(@[RlnRelayPubsubTopic])
|
await node2.mountRelay(@[RlnRelayPubsubTopic])
|
||||||
discard await node2.mountRlnRelayDynamic(ethClientAddr = EthClient,
|
let mountRes2 = await mountRlnRelayDynamic(wakuRelay=node2.wakuRelay,
|
||||||
|
ethClientAddr = EthClient,
|
||||||
ethAccountAddress = some(ethacc),
|
ethAccountAddress = some(ethacc),
|
||||||
ethAccountPrivKeyOpt = some(ethPrivKey),
|
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||||
memContractAddr = contractAddress,
|
memContractAddr = contractAddress,
|
||||||
|
@ -597,12 +608,17 @@ procSuite "Waku-rln-relay":
|
||||||
pubsubTopic = RlnRelayPubsubTopic,
|
pubsubTopic = RlnRelayPubsubTopic,
|
||||||
contentTopic = RlnRelayContentTopic)
|
contentTopic = RlnRelayContentTopic)
|
||||||
|
|
||||||
|
require:
|
||||||
|
mountRes2.isOk()
|
||||||
|
|
||||||
|
let wakuRlnRelay2 = mountRes2.get()
|
||||||
|
|
||||||
# the two nodes should be registered into the contract
|
# the two nodes should be registered into the contract
|
||||||
# since nodes are spun up sequentially
|
# since nodes are spun up sequentially
|
||||||
# the first node has index 0 whereas the second node gets index 1
|
# the first node has index 0 whereas the second node gets index 1
|
||||||
check:
|
check:
|
||||||
node.wakuRlnRelay.membershipIndex == MembershipIndex(0)
|
wakuRlnRelay.membershipIndex == MembershipIndex(0)
|
||||||
node2.wakuRlnRelay.membershipIndex == MembershipIndex(1)
|
wakuRlnRelay2.membershipIndex == MembershipIndex(1)
|
||||||
|
|
||||||
await node.stop()
|
await node.stop()
|
||||||
await node2.stop()
|
await node2.stop()
|
||||||
|
|
|
@ -11,7 +11,6 @@ import
|
||||||
libp2p/peerid,
|
libp2p/peerid,
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
libp2p/switch,
|
libp2p/switch,
|
||||||
libp2p/protocols/pubsub/rpc/messages,
|
|
||||||
libp2p/protocols/pubsub/pubsub,
|
libp2p/protocols/pubsub/pubsub,
|
||||||
eth/keys
|
eth/keys
|
||||||
import
|
import
|
||||||
|
@ -48,54 +47,35 @@ procSuite "WakuNode - RLN relay":
|
||||||
# set up three nodes
|
# set up three nodes
|
||||||
# node1
|
# node1
|
||||||
await node1.mountRelay(@[rlnRelayPubSubTopic])
|
await node1.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes1 = rlnRelayStaticSetUp(1) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes1.isOk()
|
|
||||||
|
|
||||||
let (groupOpt1, memKeyPairOpt1, memIndexOpt1) = staticSetupRes1.get()
|
|
||||||
# mount rlnrelay in off-chain mode
|
# mount rlnrelay in off-chain mode
|
||||||
let mountRes1 = node1.mountRlnRelayStatic(group = groupOpt1.get(),
|
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
memKeyPair = memKeyPairOpt1.get(),
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
memIndex = memIndexOpt1.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
rlnRelayMembershipIndex: MembershipIndex(1),
|
||||||
contentTopic = contentTopic)
|
))
|
||||||
require:
|
|
||||||
mountRes1.isOk()
|
|
||||||
|
|
||||||
await node1.start()
|
await node1.start()
|
||||||
|
|
||||||
# node 2
|
# node 2
|
||||||
await node2.mountRelay(@[rlnRelayPubSubTopic])
|
await node2.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes2 = rlnRelayStaticSetUp(2) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes2.isOk()
|
|
||||||
let (groupOpt2, memKeyPairOpt2, memIndexOpt2) = staticSetupRes2.get()
|
|
||||||
# mount rlnrelay in off-chain mode
|
# mount rlnrelay in off-chain mode
|
||||||
let mountRes2 = node2.mountRlnRelayStatic(group = groupOpt2.get(),
|
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
memKeyPair = memKeyPairOpt2.get(),
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
memIndex = memIndexOpt2.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
rlnRelayMembershipIndex: MembershipIndex(2),
|
||||||
contentTopic = contentTopic)
|
))
|
||||||
require:
|
|
||||||
mountRes2.isOk()
|
|
||||||
|
|
||||||
await node2.start()
|
await node2.start()
|
||||||
|
|
||||||
# node 3
|
# node 3
|
||||||
await node3.mountRelay(@[rlnRelayPubSubTopic])
|
await node3.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes3 = rlnRelayStaticSetUp(3) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes3.isOk()
|
|
||||||
|
|
||||||
let (groupOpt3, memKeyPairOpt3, memIndexOpt3) = staticSetupRes3.get()
|
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
# mount rlnrelay in off-chain mode
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
let mountRes3 = node3.mountRlnRelayStatic(group = groupOpt3.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
memKeyPair = memKeyPairOpt3.get(),
|
rlnRelayMembershipIndex: MembershipIndex(3),
|
||||||
memIndex = memIndexOpt3.get(),
|
))
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
|
||||||
contentTopic = contentTopic)
|
|
||||||
require:
|
|
||||||
mountRes3.isOk()
|
|
||||||
|
|
||||||
await node3.start()
|
await node3.start()
|
||||||
|
|
||||||
|
@ -151,56 +131,41 @@ procSuite "WakuNode - RLN relay":
|
||||||
rlnRelayPubSubTopic = RlnRelayPubsubTopic
|
rlnRelayPubSubTopic = RlnRelayPubsubTopic
|
||||||
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
||||||
|
|
||||||
|
# set up three nodes
|
||||||
|
# node1
|
||||||
# set up three nodes
|
# set up three nodes
|
||||||
# node1
|
# node1
|
||||||
await node1.mountRelay(@[rlnRelayPubSubTopic])
|
await node1.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes1 = rlnRelayStaticSetUp(1) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes1.isOk()
|
|
||||||
|
|
||||||
let (groupOpt1, memKeyPairOpt1, memIndexOpt1) = staticSetupRes1.get()
|
|
||||||
# mount rlnrelay in off-chain mode
|
# mount rlnrelay in off-chain mode
|
||||||
let mountRes1 = node1.mountRlnRelayStatic(group = groupOpt1.get(),
|
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
memKeyPair = memKeyPairOpt1.get(),
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
memIndex = memIndexOpt1.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
rlnRelayMembershipIndex: MembershipIndex(1),
|
||||||
contentTopic = contentTopic)
|
))
|
||||||
require:
|
|
||||||
mountRes1.isOk()
|
|
||||||
await node1.start()
|
await node1.start()
|
||||||
|
|
||||||
# node 2
|
# node 2
|
||||||
await node2.mountRelay(@[rlnRelayPubSubTopic])
|
await node2.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes2 = rlnRelayStaticSetUp(2) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes2.isOk()
|
|
||||||
|
|
||||||
let (groupOpt2, memKeyPairOpt2, memIndexOpt2) = staticSetupRes2.get()
|
|
||||||
# mount rlnrelay in off-chain mode
|
# mount rlnrelay in off-chain mode
|
||||||
let mountRes2 = node2.mountRlnRelayStatic(group = groupOpt2.get(),
|
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
memKeyPair = memKeyPairOpt2.get(),
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
memIndex = memIndexOpt2.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
rlnRelayMembershipIndex: MembershipIndex(2),
|
||||||
contentTopic = contentTopic)
|
))
|
||||||
require:
|
|
||||||
mountRes2.isOk()
|
|
||||||
await node2.start()
|
await node2.start()
|
||||||
|
|
||||||
# node 3
|
# node 3
|
||||||
await node3.mountRelay(@[rlnRelayPubSubTopic])
|
await node3.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes3 = rlnRelayStaticSetUp(3) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes3.isOk()
|
|
||||||
|
|
||||||
let (groupOpt3, memKeyPairOpt3, memIndexOpt3) = staticSetupRes3.get()
|
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
# mount rlnrelay in off-chain mode
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
let mountRes3 = node3.mountRlnRelayStatic(group = groupOpt3.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
memKeyPair = memKeyPairOpt3.get(),
|
rlnRelayMembershipIndex: MembershipIndex(3),
|
||||||
memIndex= memIndexOpt3.get(),
|
))
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
|
||||||
contentTopic = contentTopic)
|
|
||||||
require:
|
|
||||||
mountRes3.isOk()
|
|
||||||
await node3.start()
|
await node3.start()
|
||||||
|
|
||||||
# connect them together
|
# connect them together
|
||||||
|
@ -278,55 +243,37 @@ procSuite "WakuNode - RLN relay":
|
||||||
# set up three nodes
|
# set up three nodes
|
||||||
# node1
|
# node1
|
||||||
await node1.mountRelay(@[rlnRelayPubSubTopic])
|
await node1.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes1 = rlnRelayStaticSetUp(1) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes1.isOk()
|
|
||||||
|
|
||||||
let (groupOpt1, memKeyPairOpt1, memIndexOpt1) = staticSetupRes1.get()
|
|
||||||
# mount rlnrelay in off-chain mode
|
# mount rlnrelay in off-chain mode
|
||||||
let mountRes1 = node1.mountRlnRelayStatic(group = groupOpt1.get(),
|
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
memKeyPair = memKeyPairOpt1.get(),
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
memIndex = memIndexOpt1.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
rlnRelayMembershipIndex: MembershipIndex(1),
|
||||||
contentTopic = contentTopic)
|
))
|
||||||
require:
|
|
||||||
mountRes1.isOk()
|
|
||||||
|
|
||||||
await node1.start()
|
await node1.start()
|
||||||
|
|
||||||
# node 2
|
# node 2
|
||||||
await node2.mountRelay(@[rlnRelayPubSubTopic])
|
await node2.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes2 = rlnRelayStaticSetUp(2) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes2.isOk()
|
|
||||||
|
|
||||||
let (groupOpt2, memKeyPairOpt2, memIndexOpt2) = staticSetupRes2.get()
|
|
||||||
# mount rlnrelay in off-chain mode
|
# mount rlnrelay in off-chain mode
|
||||||
let mountRes2 = node2.mountRlnRelayStatic(group = groupOpt2.get(),
|
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
memKeyPair = memKeyPairOpt2.get(),
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
memIndex = memIndexOpt2.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
rlnRelayMembershipIndex: MembershipIndex(2),
|
||||||
contentTopic = contentTopic)
|
))
|
||||||
require:
|
|
||||||
mountRes2.isOk()
|
|
||||||
|
|
||||||
await node2.start()
|
await node2.start()
|
||||||
|
|
||||||
# node 3
|
# node 3
|
||||||
await node3.mountRelay(@[rlnRelayPubSubTopic])
|
await node3.mountRelay(@[rlnRelayPubSubTopic])
|
||||||
let staticSetupRes3 = rlnRelayStaticSetUp(3) # set up rln relay inputs
|
|
||||||
require:
|
|
||||||
staticSetupRes3.isOk()
|
|
||||||
|
|
||||||
let (groupOpt3, memKeyPairOpt3, memIndexOpt3) = staticSetupRes3.get()
|
|
||||||
# mount rlnrelay in off-chain mode
|
# mount rlnrelay in off-chain mode
|
||||||
let mountRes3 = node3.mountRlnRelayStatic(group = groupOpt3.get(),
|
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
memKeyPair = memKeyPairOpt3.get(),
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
memIndex = memIndexOpt3.get(),
|
rlnRelayContentTopic: contentTopic,
|
||||||
pubsubTopic = rlnRelayPubSubTopic,
|
rlnRelayMembershipIndex: MembershipIndex(3),
|
||||||
contentTopic = contentTopic)
|
))
|
||||||
require:
|
|
||||||
mountRes3.isOk()
|
|
||||||
|
|
||||||
await node3.start()
|
await node3.start()
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ import
|
||||||
|
|
||||||
when defined(rln):
|
when defined(rln):
|
||||||
import
|
import
|
||||||
../protocol/waku_rln_relay/protocol_types
|
../protocol/waku_rln_relay
|
||||||
|
|
||||||
declarePublicGauge waku_version, "Waku version info (in git describe format)", ["version"]
|
declarePublicGauge waku_version, "Waku version info (in git describe format)", ["version"]
|
||||||
declarePublicCounter waku_node_messages, "number of messages received", ["type"]
|
declarePublicCounter waku_node_messages, "number of messages received", ["type"]
|
||||||
|
@ -777,6 +777,22 @@ proc lightpushPublish*(node: WakuNode, pubsubTopic: PubsubTopic, message: WakuMe
|
||||||
|
|
||||||
error "failed to publish message", error=publishRes.error
|
error "failed to publish message", error=publishRes.error
|
||||||
|
|
||||||
|
## Waku RLN Relay
|
||||||
|
when defined(rln):
|
||||||
|
proc mountRlnRelay*(node: WakuNode,
|
||||||
|
rlnConf: WakuRlnConfig,
|
||||||
|
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
||||||
|
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)) {.async.} =
|
||||||
|
info "mounting rln relay"
|
||||||
|
|
||||||
|
let rlnRelayRes = await WakuRlnRelay.new(node.wakuRelay,
|
||||||
|
rlnConf,
|
||||||
|
spamHandler,
|
||||||
|
registrationHandler)
|
||||||
|
if rlnRelayRes.isErr():
|
||||||
|
error "failed to mount rln relay", error=rlnRelayRes.error
|
||||||
|
return
|
||||||
|
node.wakuRlnRelay = rlnRelayRes.get()
|
||||||
|
|
||||||
## Waku peer-exchange
|
## Waku peer-exchange
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,13 @@ import
|
||||||
./waku_rln_relay/constants,
|
./waku_rln_relay/constants,
|
||||||
./waku_rln_relay/protocol_types,
|
./waku_rln_relay/protocol_types,
|
||||||
./waku_rln_relay/protocol_metrics,
|
./waku_rln_relay/protocol_metrics,
|
||||||
./waku_rln_relay/utils
|
./waku_rln_relay/utils,
|
||||||
|
./waku_rln_relay/contract
|
||||||
|
|
||||||
export
|
export
|
||||||
rln,
|
rln,
|
||||||
constants,
|
constants,
|
||||||
protocol_types,
|
protocol_types,
|
||||||
protocol_metrics,
|
protocol_metrics,
|
||||||
utils
|
utils,
|
||||||
|
contract
|
||||||
|
|
|
@ -23,8 +23,8 @@ import
|
||||||
import
|
import
|
||||||
../../utils/time,
|
../../utils/time,
|
||||||
../../utils/keyfile,
|
../../utils/keyfile,
|
||||||
../../node/waku_node,
|
../waku_message,
|
||||||
../waku_message
|
../waku_relay
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "waku rln_relay"
|
topics = "waku rln_relay"
|
||||||
|
@ -971,7 +971,11 @@ proc handleGroupUpdates*(rlnPeer: WakuRLNRelay) {.async, gcsafe.} =
|
||||||
contractAddress = rlnPeer.membershipContractAddress,
|
contractAddress = rlnPeer.membershipContractAddress,
|
||||||
handler = handler)
|
handler = handler)
|
||||||
|
|
||||||
proc addRLNRelayValidator*(node: WakuNode, pubsubTopic: PubsubTopic, contentTopic: ContentTopic, spamHandler: Option[SpamHandler] = none(SpamHandler)) =
|
proc addRLNRelayValidator*(wakuRlnRelay: WakuRLNRelay,
|
||||||
|
wakuRelay: WakuRelay,
|
||||||
|
pubsubTopic: PubsubTopic,
|
||||||
|
contentTopic: ContentTopic,
|
||||||
|
spamHandler: Option[SpamHandler] = none(SpamHandler)) =
|
||||||
## this procedure is a thin wrapper for the pubsub addValidator method
|
## this procedure is a thin wrapper for the pubsub addValidator method
|
||||||
## it sets a validator for the waku messages published on the supplied pubsubTopic and contentTopic
|
## it sets a validator for the waku messages published on the supplied pubsubTopic and contentTopic
|
||||||
## if contentTopic is empty, then validation takes place for All the messages published on the given pubsubTopic
|
## if contentTopic is empty, then validation takes place for All the messages published on the given pubsubTopic
|
||||||
|
@ -998,7 +1002,7 @@ proc addRLNRelayValidator*(node: WakuNode, pubsubTopic: PubsubTopic, contentTopi
|
||||||
|
|
||||||
# validate the message
|
# validate the message
|
||||||
let
|
let
|
||||||
validationRes = node.wakuRlnRelay.validateMessage(wakumessage)
|
validationRes = wakuRlnRelay.validateMessage(wakumessage)
|
||||||
proof = toHex(msgProof.proof)
|
proof = toHex(msgProof.proof)
|
||||||
epoch = fromEpoch(msgProof.epoch)
|
epoch = fromEpoch(msgProof.epoch)
|
||||||
root = inHex(msgProof.merkleRoot)
|
root = inHex(msgProof.merkleRoot)
|
||||||
|
@ -1022,29 +1026,19 @@ proc addRLNRelayValidator*(node: WakuNode, pubsubTopic: PubsubTopic, contentTopi
|
||||||
handler(wakumessage)
|
handler(wakumessage)
|
||||||
return pubsub.ValidationResult.Reject
|
return pubsub.ValidationResult.Reject
|
||||||
# set a validator for the supplied pubsubTopic
|
# set a validator for the supplied pubsubTopic
|
||||||
let pb = PubSub(node.wakuRelay)
|
let pb = PubSub(wakuRelay)
|
||||||
pb.addValidator(pubsubTopic, validator)
|
pb.addValidator(pubsubTopic, validator)
|
||||||
|
|
||||||
proc mountRlnRelayStatic*(node: WakuNode,
|
proc mountRlnRelayStatic*(wakuRelay: WakuRelay,
|
||||||
group: seq[IDCommitment],
|
group: seq[IDCommitment],
|
||||||
memKeyPair: MembershipKeyPair,
|
memKeyPair: MembershipKeyPair,
|
||||||
memIndex: MembershipIndex,
|
memIndex: MembershipIndex,
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
spamHandler: Option[SpamHandler] = none(SpamHandler)): RlnRelayResult[void] =
|
spamHandler: Option[SpamHandler] = none(SpamHandler)): RlnRelayResult[WakuRlnRelay] =
|
||||||
# Returns RlnRelayResult[void] to indicate the success of the call
|
# Returns RlnRelayResult[void] to indicate the success of the call
|
||||||
|
|
||||||
debug "mounting rln-relay in off-chain/static mode"
|
debug "mounting rln-relay in off-chain/static mode"
|
||||||
# check whether inputs are provided
|
|
||||||
# relay protocol is the prerequisite of rln-relay
|
|
||||||
if node.wakuRelay.isNil():
|
|
||||||
return err("WakuRelay protocol is not mounted")
|
|
||||||
# check whether the pubsub topic is supported at the relay level
|
|
||||||
if pubsubTopic notin node.wakuRelay.defaultPubsubTopics:
|
|
||||||
return err("The relay protocol does not support the configured pubsub topic")
|
|
||||||
|
|
||||||
debug "rln-relay input validation passed"
|
|
||||||
|
|
||||||
# check the peer's index and the inclusion of user's identity commitment in the group
|
# check the peer's index and the inclusion of user's identity commitment in the group
|
||||||
if not memKeyPair.idCommitment == group[int(memIndex)]:
|
if not memKeyPair.idCommitment == group[int(memIndex)]:
|
||||||
return err("The peer's index is not consistent with the group")
|
return err("The peer's index is not consistent with the group")
|
||||||
|
@ -1070,33 +1064,23 @@ proc mountRlnRelayStatic*(node: WakuNode,
|
||||||
# adds a topic validator for the supplied pubsub topic at the relay protocol
|
# adds a topic validator for the supplied pubsub topic at the relay protocol
|
||||||
# messages published on this pubsub topic will be relayed upon a successful validation, otherwise they will be dropped
|
# messages published on this pubsub topic will be relayed upon a successful validation, otherwise they will be dropped
|
||||||
# the topic validator checks for the correct non-spamming proof of the message
|
# the topic validator checks for the correct non-spamming proof of the message
|
||||||
node.addRLNRelayValidator(pubsubTopic, contentTopic, spamHandler)
|
rlnPeer.addRLNRelayValidator(wakuRelay, pubsubTopic, contentTopic, spamHandler)
|
||||||
debug "rln relay topic validator is mounted successfully", pubsubTopic=pubsubTopic, contentTopic=contentTopic
|
debug "rln relay topic validator is mounted successfully", pubsubTopic=pubsubTopic, contentTopic=contentTopic
|
||||||
|
|
||||||
node.wakuRlnRelay = rlnPeer
|
return ok(rlnPeer)
|
||||||
return ok()
|
|
||||||
|
|
||||||
proc mountRlnRelayDynamic*(node: WakuNode,
|
proc mountRlnRelayDynamic*(wakuRelay: WakuRelay,
|
||||||
ethClientAddr: string = "",
|
ethClientAddr: string = "",
|
||||||
ethAccountAddress: Option[web3.Address] = none(web3.Address),
|
ethAccountAddress: Option[web3.Address] = none(web3.Address),
|
||||||
ethAccountPrivKeyOpt: Option[keys.PrivateKey],
|
ethAccountPrivKeyOpt: Option[keys.PrivateKey],
|
||||||
memContractAddr: web3.Address,
|
memContractAddr: web3.Address,
|
||||||
memKeyPair: Option[MembershipKeyPair] = none(MembershipKeyPair),
|
memKeyPair: Option[MembershipKeyPair] = none(MembershipKeyPair),
|
||||||
memIndex: Option[MembershipIndex] = none(MembershipIndex),
|
memIndex: Option[MembershipIndex] = none(MembershipIndex),
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
||||||
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)) : Future[RlnRelayResult[void]] {.async.} =
|
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)) : Future[RlnRelayResult[WakuRlnRelay]] {.async.} =
|
||||||
debug "mounting rln-relay in on-chain/dynamic mode"
|
debug "mounting rln-relay in on-chain/dynamic mode"
|
||||||
# TODO return a bool value to indicate the success of the call
|
|
||||||
# relay protocol is the prerequisite of rln-relay
|
|
||||||
if node.wakuRelay.isNil:
|
|
||||||
return err("WakuRelay protocol is not mounted.")
|
|
||||||
# check whether the pubsub topic is supported at the relay level
|
|
||||||
if pubsubTopic notin node.wakuRelay.defaultPubsubTopics:
|
|
||||||
return err("WakuRelay protocol does not support the configured pubsub topic.")
|
|
||||||
debug "rln-relay input validation passed"
|
|
||||||
|
|
||||||
# create an RLN instance
|
# create an RLN instance
|
||||||
let rlnInstance = createRLNInstance()
|
let rlnInstance = createRLNInstance()
|
||||||
|
|
||||||
|
@ -1153,11 +1137,10 @@ proc mountRlnRelayDynamic*(node: WakuNode,
|
||||||
# adds a topic validator for the supplied pubsub topic at the relay protocol
|
# adds a topic validator for the supplied pubsub topic at the relay protocol
|
||||||
# messages published on this pubsub topic will be relayed upon a successful validation, otherwise they will be dropped
|
# messages published on this pubsub topic will be relayed upon a successful validation, otherwise they will be dropped
|
||||||
# the topic validator checks for the correct non-spamming proof of the message
|
# the topic validator checks for the correct non-spamming proof of the message
|
||||||
addRLNRelayValidator(node, pubsubTopic, contentTopic, spamHandler)
|
rlnPeer.addRLNRelayValidator(wakuRelay, pubsubTopic, contentTopic, spamHandler)
|
||||||
debug "rln relay topic validator is mounted successfully", pubsubTopic=pubsubTopic, contentTopic=contentTopic
|
debug "rln relay topic validator is mounted successfully", pubsubTopic=pubsubTopic, contentTopic=contentTopic
|
||||||
|
|
||||||
node.wakuRlnRelay = rlnPeer
|
return ok(rlnPeer)
|
||||||
return ok()
|
|
||||||
|
|
||||||
proc writeRlnCredentials*(path: string,
|
proc writeRlnCredentials*(path: string,
|
||||||
credentials: RlnMembershipCredentials,
|
credentials: RlnMembershipCredentials,
|
||||||
|
@ -1204,34 +1187,37 @@ proc readRlnCredentials*(path: string,
|
||||||
except:
|
except:
|
||||||
return err("Error while loading keyfile for RLN credentials at " & path)
|
return err("Error while loading keyfile for RLN credentials at " & path)
|
||||||
|
|
||||||
proc mount(node: WakuNode,
|
proc mount(wakuRelay: WakuRelay,
|
||||||
conf: WakuRlnConfig,
|
conf: WakuRlnConfig,
|
||||||
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
||||||
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)
|
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)
|
||||||
): Future[RlnRelayResult[void]] {.async.} =
|
): Future[RlnRelayResult[WakuRlnRelay]] {.async.} =
|
||||||
# Returns RlnRelayResult[void], which indicates the success of the call
|
|
||||||
if not conf.rlnRelayDynamic:
|
if not conf.rlnRelayDynamic:
|
||||||
info " setting up waku-rln-relay in off-chain mode... "
|
info " setting up waku-rln-relay in off-chain mode... "
|
||||||
# set up rln relay inputs
|
# set up rln relay inputs
|
||||||
let staticSetupRes = rlnRelayStaticSetUp(MembershipIndex(conf.rlnRelayMembershipIndex))
|
let staticSetupRes = rlnRelayStaticSetUp(MembershipIndex(conf.rlnRelayMembershipIndex))
|
||||||
if staticSetupRes.isErr():
|
if staticSetupRes.isErr():
|
||||||
return err("rln relay static setup failed: " & staticSetupRes.error())
|
return err("rln relay static setup failed: " & staticSetupRes.error())
|
||||||
let (groupOpt, memKeyPairOpt, memIndexOpt) = staticSetupRes.get()
|
let (groupOpt, memKeyPairOpt, memIndexOpt) = staticSetupRes.get()
|
||||||
if memIndexOpt.isNone:
|
if memIndexOpt.isNone():
|
||||||
error "failed to mount WakuRLNRelay"
|
error "failed to mount WakuRLNRelay"
|
||||||
return err("failed to mount WakuRLNRelay")
|
return err("failed to mount WakuRLNRelay")
|
||||||
else:
|
else:
|
||||||
# mount rlnrelay in off-chain mode with a static group of users
|
# mount rlnrelay in off-chain mode with a static group of users
|
||||||
let mountRes = node.mountRlnRelayStatic(group = groupOpt.get(),
|
let mountRes = mountRlnRelayStatic(wakuRelay,
|
||||||
memKeyPair = memKeyPairOpt.get(),
|
group = groupOpt.get(),
|
||||||
memIndex= memIndexOpt.get(),
|
memKeyPair = memKeyPairOpt.get(),
|
||||||
pubsubTopic = conf.rlnRelayPubsubTopic,
|
memIndex = memIndexOpt.get(),
|
||||||
contentTopic = conf.rlnRelayContentTopic,
|
pubsubTopic = conf.rlnRelayPubsubTopic,
|
||||||
spamHandler = spamHandler)
|
contentTopic = conf.rlnRelayContentTopic,
|
||||||
|
spamHandler = spamHandler)
|
||||||
|
|
||||||
if mountRes.isErr():
|
if mountRes.isErr():
|
||||||
return err("Failed to mount WakuRLNRelay: " & mountRes.error())
|
return err("Failed to mount WakuRLNRelay: " & mountRes.error())
|
||||||
|
|
||||||
|
let rlnRelay = mountRes.get()
|
||||||
|
|
||||||
info "membership id key", idkey=memKeyPairOpt.get().idKey.inHex()
|
info "membership id key", idkey=memKeyPairOpt.get().idKey.inHex()
|
||||||
info "membership id commitment key", idCommitmentkey=memKeyPairOpt.get().idCommitment.inHex()
|
info "membership id commitment key", idCommitmentkey=memKeyPairOpt.get().idCommitment.inHex()
|
||||||
|
|
||||||
|
@ -1239,7 +1225,7 @@ proc mount(node: WakuNode,
|
||||||
# no error should happen as it is already captured in the unit tests
|
# no error should happen as it is already captured in the unit tests
|
||||||
# TODO have added this check to account for unseen corner cases, will remove it later
|
# TODO have added this check to account for unseen corner cases, will remove it later
|
||||||
let
|
let
|
||||||
rootRes = node.wakuRlnRelay.rlnInstance.getMerkleRoot()
|
rootRes = rlnRelay.rlnInstance.getMerkleRoot()
|
||||||
expectedRoot = StaticGroupMerkleRoot
|
expectedRoot = StaticGroupMerkleRoot
|
||||||
|
|
||||||
if rootRes.isErr():
|
if rootRes.isErr():
|
||||||
|
@ -1251,7 +1237,7 @@ proc mount(node: WakuNode,
|
||||||
error "root mismatch: something went wrong not in Merkle tree construction"
|
error "root mismatch: something went wrong not in Merkle tree construction"
|
||||||
debug "the calculated root", root
|
debug "the calculated root", root
|
||||||
info "WakuRLNRelay is mounted successfully", pubsubtopic=conf.rlnRelayPubsubTopic, contentTopic=conf.rlnRelayContentTopic
|
info "WakuRLNRelay is mounted successfully", pubsubtopic=conf.rlnRelayPubsubTopic, contentTopic=conf.rlnRelayContentTopic
|
||||||
return ok()
|
return ok(rlnRelay)
|
||||||
else: # mount the rln relay protocol in the on-chain/dynamic mode
|
else: # mount the rln relay protocol in the on-chain/dynamic mode
|
||||||
debug "setting up waku-rln-relay in on-chain mode... "
|
debug "setting up waku-rln-relay in on-chain mode... "
|
||||||
|
|
||||||
|
@ -1268,7 +1254,9 @@ proc mount(node: WakuNode,
|
||||||
var ethAccountPrivKeyOpt = none(keys.PrivateKey)
|
var ethAccountPrivKeyOpt = none(keys.PrivateKey)
|
||||||
var ethAccountAddressOpt = none(Address)
|
var ethAccountAddressOpt = none(Address)
|
||||||
var credentials = none(RlnMembershipCredentials)
|
var credentials = none(RlnMembershipCredentials)
|
||||||
var res: RlnRelayResult[void]
|
var rlnRelayRes: RlnRelayResult[WakuRlnRelay]
|
||||||
|
var rlnRelayCredPath: string
|
||||||
|
var persistCredentials: bool = false
|
||||||
|
|
||||||
if conf.rlnRelayEthAccountPrivateKey != "":
|
if conf.rlnRelayEthAccountPrivateKey != "":
|
||||||
ethAccountPrivKeyOpt = some(keys.PrivateKey(SkSecretKey.fromHex(conf.rlnRelayEthAccountPrivateKey).value))
|
ethAccountPrivKeyOpt = some(keys.PrivateKey(SkSecretKey.fromHex(conf.rlnRelayEthAccountPrivateKey).value))
|
||||||
|
@ -1286,7 +1274,7 @@ proc mount(node: WakuNode,
|
||||||
# if there is a credential file, then no new credentials are generated, instead the content of the file is read and used to mount rln-relay
|
# if there is a credential file, then no new credentials are generated, instead the content of the file is read and used to mount rln-relay
|
||||||
if conf.rlnRelayCredPath != "":
|
if conf.rlnRelayCredPath != "":
|
||||||
|
|
||||||
let rlnRelayCredPath = joinPath(conf.rlnRelayCredPath, RlnCredentialsFilename)
|
rlnRelayCredPath = joinPath(conf.rlnRelayCredPath, RlnCredentialsFilename)
|
||||||
debug "rln-relay credential path", rlnRelayCredPath
|
debug "rln-relay credential path", rlnRelayCredPath
|
||||||
|
|
||||||
# check if there is an rln-relay credential file in the supplied path
|
# check if there is an rln-relay credential file in the supplied path
|
||||||
|
@ -1298,7 +1286,7 @@ proc mount(node: WakuNode,
|
||||||
let readCredentialsRes = readRlnCredentials(rlnRelayCredPath, conf.rlnRelayCredentialsPassword)
|
let readCredentialsRes = readRlnCredentials(rlnRelayCredPath, conf.rlnRelayCredentialsPassword)
|
||||||
|
|
||||||
if readCredentialsRes.isErr():
|
if readCredentialsRes.isErr():
|
||||||
return err("RLN credentials cannot be read: " & readCredentialsRes.error())
|
return err("RLN credentials cannot be read: " & readCredentialsRes.error())
|
||||||
|
|
||||||
credentials = readCredentialsRes.get()
|
credentials = readCredentialsRes.get()
|
||||||
|
|
||||||
|
@ -1309,59 +1297,80 @@ proc mount(node: WakuNode,
|
||||||
|
|
||||||
if credentials.isSome():
|
if credentials.isSome():
|
||||||
# mount rln-relay in on-chain mode, with credentials that were read or generated
|
# mount rln-relay in on-chain mode, with credentials that were read or generated
|
||||||
res = await node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress,
|
rlnRelayRes = await mountRlnRelayDynamic(wakuRelay,
|
||||||
ethClientAddr = ethClientAddr,
|
memContractAddr = ethMemContractAddress,
|
||||||
ethAccountAddress = ethAccountAddressOpt,
|
ethClientAddr = ethClientAddr,
|
||||||
ethAccountPrivKeyOpt = ethAccountPrivKeyOpt,
|
ethAccountAddress = ethAccountAddressOpt,
|
||||||
pubsubTopic = conf.rlnRelayPubsubTopic,
|
ethAccountPrivKeyOpt = ethAccountPrivKeyOpt,
|
||||||
contentTopic = conf.rlnRelayContentTopic,
|
pubsubTopic = conf.rlnRelayPubsubTopic,
|
||||||
spamHandler = spamHandler,
|
contentTopic = conf.rlnRelayContentTopic,
|
||||||
registrationHandler = registrationHandler,
|
spamHandler = spamHandler,
|
||||||
memKeyPair = some(credentials.get().membershipKeyPair),
|
registrationHandler = registrationHandler,
|
||||||
memIndex = some(credentials.get().rlnIndex))
|
memKeyPair = some(credentials.get().membershipKeyPair),
|
||||||
|
memIndex = some(credentials.get().rlnIndex))
|
||||||
else:
|
else:
|
||||||
# mount rln-relay in on-chain mode, with the provided private key
|
# mount rln-relay in on-chain mode, with the provided private key
|
||||||
res = await node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress,
|
rlnRelayRes = await mountRlnRelayDynamic(wakuRelay,
|
||||||
ethClientAddr = ethClientAddr,
|
memContractAddr = ethMemContractAddress,
|
||||||
ethAccountAddress = ethAccountAddressOpt,
|
ethClientAddr = ethClientAddr,
|
||||||
ethAccountPrivKeyOpt = ethAccountPrivKeyOpt,
|
ethAccountAddress = ethAccountAddressOpt,
|
||||||
pubsubTopic = conf.rlnRelayPubsubTopic,
|
ethAccountPrivKeyOpt = ethAccountPrivKeyOpt,
|
||||||
contentTopic = conf.rlnRelayContentTopic,
|
pubsubTopic = conf.rlnRelayPubsubTopic,
|
||||||
spamHandler = spamHandler,
|
contentTopic = conf.rlnRelayContentTopic,
|
||||||
registrationHandler = registrationHandler)
|
spamHandler = spamHandler,
|
||||||
|
registrationHandler = registrationHandler)
|
||||||
|
|
||||||
# TODO should be replaced with key-store with proper encryption
|
persistCredentials = true
|
||||||
# persist rln credential
|
|
||||||
credentials = some(RlnMembershipCredentials(rlnIndex: node.wakuRlnRelay.membershipIndex,
|
|
||||||
membershipKeyPair: node.wakuRlnRelay.membershipKeyPair))
|
|
||||||
if writeRlnCredentials(rlnRelayCredPath, credentials.get(), conf.rlnRelayCredentialsPassword).isErr():
|
|
||||||
return err("error in storing rln credentials")
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# do not persist or use a persisted rln-relay credential
|
# do not persist or use a persisted rln-relay credential
|
||||||
# a new credential will be generated during the mount process but will not be persisted
|
# a new credential will be generated during the mount process but will not be persisted
|
||||||
info "no need to persist or use a persisted rln-relay credential"
|
info "no need to persist or use a persisted rln-relay credential"
|
||||||
res = await node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr,
|
rlnRelayRes = await mountRlnRelayDynamic(wakuRelay,
|
||||||
ethAccountAddress = ethAccountAddressOpt, ethAccountPrivKeyOpt = ethAccountPrivKeyOpt, pubsubTopic = conf.rlnRelayPubsubTopic,
|
memContractAddr = ethMemContractAddress,
|
||||||
contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler, registrationHandler = registrationHandler)
|
ethClientAddr = ethClientAddr,
|
||||||
|
ethAccountAddress = ethAccountAddressOpt,
|
||||||
|
ethAccountPrivKeyOpt = ethAccountPrivKeyOpt,
|
||||||
|
pubsubTopic = conf.rlnRelayPubsubTopic,
|
||||||
|
contentTopic = conf.rlnRelayContentTopic,
|
||||||
|
spamHandler = spamHandler,
|
||||||
|
registrationHandler = registrationHandler)
|
||||||
|
|
||||||
if res.isErr():
|
if rlnRelayRes.isErr():
|
||||||
return err("dynamic rln-relay could not be mounted: " & res.error())
|
return err("dynamic rln-relay could not be mounted: " & rlnRelayRes.error())
|
||||||
return ok()
|
let wakuRlnRelay = rlnRelayRes.get()
|
||||||
|
if persistCredentials:
|
||||||
|
# persist rln credential
|
||||||
|
credentials = some(RlnMembershipCredentials(rlnIndex: wakuRlnRelay.membershipIndex,
|
||||||
|
membershipKeyPair: wakuRlnRelay.membershipKeyPair))
|
||||||
|
if writeRlnCredentials(rlnRelayCredPath, credentials.get(), conf.rlnRelayCredentialsPassword).isErr():
|
||||||
|
return err("error in storing rln credentials")
|
||||||
|
return ok(wakuRlnRelay)
|
||||||
|
|
||||||
proc mountRlnRelay*(node: WakuNode,
|
proc new*(T: type WakuRlnRelay,
|
||||||
conf: WakuRlnConfig,
|
wakuRelay: WakuRelay,
|
||||||
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
conf: WakuRlnConfig,
|
||||||
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)
|
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
||||||
): Future[RlnRelayResult[void]] {.async.} =
|
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)
|
||||||
|
): Future[RlnRelayResult[WakuRlnRelay]] {.async.} =
|
||||||
## Mounts the rln-relay protocol on the node.
|
## Mounts the rln-relay protocol on the node.
|
||||||
## The rln-relay protocol can be mounted in two modes: on-chain and off-chain.
|
## The rln-relay protocol can be mounted in two modes: on-chain and off-chain.
|
||||||
## Returns an error if the rln-relay protocol could not be mounted.
|
## Returns an error if the rln-relay protocol could not be mounted.
|
||||||
waku_rln_relay_mounting_duration_seconds.nanosecondTime:
|
|
||||||
let res = await mount(
|
# check whether inputs are provided
|
||||||
node,
|
# relay protocol is the prerequisite of rln-relay
|
||||||
|
if wakuRelay.isNil():
|
||||||
|
return err("WakuRelay protocol is not mounted")
|
||||||
|
# check whether the pubsub topic is supported at the relay level
|
||||||
|
if conf.rlnRelayPubsubTopic notin wakuRelay.defaultPubsubTopics:
|
||||||
|
return err("The relay protocol does not support the configured pubsub topic")
|
||||||
|
|
||||||
|
debug "rln-relay input validation passed"
|
||||||
|
waku_rln_relay_mounting_duration_seconds.nanosecondTime:
|
||||||
|
let rlnRelayRes = await mount(
|
||||||
|
wakuRelay,
|
||||||
conf,
|
conf,
|
||||||
spamHandler,
|
spamHandler,
|
||||||
registrationHandler
|
registrationHandler
|
||||||
)
|
)
|
||||||
return res
|
return rlnRelayRes
|
Loading…
Reference in New Issue