Enables RLN compilation under CI env var (#786)

* compiles RLN if CI is defined

* minor ineffective change

* minor

* removes excess space

* resolves namespace conflicts

* moves pubsub import under compiler flag

* disables rln on-chain tests

* brings back the on-chain tests and fixes a name mismatch

* adds a debug log message

* minor formating

* kills ganache-cli procces on windows

* wip: adds a line to kill ganache-cli on windows

* disables rln-relay tests that depend on ganache-cli

* disables ganache-cli installation

* introduces onchain rln flag

* fixes a flaky test

* enables onchain test in non-windows CIs

* moves variables around

it seems detected_os is undefined, hence the compiler flag onchain_rln, which is conditioned to the os, does not get added

* limits onchain rln to macOS
This commit is contained in:
Sanaz Taheri Boshrooyeh 2022-01-28 13:57:17 -08:00 committed by GitHub
parent 4421b8de00
commit a5f8b90c23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 117 deletions

View File

@ -68,8 +68,32 @@ else
NIM_PARAMS := $(NIM_PARAMS) -d:release
endif
# control rln code compilation
ifeq ($(RLN), true)
NIM_PARAMS := $(NIM_PARAMS) -d:rln
else ifeq ($(CI), true)
NIM_PARAMS := $(NIM_PARAMS) -d:rln
endif
# detecting the os
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
else ifeq ($(strip $(shell uname)),Darwin)
detected_OS := macOS
else
# e.g. Linux
detected_OS := $(strip $(shell uname))
endif
# control compilation of rln tests that require on chain interaction
ifeq ($(ONCHAIN_RLN), true)
NIM_PARAMS := $(NIM_PARAMS) -d:onchain_rln
else
ifeq ($(CI), true)
ifeq ($(detected_OS), macOS)
NIM_PARAMS := $(NIM_PARAMS) -d:onchain_rln
endif
endif
endif
deps: | deps-common nat-libs waku.nims rlnlib
@ -123,24 +147,23 @@ example2: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim example2 $(NIM_PARAMS) waku.nims
# detecting the os
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
else ifeq ($(strip $(shell uname)),Darwin)
detected_OS := macOS
else
# e.g. Linux
detected_OS := $(strip $(shell uname))
endif
installganache:
ifeq ($(RLN), true)
ifeq ($(ONCHAIN_RLN), true)
npm install ganache-cli; npx ganache-cli -p 8540 -g 0 -l 3000000000000&
else
ifeq ($(CI), true)
ifeq ($(detected_OS), macOS)
npm install ganache-cli; npx ganache-cli -p 8540 -g 0 -l 3000000000000&
endif
endif
endif
rlnlib:
ifeq ($(RLN), true)
cargo build --manifest-path vendor/rln/Cargo.toml
else ifeq ($(CI), true)
cargo build --manifest-path vendor/rln/Cargo.toml
endif
test2: | build deps installganache

View File

@ -136,11 +136,13 @@ proc uploadContract(ethClientAddress: string): Future[Address] {.async.} =
return contractAddress
procSuite "Waku rln relay":
when defined(onchain_rln):
asyncTest "contract membership":
let contractAddress = await uploadContract(EthClient)
debug "ethereum client address", ETH_CLIENT
let contractAddress = await uploadContract(ETH_CLIENT)
# connect to the eth client
let web3 = await newWeb3(EthClient)
debug "web3 connected to", EthClient
let web3 = await newWeb3(ETH_CLIENT)
debug "web3 connected to", ETH_CLIENT
# fetch the list of registered accounts
let accounts = await web3.provider.eth_accounts()
@ -163,15 +165,15 @@ procSuite "Waku rln relay":
# debug "Balance after registration: ", balance
await web3.close()
debug "disconnected from", EthClient
debug "disconnected from", ETH_CLIENT
asyncTest "registration procedure":
# deploy the contract
let contractAddress = await uploadContract(EthClient)
let contractAddress = await uploadContract(ETH_CLIENT)
# prepare rln-relay peer inputs
let
web3 = await newWeb3(EthClient)
web3 = await newWeb3(ETH_CLIENT)
accounts = await web3.provider.eth_accounts()
# choose one of the existing accounts for the rln-relay peer
ethAccountAddress = accounts[9]
@ -189,7 +191,7 @@ procSuite "Waku rln relay":
# initialize the WakuRLNRelay
var rlnPeer = WakuRLNRelay(membershipKeyPair: membershipKeyPair.get(),
membershipIndex: MembershipIndex(0),
ethClientAddress: EthClient,
ethClientAddress: ETH_CLIENT,
ethAccountAddress: ethAccountAddress,
membershipContractAddress: contractAddress)
@ -205,11 +207,11 @@ procSuite "Waku rln relay":
await node.start()
# deploy the contract
let membershipContractAddress = await uploadContract(EthClient)
let membershipContractAddress = await uploadContract(ETH_CLIENT)
# prepare rln-relay inputs
let
web3 = await newWeb3(EthClient)
web3 = await newWeb3(ETH_CLIENT)
accounts = await web3.provider.eth_accounts()
# choose one of the existing account for the rln-relay peer
ethAccountAddress = accounts[9]
@ -248,7 +250,7 @@ procSuite "Waku rln relay":
# start rln-relay
node.mountRelay(@[RLNRELAY_PUBSUB_TOPIC])
await node.mountRlnRelay(ethClientAddrOpt = some(EthClient), ethAccAddrOpt = some(ethAccountAddress), memContractAddOpt = some(membershipContractAddress), groupOpt = some(group), memKeyPairOpt = some(keypair.get()), memIndexOpt = some(index), pubsubTopic = RLNRELAY_PUBSUB_TOPIC)
await node.mountRlnRelay(ethClientAddrOpt = some(ETH_CLIENT), ethAccAddrOpt = some(ethAccountAddress), memContractAddOpt = some(membershipContractAddress), groupOpt = some(group), memKeyPairOpt = some(keypair.get()), memIndexOpt = some(index), pubsubTopic = RLNRELAY_PUBSUB_TOPIC)
let calculatedRoot = node.wakuRlnRelay.rlnInstance.getMerkleRoot().value().toHex
debug "calculated root ", calculatedRoot
@ -885,13 +887,13 @@ suite "Waku rln relay":
# validate messages
# validateMessage proc checks the validity of the message fields and adds it to the log (if valid)
let
msgValidate1 = wakuRlnRelay.validateMessage(wm1)
msgValidate1 = wakuRlnRelay.validateMessage(wm1, some(time))
# wm2 is published within the same Epoch as wm1 and should be found as spam
msgValidate2 = wakuRlnRelay.validateMessage(wm2)
msgValidate2 = wakuRlnRelay.validateMessage(wm2, some(time))
# a valid message should be validated successfully
msgValidate3 = wakuRlnRelay.validateMessage(wm3)
msgValidate3 = wakuRlnRelay.validateMessage(wm3, some(time))
# wm4 has no rln proof and should not be validated
msgValidate4 = wakuRlnRelay.validateMessage(wm4)
msgValidate4 = wakuRlnRelay.validateMessage(wm4, some(time))
check:

View File

@ -427,18 +427,25 @@ proc compare*(e1, e2: Epoch): int64 =
return int64(epoch1) - int64(epoch2)
proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage): MessageValidationResult =
proc validateMessage*(rlnPeer: WakuRLNRelay, msg: WakuMessage, timeOption: Option[float64] = none(float64)): MessageValidationResult =
## validate the supplied `msg` based on the waku-rln-relay routing protocol i.e.,
## the `msg`'s epoch is within MAX_EPOCH_GAP of the current epoch
## the `msg` has valid rate limit proof
## the `msg` does not violate the rate limit
## `timeOption` indicates Unix epoch time (fractional part holds sub-seconds)
## if `timeOption` is supplied, then the current epoch is calculated based on that
# checks if the `msg`'s epoch is far from the current epoch
# it corresponds to the validation of rln external nullifier
let
var epoch: Epoch
if timeOption.isSome():
epoch = calcEpoch(timeOption.get())
else:
# get current rln epoch
epoch = getCurrentEpoch()
let
msgEpoch = msg.proof.epoch
# calculate the gaps
gap = compare(epoch, msgEpoch)