each nwaku service uses its index to retrieve a private key for keystore

This commit is contained in:
stubbsta 2024-05-24 12:04:57 +02:00
parent 00e8d65ba8
commit 0a7a3120ab
No known key found for this signature in database
3 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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 \