mirror of
https://github.com/waku-org/waku-simulator.git
synced 2025-02-28 15:30:31 +00:00
get anvil account private keys and use nwaku container index to select one
This commit is contained in:
parent
c0760faf8b
commit
894f73462d
@ -16,16 +16,20 @@ services:
|
||||
com.centurylinklabs.watchtower.enable: '${WATCHTOWER_ENABLED:-false}'
|
||||
ports:
|
||||
- 0.0.0.0:8545:8545
|
||||
environment:
|
||||
- ANVIL_ACC=${ACCOUNTS}
|
||||
command:
|
||||
- anvil
|
||||
--port=8545
|
||||
--host=0.0.0.0
|
||||
--chain-id=1337
|
||||
--accounts=1
|
||||
--accounts=${NUM_NWAKU_NODES:-5}
|
||||
--allow-origin=*
|
||||
--block-time=12
|
||||
--silent
|
||||
--config-out=anvil-config.txt
|
||||
--config-out=/shared/anvil-config.txt
|
||||
volumes:
|
||||
- accounts-volume:/shared
|
||||
networks:
|
||||
- simulation
|
||||
|
||||
@ -74,7 +78,6 @@ services:
|
||||
entrypoint: sh
|
||||
environment:
|
||||
- RPC_URL=${RPC_URL:-http://foundry:8545}
|
||||
- PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
|
||||
- RLN_CONTRACT_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
|
||||
- RLN_CREDENTIAL_PATH=/keystore.json
|
||||
- RLN_CREDENTIAL_PASSWORD=passw123
|
||||
@ -82,6 +85,8 @@ services:
|
||||
- '/opt/run_nwaku.sh'
|
||||
volumes:
|
||||
- ./run_nwaku.sh:/opt/run_nwaku.sh:Z
|
||||
- ./parseAccountsDetails.sh:/opt/parseAccountsDetails.sh:Z
|
||||
- accounts-volume:/shared
|
||||
depends_on:
|
||||
contract-repo-deployer:
|
||||
condition: service_completed_successfully
|
||||
@ -213,4 +218,7 @@ services:
|
||||
- redis
|
||||
- foundry
|
||||
networks:
|
||||
- simulation
|
||||
- simulation
|
||||
|
||||
volumes:
|
||||
accounts-volume:
|
23
parseAccountsDetails.sh
Normal file
23
parseAccountsDetails.sh
Normal 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]}
|
33
run_nwaku.sh
33
run_nwaku.sh
@ -1,7 +1,9 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# Install bind-tools package used for domainname resolution
|
||||
apk add bind-tools
|
||||
apk add jq
|
||||
apk add bash
|
||||
|
||||
if test -f .env; then
|
||||
echo "Using .env file"
|
||||
@ -33,18 +35,35 @@ else
|
||||
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
|
||||
echo "$RLN_CREDENTIAL_PATH already exists. Use it instead of creating a new one."
|
||||
else
|
||||
|
||||
wait_time=$((RANDOM % 400))
|
||||
echo "Waiting $wait_time seconds before generating RLN keystore to avoid collision with other nodes."
|
||||
sleep $wait_time;
|
||||
val=$(/bin/bash ./opt/parseAccountsDetails.sh $INDEX)
|
||||
echo $val
|
||||
|
||||
echo "Generating RLN keystore"
|
||||
/usr/bin/wakunode generateRlnKeystore \
|
||||
--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-cred-path=$RLN_CREDENTIAL_PATH \
|
||||
--rln-relay-cred-password=$RLN_CREDENTIAL_PASSWORD \
|
||||
@ -52,8 +71,6 @@ else
|
||||
--execute
|
||||
fi
|
||||
|
||||
IP=$(ip a | grep "inet " | grep -Fv 127.0.0.1 | sed 's/.*inet \([^/]*\).*/\1/')
|
||||
|
||||
echo "I am a nwaku node"
|
||||
|
||||
# Get an unique node index based on the container's IP
|
||||
|
Loading…
x
Reference in New Issue
Block a user