get anvil account private keys and use nwaku container index to select one

This commit is contained in:
stubbsta 2024-05-23 16:25:55 +02:00
parent c0760faf8b
commit 894f73462d
No known key found for this signature in database
3 changed files with 60 additions and 12 deletions

View File

@ -16,16 +16,20 @@ services:
com.centurylinklabs.watchtower.enable: '${WATCHTOWER_ENABLED:-false}' com.centurylinklabs.watchtower.enable: '${WATCHTOWER_ENABLED:-false}'
ports: ports:
- 0.0.0.0:8545:8545 - 0.0.0.0:8545:8545
environment:
- ANVIL_ACC=${ACCOUNTS}
command: command:
- anvil - anvil
--port=8545 --port=8545
--host=0.0.0.0 --host=0.0.0.0
--chain-id=1337 --chain-id=1337
--accounts=1 --accounts=${NUM_NWAKU_NODES:-5}
--allow-origin=* --allow-origin=*
--block-time=12 --block-time=12
--silent --silent
--config-out=anvil-config.txt --config-out=/shared/anvil-config.txt
volumes:
- accounts-volume:/shared
networks: networks:
- simulation - simulation
@ -74,7 +78,6 @@ services:
entrypoint: sh entrypoint: sh
environment: environment:
- RPC_URL=${RPC_URL:-http://foundry:8545} - RPC_URL=${RPC_URL:-http://foundry:8545}
- PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- RLN_CONTRACT_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 - RLN_CONTRACT_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
- RLN_CREDENTIAL_PATH=/keystore.json - RLN_CREDENTIAL_PATH=/keystore.json
- RLN_CREDENTIAL_PASSWORD=passw123 - RLN_CREDENTIAL_PASSWORD=passw123
@ -82,6 +85,8 @@ services:
- '/opt/run_nwaku.sh' - '/opt/run_nwaku.sh'
volumes: volumes:
- ./run_nwaku.sh:/opt/run_nwaku.sh:Z - ./run_nwaku.sh:/opt/run_nwaku.sh:Z
- ./parseAccountsDetails.sh:/opt/parseAccountsDetails.sh:Z
- accounts-volume:/shared
depends_on: depends_on:
contract-repo-deployer: contract-repo-deployer:
condition: service_completed_successfully condition: service_completed_successfully
@ -213,4 +218,7 @@ services:
- redis - redis
- foundry - foundry
networks: networks:
- simulation - simulation
volumes:
accounts-volume:

23
parseAccountsDetails.sh Normal file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# Read the JSON file
json_content=$(cat /shared/anvil-config.txt)
# Extract available_accounts and private_keys arrays using jq
available_accounts=$(echo "$json_content" | jq -r '.available_accounts[]')
private_keys=$(echo "$json_content" | jq -r '.private_keys[]')
# Convert the extracted strings to Bash arrays
available_accounts_array=()
while IFS= read -r account; do
available_accounts_array+=("$account")
done <<< "$available_accounts"
private_keys_array=()
while IFS= read -r key; do
private_keys_array+=("$key")
done <<< "$private_keys"
# echo "ACCOUNT: ${available_accounts_array[$1-1]}"
# echo "PRIVATE KEY: ${private_keys_array[$1-1]}"
echo ${private_keys_array[$1-1]}

View File

@ -1,7 +1,9 @@
#!/bin/sh #!/bin/bash
# Install bind-tools package used for domainname resolution # Install bind-tools package used for domainname resolution
apk add bind-tools apk add bind-tools
apk add jq
apk add bash
if test -f .env; then if test -f .env; then
echo "Using .env file" echo "Using .env file"
@ -33,18 +35,35 @@ else
fi fi
fi fi
IP=$(ip a | grep "inet " | grep -Fv 127.0.0.1 | sed 's/.*inet \([^/]*\).*/\1/')
echo "IP: $IP"
# get the service name you specified in the docker-compose.yml
# by a reverse DNS lookup on the IP
SERVICE=`dig -x $IP +short | cut -d'_' -f2`
# the number of replicas is equal to the A records
# associated with the service name
COUNT=`dig $SERVICE +short | wc -l`
# extract the replica number from the same PTR entry
INDEX=`dig -x $IP +short | sed 's/.*_\([0-9]*\)\..*/\1/'`
# Hello
echo "Hello I'm container $INDEX of $COUNT"
###########################################################################
if test -f .$RLN_CREDENTIAL_PATH; then if test -f .$RLN_CREDENTIAL_PATH; then
echo "$RLN_CREDENTIAL_PATH already exists. Use it instead of creating a new one." echo "$RLN_CREDENTIAL_PATH already exists. Use it instead of creating a new one."
else else
val=$(/bin/bash ./opt/parseAccountsDetails.sh $INDEX)
wait_time=$((RANDOM % 400)) echo $val
echo "Waiting $wait_time seconds before generating RLN keystore to avoid collision with other nodes."
sleep $wait_time;
echo "Generating RLN keystore" echo "Generating RLN keystore"
/usr/bin/wakunode generateRlnKeystore \ /usr/bin/wakunode generateRlnKeystore \
--rln-relay-eth-client-address="$RPC_URL" \ --rln-relay-eth-client-address="$RPC_URL" \
--rln-relay-eth-private-key=$PRIVATE_KEY \ --rln-relay-eth-private-key=$val \
--rln-relay-eth-contract-address=$RLN_CONTRACT_ADDRESS \ --rln-relay-eth-contract-address=$RLN_CONTRACT_ADDRESS \
--rln-relay-cred-path=$RLN_CREDENTIAL_PATH \ --rln-relay-cred-path=$RLN_CREDENTIAL_PATH \
--rln-relay-cred-password=$RLN_CREDENTIAL_PASSWORD \ --rln-relay-cred-password=$RLN_CREDENTIAL_PASSWORD \
@ -52,8 +71,6 @@ else
--execute --execute
fi fi
IP=$(ip a | grep "inet " | grep -Fv 127.0.0.1 | sed 's/.*inet \([^/]*\).*/\1/')
echo "I am a nwaku node" echo "I am a nwaku node"
# Get an unique node index based on the container's IP # Get an unique node index based on the container's IP