diff --git a/.gitmodules b/.gitmodules index ef341c24f..5c7cb0376 100644 --- a/.gitmodules +++ b/.gitmodules @@ -143,7 +143,7 @@ path = vendor/zerokit url = https://github.com/vacp2p/zerokit.git ignore = dirty - branch = v0.3.2 + branch = v0.3.4 [submodule "vendor/nim-regex"] path = vendor/nim-regex url = https://github.com/nitely/nim-regex.git diff --git a/Makefile b/Makefile index e083d3032..586bdb82e 100644 --- a/Makefile +++ b/Makefile @@ -119,16 +119,17 @@ clean: | clean-libbacktrace .PHONY: librln LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit +LIBRLN_VERSION := v0.3.4 ifeq ($(OS),Windows_NT) LIBRLN_FILE := rln.lib else -LIBRLN_FILE := librln.a +LIBRLN_FILE := librln_$(LIBRLN_VERSION).a endif $(LIBRLN_FILE): echo -e $(BUILD_MSG) "$@" && \ - ./scripts/build_rln.sh $(LIBRLN_BUILDDIR) + ./scripts/build_rln.sh $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(LIBRLN_FILE) librln: | $(LIBRLN_FILE) diff --git a/scripts/build_rln.sh b/scripts/build_rln.sh index 3fda88ab8..dec443dc4 100755 --- a/scripts/build_rln.sh +++ b/scripts/build_rln.sh @@ -7,25 +7,45 @@ set -e # first argument is the build directory build_dir=$1 +rln_version=$2 +output_filename=$3 if [[ -z "$build_dir" ]]; then echo "No build directory specified" exit 1 fi +if [[ -z "$rln_version" ]]; then + echo "No rln version specified" + exit 1 +fi + +if [[ -z "$output_filename" ]]; then + echo "No output filename specified" + exit 1 +fi + # Get the host triplet host_triplet=$(rustup show | grep "Default host: " | cut -d' ' -f3) # Download the prebuilt rln library if it is available -if curl --silent --fail-with-body -L "https://github.com/vacp2p/zerokit/releases/download/v0.3.2/$host_triplet-rln.tar.gz" >> "$host_triplet-rln.tar.gz" +if curl --silent --fail-with-body -L "https://github.com/vacp2p/zerokit/releases/download/$rln_version/$host_triplet-rln.tar.gz" >> "$host_triplet-rln.tar.gz" then echo "Downloaded $host_triplet-rln.tar.gz" tar -xzf "$host_triplet-rln.tar.gz" - mv release/librln.a . + mv release/librln.a $output_filename rm -rf "$host_triplet-rln.tar.gz" release else echo "Failed to download $host_triplet-rln.tar.gz" # Build rln instead + # first, check if submodule version = version in Makefile + submodule_version=$(cargo metadata --format-version=1 --no-deps | jq '.packages[] | select(.name == "rln") | .version') + if [[ "v$submodule_version" != "$rln_version" ]]; then + echo "Submodule version (v$submodule_version) does not match version in Makefile ($rln_version)" + echo "Please update the submodule to $rln_version" + exit 1 + fi + # if submodule version = version in Makefile, build rln cargo build --release -p rln --manifest-path "$build_dir/rln/Cargo.toml" - cp "$build_dir/target/release/librln.a" . + cp "$build_dir/target/release/librln.a" $output_filename fi diff --git a/tests/waku_rln_relay/test_waku_rln_relay.nim b/tests/waku_rln_relay/test_waku_rln_relay.nim index d99bc1812..bb032f964 100644 --- a/tests/waku_rln_relay/test_waku_rln_relay.nim +++ b/tests/waku_rln_relay/test_waku_rln_relay.nim @@ -210,6 +210,7 @@ suite "Waku rln relay": idCredentialRes.isOk() check: rln.insertMembers(0, @[idCredentialRes.get().idCommitment]) + rln.leavesSet() == 1 test "insertMember rln utils": # create an RLN instance which also includes an empty Merkle tree diff --git a/vendor/zerokit b/vendor/zerokit index b51896c3a..b903d8d74 160000 --- a/vendor/zerokit +++ b/vendor/zerokit @@ -1 +1 @@ -Subproject commit b51896c3a710f567fc7e054681767d6547a8eb9b +Subproject commit b903d8d740e0b8b82057bcc5377ddce05ae5676b diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index f23cc0d30..618a64d00 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -106,7 +106,7 @@ method atomicBatch*(g: OnchainGroupManager, if not operationSuccess: raise newException(ValueError, "atomic batch operation failed") # TODO: when slashing is enabled, we need to track slashed members - waku_rln_number_registered_memberships.set(int64(start.int + idCommitments.len - toRemoveIndices.len)) + waku_rln_number_registered_memberships.set(int64(g.rlnInstance.leavesSet())) if g.registerCb.isSome(): var membersSeq = newSeq[Membership]() @@ -352,8 +352,10 @@ proc startOnchainSync(g: OnchainGroupManager): Future[void] {.async.} = let blockChunkSize = 2_000 var fromBlock = if g.latestProcessedBlock > g.rlnContractDeployedBlockNumber: + info "syncing from last processed block", blockNumber = g.latestProcessedBlock g.latestProcessedBlock + 1 else: + info "syncing from rln contract deployed block", blockNumber = g.rlnContractDeployedBlockNumber g.rlnContractDeployedBlockNumber try: @@ -482,6 +484,7 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = var deployedBlockNumber: Uint256 try: deployedBlockNumber = await rlnContract.deployedBlockNumber().call() + debug "using rln storage", deployedBlockNumber, rlnContractAddress except CatchableError: raise newException(ValueError, "could not get the deployed block number: " & getCurrentExceptionMsg()) @@ -504,6 +507,7 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = except CatchableError: error "failed to restart group sync", error = getCurrentExceptionMsg() + waku_rln_number_registered_memberships.set(int64(g.rlnInstance.leavesSet())) g.initialized = true method stop*(g: OnchainGroupManager): Future[void] {.async.} = diff --git a/waku/waku_rln_relay/rln/rln_interface.nim b/waku/waku_rln_relay/rln/rln_interface.nim index 828b20548..c3668c6c6 100644 --- a/waku/waku_rln_relay/rln/rln_interface.nim +++ b/waku/waku_rln_relay/rln/rln_interface.nim @@ -59,6 +59,10 @@ proc get_leaf*(ctx: ptr RLN, index: uint, output_buffer: ptr Buffer): bool {.imp ## the output_buffer holds a serialized leaf of 32 bytes ## the return bool value indicates the success or failure of the operation +proc leaves_set*(ctx: ptr RLN): uint {.importc: "leaves_set".} +## gets the number of leaves set in the tree stored by ctx +## the return uint value indicates the number of leaves set in the tree + proc init_tree_with_leaves*(ctx: ptr RLN, input_buffer: ptr Buffer): bool {.importc: "init_tree_with_leaves".} ## sets multiple leaves in the tree stored by ctx to the value passed by input_buffer ## the input_buffer holds a serialized vector of leaves (32 bytes each)