diff --git a/docker-compose.yml b/docker-compose.yml index 60aa637..4f5f4d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,10 +25,9 @@ services: --allow-origin=* --block-time=12 --silent - --config-out=anvil-config.txt + --config-out=/shared/anvil-config.txt volumes: - privatekeys-volume:/shared - - ./getPrivateKeys.sh:/getPrivateKeys.sh networks: - simulation diff --git a/getPrivateKeys.sh b/getPrivateKeys.sh deleted file mode 100644 index 3e2576c..0000000 --- a/getPrivateKeys.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Install json parser -apk update -apk add jq - -# Read the JSON file -json_content=$(cat anvil-config.txt) - -# Extract private_keys array values using jq -private_keys=$(echo "$json_content" | jq -r '.private_keys[]') - -# Write private keys to a new file for easier indexing -echo "Writing private keys to file" -echo "$private_keys" > /shared/private-keys.txt \ No newline at end of file diff --git a/run_nwaku.sh b/run_nwaku.sh index d15bba4..05114be 100755 --- a/run_nwaku.sh +++ b/run_nwaku.sh @@ -1,7 +1,8 @@ -#!/bin/sh +#!/bin/bash -# Install bind-tools package used for domainname resolution +# Install bind-tools package used for domainname resolution and jq for json parsing apk add bind-tools +apk add jq if test -f .env; then echo "Using .env file" @@ -38,6 +39,12 @@ fi #Function to get the index of the container and use it to retrieve a private key to be used to generate the keystore get_private_key(){ + # Read the JSON file + json_content=$(cat /shared/anvil-config.txt) + + # Extract private_keys json array using jq + private_keys=$(echo "$json_content" | jq -r '.private_keys[]') + # get the service specified in the docker-compose.yml # by a reverse DNS lookup on the IP SERVICE=`dig -x $IP +short | cut -d'_' -f2` @@ -49,9 +56,17 @@ get_private_key(){ # extract the replica number from the same PTR entry INDEX=`dig -x $IP +short | sed 's/.*_\([0-9]*\)\..*/\1/'` - # get the line in the file corresponding to index - key=$(sed -n "${INDEX}p" /shared/private-keys.txt) - echo $key + # iterate through list of private keys and get the one corresponding to the container index + # we need to iterate because array objects cannot be used in /bin/ash (Alpine) and a separate script would need to be called to use bash + current_index=1 + for key in $private_keys + do + if [ $current_index -eq $INDEX ]; then + echo $key + break + fi + current_index=$((current_index+1)) + done } if test -f .$RLN_CREDENTIAL_PATH; then @@ -60,12 +75,14 @@ else private_key="$(get_private_key)" echo "Private key: $private_key" + 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-contract-address=$RLN_CONTRACT_ADDRESS \ --rln-relay-cred-path=$RLN_CREDENTIAL_PATH \ --rln-relay-cred-password=$RLN_CREDENTIAL_PASSWORD \ + --log-level=INFO \ --execute fi @@ -102,7 +119,7 @@ exec /usr/bin/wakunode\ --dns-discovery=true\ --discv5-discovery=true\ --discv5-enr-auto-update=True\ - --log-level=INFO\ + --log-level=DEBUG\ --metrics-server=True\ --metrics-server-address=0.0.0.0\ --discv5-bootstrap-node=${BOOTSTRAP_ENR}\