mirror of https://github.com/waku-org/nwaku.git
Feat(Rln relay): Enables and integrates onchain rln into chat2 (#1029)
* adds wakunode2_types * removes unused imports * adds dynamic rln relay config options * deletes unused imports * replaces static rln-relay with both modes * introduces spamHandler parameter to mountRlnRelay * some debugging info * introduces the config option * adds the eth priv key to the register proc * refactors the code by adding eth private key to the relevant procs * revises config descriptions * minor wording fix * make a minor edit * further edits * adds Eth private key to the config options * calls spam handler when to rln credential is given * defaults to none for the spam handler * updates the membership fee to match the contract * fixes an issue for event subscription * adds eth private key to the transactions made in the tests * adds eth private key for the test of register process * adds comments * deletes lingering echo * displays registration info * removes an echo * removes Goerli testnet from the config descriptions * removes an excess space
This commit is contained in:
parent
2ca27ea898
commit
daaca4a4a3
|
@ -508,29 +508,11 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
|
||||||
echo "A spam message is found and discarded"
|
echo "A spam message is found and discarded"
|
||||||
chat.prompt = false
|
chat.prompt = false
|
||||||
showChatPrompt(chat)
|
showChatPrompt(chat)
|
||||||
|
echo "rln-relay preparation is in progress ..."
|
||||||
# set up rln relay inputs
|
node.mountRlnRelay(conf, some(spamHandler))
|
||||||
let (groupOpt, memKeyPairOpt, memIndexOpt) = rlnRelayStaticSetUp(conf.rlnRelayMemIndex)
|
echo "your membership index is: ", node.wakuRlnRelay.membershipIndex
|
||||||
if memIndexOpt.isNone:
|
echo "your rln identity key is: ", node.wakuRlnRelay.membershipKeyPair.idKey.toHex()
|
||||||
error "failed to mount WakuRLNRelay"
|
echo "your rln identity commitment key is: ", node.wakuRlnRelay.membershipKeyPair.idCommitment.toHex()
|
||||||
else:
|
|
||||||
# mount rlnrelay in offline mode (for now)
|
|
||||||
node.mountRlnRelayStatic(group = groupOpt.get(), memKeyPair = memKeyPairOpt.get(), memIndex = memIndexOpt.get(), pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = some(spamHandler))
|
|
||||||
|
|
||||||
debug "membership id key", idkey=memKeyPairOpt.get().idKey.toHex
|
|
||||||
debug "membership id commitment key", idCommitmentkey=memKeyPairOpt.get().idCommitment.toHex
|
|
||||||
|
|
||||||
# check the correct construction of the tree by comparing the calculated root against the expected root
|
|
||||||
# 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
|
|
||||||
let
|
|
||||||
root = node.wakuRlnRelay.rlnInstance.getMerkleRoot.value.toHex()
|
|
||||||
expectedRoot = STATIC_GROUP_MERKLE_ROOT
|
|
||||||
if root != expectedRoot:
|
|
||||||
error "root mismatch: something went wrong not in Merkle tree construction"
|
|
||||||
debug "the calculated root", root
|
|
||||||
debug "WakuRLNRelay is mounted successfully", pubsubtopic=conf.rlnRelayPubsubTopic, contentTopic=conf.rlnRelayContentTopic
|
|
||||||
|
|
||||||
|
|
||||||
await chat.readWriteLoop()
|
await chat.readWriteLoop()
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,42 @@ type
|
||||||
desc: "the pubsub topic for which rln-relay gets enabled",
|
desc: "the pubsub topic for which rln-relay gets enabled",
|
||||||
defaultValue: "/waku/2/default-waku/proto"
|
defaultValue: "/waku/2/default-waku/proto"
|
||||||
name: "rln-relay-pubsub-topic" }: string
|
name: "rln-relay-pubsub-topic" }: string
|
||||||
|
|
||||||
|
rlnRelayDynamic* {.
|
||||||
|
desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false",
|
||||||
|
defaultValue: false
|
||||||
|
name: "rln-relay-dynamic" }: bool
|
||||||
|
|
||||||
|
rlnRelayIdKey* {.
|
||||||
|
desc: "Rln relay identity secret key as a Hex string",
|
||||||
|
defaultValue: ""
|
||||||
|
name: "rln-relay-id" }: string
|
||||||
|
|
||||||
|
rlnRelayIdCommitmentKey* {.
|
||||||
|
desc: "Rln relay identity commitment key as a Hex string",
|
||||||
|
defaultValue: ""
|
||||||
|
name: "rln-relay-id-commitment" }: string
|
||||||
|
|
||||||
|
rlnRelayEthAccount* {.
|
||||||
|
desc: "Ethereum account address for an Ethereum testnet",
|
||||||
|
defaultValue: ""
|
||||||
|
name: "eth-account-address" }: string
|
||||||
|
|
||||||
|
rlnRelayEthAccountPrivKey* {.
|
||||||
|
desc: "Account private key for an Ethereum testnet",
|
||||||
|
defaultValue: ""
|
||||||
|
name: "eth-account-privatekey" }: string
|
||||||
|
|
||||||
|
rlnRelayEthClientAddress* {.
|
||||||
|
desc: "Ethereum testnet client address e.g., ws://localhost:8540/",
|
||||||
|
defaultValue: "ws://localhost:8540/"
|
||||||
|
name: "eth-client-address" }: string
|
||||||
|
|
||||||
|
rlnRelayEthMemContractAddress* {.
|
||||||
|
desc: "Address of membership contract on an Ethereum testnet",
|
||||||
|
defaultValue: ""
|
||||||
|
name: "eth-mem-contract-address" }: string
|
||||||
|
|
||||||
# NOTE: Keys are different in nim-libp2p
|
# NOTE: Keys are different in nim-libp2p
|
||||||
proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
|
proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -14,6 +14,7 @@ import
|
||||||
rln,
|
rln,
|
||||||
waku_rln_relay_types,
|
waku_rln_relay_types,
|
||||||
../../node/[wakunode2_types,config],
|
../../node/[wakunode2_types,config],
|
||||||
|
../../../../../examples/v2/config_chat2,
|
||||||
../waku_message
|
../waku_message
|
||||||
|
|
||||||
|
|
||||||
|
@ -681,8 +682,8 @@ proc addRLNRelayValidator*(node: WakuNode, pubsubTopic: string, contentTopic: Co
|
||||||
debug "A spam message is found! yay! discarding:", contentTopic=wakumessage.contentTopic, epoch=epoch, timestamp=wakumessage.timestamp, payload=payload
|
debug "A spam message is found! yay! discarding:", contentTopic=wakumessage.contentTopic, epoch=epoch, timestamp=wakumessage.timestamp, payload=payload
|
||||||
trace "A spam message is found! yay! discarding:", proof=proof, root=root, shareX=shareX, shareY=shareY, nullifier=nullifier
|
trace "A spam message is found! yay! discarding:", proof=proof, root=root, shareX=shareX, shareY=shareY, nullifier=nullifier
|
||||||
if spamHandler.isSome:
|
if spamHandler.isSome:
|
||||||
let handler = spamHandler.get
|
let handler = spamHandler.get
|
||||||
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(node.wakuRelay)
|
||||||
|
@ -818,7 +819,7 @@ proc mountRlnRelayDynamic*(node: WakuNode,
|
||||||
node.wakuRlnRelay = rlnPeer
|
node.wakuRlnRelay = rlnPeer
|
||||||
|
|
||||||
|
|
||||||
proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, ValueError, IOError, CatchableError].} =
|
proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf|Chat2Conf, spamHandler: Option[SpamHandler] = none(SpamHandler)) {.raises: [Defect, ValueError, IOError, CatchableError].} =
|
||||||
if not conf.rlnRelayDynamic:
|
if not conf.rlnRelayDynamic:
|
||||||
info " setting up waku-rln-relay in on-chain mode... "
|
info " setting up waku-rln-relay in on-chain mode... "
|
||||||
# set up rln relay inputs
|
# set up rln relay inputs
|
||||||
|
@ -827,7 +828,7 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, Value
|
||||||
error "failed to mount WakuRLNRelay"
|
error "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
|
||||||
node.mountRlnRelayStatic(group = groupOpt.get(), memKeyPair = memKeyPairOpt.get(), memIndex= memIndexOpt.get(), pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic)
|
node.mountRlnRelayStatic(group = groupOpt.get(), memKeyPair = memKeyPairOpt.get(), memIndex= memIndexOpt.get(), pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||||
|
|
||||||
info "membership id key", idkey=memKeyPairOpt.get().idKey.toHex
|
info "membership id key", idkey=memKeyPairOpt.get().idKey.toHex
|
||||||
info "membership id commitment key", idCommitmentkey=memKeyPairOpt.get().idCommitment.toHex
|
info "membership id commitment key", idCommitmentkey=memKeyPairOpt.get().idCommitment.toHex
|
||||||
|
@ -860,9 +861,9 @@ proc mountRlnRelay*(node: WakuNode, conf: WakuNodeConf) {.raises: [Defect, Value
|
||||||
let keyPair = @[(rlnRelayId, rlnRelayIdCommitmentKey)]
|
let keyPair = @[(rlnRelayId, rlnRelayIdCommitmentKey)]
|
||||||
let memKeyPair = keyPair.toMembershipKeyPairs()[0]
|
let memKeyPair = keyPair.toMembershipKeyPairs()[0]
|
||||||
# mount the rln relay protocol in the on-chain/dynamic mode
|
# mount the rln relay protocol in the on-chain/dynamic mode
|
||||||
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, memKeyPair = some(memKeyPair), memIndex = some(rlnRelayIndex), ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic)
|
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, memKeyPair = some(memKeyPair), memIndex = some(rlnRelayIndex), ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||||
else:
|
else:
|
||||||
# no rln credential is provided
|
# no rln credential is provided
|
||||||
# mount the rln relay protocol in the on-chain/dynamic mode
|
# mount the rln relay protocol in the on-chain/dynamic mode
|
||||||
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic)
|
waitFor node.mountRlnRelayDynamic(memContractAddr = ethMemContractAddress, ethClientAddr = ethClientAddr, ethAccAddr = ethAccountAddr, ethAccountPrivKey = ethAccountPrivKey, pubsubTopic = conf.rlnRelayPubsubTopic, contentTopic = conf.rlnRelayContentTopic, spamHandler = spamHandler)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue