Make rln optional (dependencies and compilation) (#602)

* makes rlnlib target optional

* makes the rln-related targets conditioned to the RLN command line flag

* adds the rln compiler flag condition

* adds the rln compiler flag condition to the rln module

* wakunode2 rln conditional compilation

* updates wakunode2 test

* updates waku rln relay tests

* removing the rln test from the default imports of the v2 tests

* imports rln module conditionally

* removes the rln flag condition from the rln module

* separates rln data types from its procs

* adds the import statement

* brings back the contract def to the rln utils

* adds rln module import to the rln unit tests

* clean up and reorganization

* adds a todo

* minor edits on a comment
This commit is contained in:
Sanaz Taheri Boshrooyeh 2021-06-08 11:56:32 -07:00 committed by GitHub
parent e2185caf27
commit 2fe53c334c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 175 additions and 148 deletions

View File

@ -59,6 +59,10 @@ else
NIM_PARAMS := $(NIM_PARAMS) -d:release
endif
ifeq ($(RLN), true)
NIM_PARAMS := $(NIM_PARAMS) -d:rln
endif
deps: | deps-common nat-libs waku.nims rlnlib
ifneq ($(USE_LIBBACKTRACE), 0)
deps: | libbacktrace
@ -116,10 +120,14 @@ else
endif
installganache:
ifeq ($(RLN), true)
npm install ganache-cli; npx ganache-cli -p 8540 -g 0 -l 3000000000000&
endif
rlnlib:
ifeq ($(RLN), true)
cargo build --manifest-path vendor/rln/Cargo.toml
endif
test2: | build deps installganache
echo -e $(BUILD_MSG) "build/$@" && \

View File

@ -12,11 +12,14 @@ import
./v2/test_jsonrpc_waku,
./v2/test_peer_manager,
./v2/test_web3, # TODO remove it when rln-relay tests get finalized
./v2/test_waku_rln_relay,
./v2/test_waku_bridge,
./v2/test_peer_storage,
./v2/test_waku_keepalive
when defined(rln):
import ./v2/test_waku_rln_relay
# TODO Only enable this once swap module is integrated more nicely as a dependency, i.e. as submodule with CI etc
# For PoC execute it manually and run separate module here: https://github.com/vacp2p/swap-contracts-module
# ./v2/test_waku_swap_contracts

View File

@ -1,3 +1,4 @@
{.used.}
import
@ -5,11 +6,12 @@ import
testutils/unittests, chronos, chronicles, stint, web3,
stew/byteutils, stew/shims/net as stewNet,
libp2p/crypto/crypto,
../../waku/v2/protocol/waku_rln_relay/[rln, waku_rln_relay_utils],
../../waku/v2/protocol/waku_rln_relay/[rln, waku_rln_relay_utils, waku_rln_relay_types],
../../waku/v2/node/wakunode2,
../test_helpers,
./test_utils
# the address of Ethereum client (ganache-cli for now)
# TODO this address in hardcoded in the code, we may need to take it as input from the user
const EthClient = "ws://localhost:8540/"
@ -534,15 +536,12 @@ suite "Waku rln relay":
debug "shareY", shareY
debug "nullifier", nullifier
var f = 0.uint32
let verifyIsSuccessful = verify(ctxPtr, addr proof, addr f)
doAssert(verifyIsSuccessful)
# f = 0 means the proof is verified
doAssert(f == 0)
# create and test a bad proof
# prepare a bad authentication object with a wrong peer's index
var badIndex = 8

View File

@ -524,6 +524,7 @@ procSuite "WakuNode":
await node2.stop()
await node3.stop()
when defined(rln):
asyncTest "testing rln-relay with mocked zkp":
let

View File

@ -16,8 +16,8 @@ import
../protocol/waku_store/waku_store,
../protocol/waku_swap/waku_swap,
../protocol/waku_filter/waku_filter,
../protocol/waku_rln_relay/[rln,waku_rln_relay_utils],
../protocol/waku_lightpush/waku_lightpush,
../protocol/waku_rln_relay/waku_rln_relay_types,
../protocol/waku_keepalive/waku_keepalive,
../utils/peers,
./storage/message/message_store,
@ -25,6 +25,9 @@ import
../utils/requests,
./peer_manager/peer_manager
when defined(rln):
import ../protocol/waku_rln_relay/[rln, waku_rln_relay_utils]
declarePublicCounter waku_node_messages, "number of messages received", ["type"]
declarePublicGauge waku_node_filters, "number of content filter subscriptions"
declarePublicGauge waku_node_errors, "number of wakunode errors", ["type"]
@ -304,6 +307,7 @@ proc publish*(node: WakuNode, topic: Topic, message: WakuMessage, rlnRelayEnabl
debug "publish", topic=topic, contentTopic=message.contentTopic
var publishingMessage = message
when defined(rln):
if rlnRelayEnabled:
# if rln relay is enabled then a proof must be generated and added to the waku message
let
@ -408,6 +412,7 @@ proc mountStore*(node: WakuNode, store: MessageStore = nil, persistMessages: boo
if persistMessages:
node.subscriptions.subscribe(WakuStoreCodec, node.wakuStore.subscription())
when defined(rln):
proc mountRlnRelay*(node: WakuNode, ethClientAddress: Option[string] = none(string), ethAccountAddress: Option[Address] = none(Address), membershipContractAddress: Option[Address] = none(Address)) {.async.} =
# TODO return a bool value to indicate the success of the call
# check whether inputs are provided
@ -441,6 +446,7 @@ proc mountRlnRelay*(node: WakuNode, ethClientAddress: Option[string] = none(stri
node.wakuRlnRelay = rlnPeer
when defined(rln):
proc addRLNRelayValidator*(node: WakuNode, pubsubTopic: string) =
## this procedure is a thin wrapper for the pubsub addValidator method
## it sets message validator on the given pubsubTopic, the validator will check that
@ -494,7 +500,7 @@ proc mountRelay*(node: WakuNode,
# Reconnect to previous relay peers. This will respect a backoff period, if necessary
waitFor node.peerManager.reconnectPeers(WakuRelayCodec,
wakuRelay.parameters.pruneBackoff + chronos.seconds(BackoffSlackTime))
when defined(rln):
if rlnRelayEnabled:
# TODO pass rln relay inputs to this proc, right now it uses default values that are set in the mountRlnRelay proc
info "WakuRLNRelay is enabled"

View File

@ -1,7 +1,8 @@
# this module contains the Nim wrappers for the rln library https://github.com/kilic/rln/blob/3bbec368a4adc68cd5f9bfae80b17e1bbb4ef373/src/ffi.rs
import os
import
os,
waku_rln_relay_types
const libPath = "vendor/rln/target/debug/"
when defined(Windows):
@ -14,8 +15,6 @@ elif defined(MacOsX):
# all the following procedures are Nim wrappers for the functions defined in libName
{.push dynlib: libName, raises: [Defect].}
type RLN*[E] {.incompleteStruct.} = object
type Bn256* = pointer
## Buffer struct is taken from
# https://github.com/celo-org/celo-threshold-bls-rs/blob/master/crates/threshold-bls-ffi/src/ffi.rs

View File

@ -0,0 +1,32 @@
import
chronicles, options, chronos, stint,
web3,
eth/keys
## Bn256 and RLN are Nim wrappers for the data types used in
## the rln library https://github.com/kilic/rln/blob/3bbec368a4adc68cd5f9bfae80b17e1bbb4ef373/src/ffi.rs
type Bn256* = pointer
type RLN*[E] {.incompleteStruct.} = object
# Custom data types defined for waku rln relay -------------------------
type MembershipKeyPair* = object
secretKey*: array[32, byte]
publicKey*: array[32, byte]
type WakuRLNRelay* = object
membershipKeyPair*: MembershipKeyPair
ethClientAddress*: string
ethAccountAddress*: Address
# this field is required for signing transactions
# TODO may need to erase this ethAccountPrivateKey when is not used
# TODO may need to make ethAccountPrivateKey mandatory
ethAccountPrivateKey*: Option[PrivateKey]
membershipContractAddress*: Address
# inputs of the membership contract constructor
# TODO may be able to make these constants private and put them inside the waku_rln_relay_utils
const
MembershipFee* = 5.u256
Depth* = 32.u256
# TODO the EthClient should be an input to the rln-relay
EthClient* = "ws://localhost:8540/"

View File

@ -2,29 +2,8 @@ import
chronicles, options, chronos, stint,
web3,
stew/byteutils,
eth/keys,
rln
type MembershipKeyPair* = object
secretKey*: array[32, byte]
publicKey*: array[32, byte]
type WakuRLNRelay* = object
membershipKeyPair*: MembershipKeyPair
ethClientAddress*: string
ethAccountAddress*: Address
# this field is required for signing transactions
# TODO may need to erase this ethAccountPrivateKey when is not used
# TODO may need to make ethAccountPrivateKey mandatory
ethAccountPrivateKey*: Option[PrivateKey]
membershipContractAddress*: Address
# inputs of the membership contract constructor
const
MembershipFee* = 5.u256
Depth* = 32.u256
# TODO the EthClient should be an input to the rln-relay
EthClient* = "ws://localhost:8540/"
rln,
waku_rln_relay_types
# membership contract interface
contract(MembershipContract):