diff --git a/docker-compose.yml b/docker-compose.yml index 7885729..60aa637 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -77,7 +77,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 @@ -85,6 +84,7 @@ services: - '/opt/run_nwaku.sh' volumes: - ./run_nwaku.sh:/opt/run_nwaku.sh:Z + - privatekeys-volume:/shared depends_on: contract-repo-deployer: condition: service_completed_successfully diff --git a/getPrivateKeys.sh b/getPrivateKeys.sh index 3d9e7b5..3e2576c 100644 --- a/getPrivateKeys.sh +++ b/getPrivateKeys.sh @@ -10,6 +10,6 @@ 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 access +# 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 8a69e0e..fb3926c 100755 --- a/run_nwaku.sh +++ b/run_nwaku.sh @@ -33,12 +33,34 @@ else fi fi +#Function to get the index of the container and use it to retrieve a private key to generate the keystore +get_private_key(){ + IP=$(ip a | grep "inet " | grep -Fv 127.0.0.1 | sed 's/.*inet \([^/]*\).*/\1/') + + # 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/'` + + key=$(sed -n "${INDEX}p" /shared/private-keys.txt) + echo $key +} + if test -f .$RLN_CREDENTIAL_PATH; then echo "$RLN_CREDENTIAL_PATH already exists. Use it instead of creating a new one." else + private_key="$(get_private_key)" + echo "Private key: $private_key" + /usr/bin/wakunode generateRlnKeystore \ --rln-relay-eth-client-address="$RPC_URL" \ - --rln-relay-eth-private-key=$PRIVATE_KEY \ + --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 \