Skip to content

Commit

Permalink
Rln membership registration implementation (#23)
Browse files Browse the repository at this point in the history
* add anvil config and volume to remember state and output account info; nwaku config to register rln membership

* modify run_nwaku.sh for onchain rln

* add script for rln membership registration

* run_nwaku update, removed rln membership index and added other rln parameters

* merged run_register_rln with the run_nwaku script

* added environment variables for rln-contract registration

* removed rpc related flags and added rest flags for sake of completeness, also updated BOOTSTRAP_ENR query

* removed rpc flags, added cred-path and -password

* added keystore volume and 8645 port

* removed keystore volume and keystore parent directory

* remove unused service from docker-compose
  • Loading branch information
stubbsta authored Mar 14, 2024
1 parent c56a083 commit d6fb3e5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/waku-rln-contract"]
path = submodules/waku-rln-contract
url = https://github.com/waku-org/waku-rln-contract.git
17 changes: 12 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ services:
labels:
com.centurylinklabs.watchtower.enable: '${WATCHTOWER_ENABLED:-false}'
ports:
- 127.0.0.1:8541:8541
- 127.0.0.1:8545:8545
command: >
"anvil
--port=8541
--port=8545
--host=0.0.0.0
--chain-id=1337
--block-time=12
--accounts=1
--allow-origin=*"
--allow-origin=*
--silent"
networks:
- simulation

Expand Down Expand Up @@ -54,6 +55,12 @@ services:
deploy:
replicas: ${NUM_NWAKU_NODES:-5}
entrypoint: sh
environment:
- RPC_URL=http://foundry:8545
- PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- RLN_CONTRACT_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
- RLN_CREDENTIAL_PATH=/keystore.json
- RLN_CREDENTIAL_PASSWORD=passw123
command:
- '/opt/run_nwaku.sh'
volumes:
Expand Down Expand Up @@ -158,7 +165,7 @@ services:
ports:
- 127.0.0.1:8090:8090
environment:
- NODE_ENDPOINT=http://foundry:8541
- NODE_ENDPOINT=http://foundry:8545
- MONGO_CLIENT_URI=mongodb://mongodb:27017
- REINDEX_ENDPOINT=http://ingestion/reindex/
- MONGO_DB_NAME=epirus
Expand Down Expand Up @@ -197,7 +204,7 @@ services:
ingestion:
image: web3labs/epirus-free-ingestion:latest
environment:
- NODE_ENDPOINT=http://foundry:8541
- NODE_ENDPOINT=http://foundry:8545
- MONGO_CLIENT_URI=mongodb://mongodb:27017
- MONGO_DB_NAME=epirus
- LIST_OF_METRICS_TO_CALCULATE_PER_MINUTE=hourly,daily,monthly,yearly
Expand Down
10 changes: 5 additions & 5 deletions run_bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ echo "I am a bootstrap node"

exec /usr/bin/wakunode\
--relay=true\
--rest=true\
--rest-admin=true\
--rest-private=true\
--rest-address=0.0.0.0\
--keep-alive=true\
--max-connections=300\
--dns-discovery=true\
Expand All @@ -19,4 +15,8 @@ exec /usr/bin/wakunode\
--metrics-server=True\
--metrics-server-address=0.0.0.0\
--nodekey=30348dd51465150e04a5d9d932c72864c8967f806cce60b5d26afeca1e77eb68\
--nat=extip:${IP}
--nat=extip:${IP}\
--rest=true\
--rest-admin=true\
--rest-private=true\
--rest-address=0.0.0.0
54 changes: 51 additions & 3 deletions run_nwaku.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
#!/bin/sh

# Install bind-tools package used for domainname resolution
apk add bind-tools

if test -f .env; then
echo "Using .env file"
. $(pwd)/.env
fi

# Function to extract IP address from URL, resolve the IP and replace it in the original URL
get_ip_address_and_replace() {
local url=$1
local domain_name=$(echo $RPC_URL | awk -F[/:] '{print $4}')
local ip_address=$(dig +short $domain_name)
valid_rpc_url="${url/$domain_name/$ip_address}"
echo $valid_rpc_url
}

# the format of the RPC URL is checked in the generateRlnKeystore command and hostnames are not valid
pattern="^(https?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*"
# Perform regex matching
if [[ $RPC_URL =~ $pattern ]]; then
echo "RPC URL is valid"
else
echo "RPC URL is invalid: $RPC_URL. Attempting to resolve hostname."
resolved_rpc_url="$(get_ip_address_and_replace $RPC_URL)"
if [ -z "$resolved_rpc_url" ]; then
echo -e "Failed to retrieve IP address for $RPC_URL\n"
else
echo -e "Resolved RPC URL for $RPC_URL: $resolved_rpc_url"
RPC_URL="$resolved_rpc_url"
fi
fi

if test -f .$RLN_CREDENTIAL_PATH; then
echo "$RLN_CREDENTIAL_PATH already exists. Use it instead of creating a new one."
else
/usr/bin/wakunode generateRlnKeystore \
--rln-relay-eth-client-address="$RPC_URL" \
--rln-relay-eth-private-key=$PRIVATE_KEY \
--rln-relay-eth-contract-address=$RLN_CONTRACT_ADDRESS \
--rln-relay-cred-path=$RLN_CREDENTIAL_PATH \
--rln-relay-cred-password=$RLN_CREDENTIAL_PASSWORD \
--execute
fi

IP=$(ip a | grep "inet " | grep -Fv 127.0.0.1 | sed 's/.*inet \([^/]*\).*/\1/')

echo "I am a nwaku node"
Expand Down Expand Up @@ -34,13 +79,16 @@ exec /usr/bin/wakunode\
--rest-private=true\
--rest-address=0.0.0.0\
--rln-relay=true\
--rln-relay-dynamic=false\
--rln-relay-membership-index=${NODE_INDEX}\
--rln-relay-dynamic=true\
--rln-relay-eth-client-address="$RPC_URL"\
--rln-relay-eth-contract-address=$RLN_CONTRACT_ADDRESS\
--rln-relay-cred-path=$RLN_CREDENTIAL_PATH\
--rln-relay-cred-password=$RLN_CREDENTIAL_PASSWORD\
--dns-discovery=true\
--discv5-discovery=true\
--discv5-enr-auto-update=True\
--log-level=INFO\
--metrics-server=True\
--metrics-server-address=0.0.0.0\
--discv5-bootstrap-node=${BOOTSTRAP_ENR}\
--nat=extip:${IP}
--nat=extip:${IP}
1 change: 1 addition & 0 deletions submodules/waku-rln-contract
Submodule waku-rln-contract added at a01daa

0 comments on commit d6fb3e5

Please sign in to comment.