Skip to content

Commit

Permalink
chore(rln-relay): logs, updated submodule, leaves_set metric (#2024)
Browse files Browse the repository at this point in the history
* chore(rln-relay): logs, updated submodule, leaves_set metric

* chore(rln-relay): update build script, fix makefile
  • Loading branch information
rymnc committed Sep 18, 2023
1 parent dac072f commit 2e515a0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 23 additions & 3 deletions scripts/build_rln.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/waku_rln_relay/test_waku_rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vendor/zerokit
6 changes: 5 additions & 1 deletion waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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())
Expand All @@ -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.} =
Expand Down
4 changes: 4 additions & 0 deletions waku/waku_rln_relay/rln/rln_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2e515a0

Please sign in to comment.