From adc4607fd7f504fc816b7670d7030b62b5ca908e Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 15 Sep 2023 15:05:08 +0530 Subject: [PATCH] Setup Nitro config --- .../docker-compose-watcher-mobymask-v3.yml | 9 +-- .../deploy-nitro-contracts.sh | 10 +-- .../read-nitro-contracts.sh | 18 ----- .../watcher-mobymask-v3/start-server.sh | 67 +++++++++++++++++++ .../watcher-config-rates.toml | 14 ++++ .../watcher-config-template.toml | 17 +++++ app/data/stacks/mobymask-v3/watcher.md | 7 +- 7 files changed, 114 insertions(+), 28 deletions(-) delete mode 100755 app/data/config/watcher-mobymask-v3/read-nitro-contracts.sh create mode 100755 app/data/config/watcher-mobymask-v3/start-server.sh create mode 100644 app/data/config/watcher-mobymask-v3/watcher-config-rates.toml diff --git a/app/data/compose/docker-compose-watcher-mobymask-v3.yml b/app/data/compose/docker-compose-watcher-mobymask-v3.yml index 0702c93e..655fbd82 100644 --- a/app/data/compose/docker-compose-watcher-mobymask-v3.yml +++ b/app/data/compose/docker-compose-watcher-mobymask-v3.yml @@ -81,7 +81,6 @@ services: CERC_L2_GETH_RPC: ${CERC_L2_GETH_RPC} CERC_L1_ACCOUNTS_CSV_URL: ${CERC_L1_ACCOUNTS_CSV_URL} CERC_PRIVATE_KEY_DEPLOYER: ${CERC_PRIVATE_KEY_DEPLOYER} - CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER} CERC_RELAY_PEERS: ${CERC_RELAY_PEERS} CERC_DENY_MULTIADDRS: ${CERC_DENY_MULTIADDRS} CERC_PUBSUB: ${CERC_PUBSUB} @@ -91,14 +90,16 @@ services: CERC_NA_ADDRESS: ${CERC_NA_ADDRESS} CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS} CERC_CA_ADDRESS: ${CERC_CA_ADDRESS} + CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER} + CERC_PRIVATE_KEY_NITRO: ${CERC_PRIVATE_KEY_NITRO} entrypoint: ["bash", "-c"] - command: ["./deploy-nitro-contracts.sh && ./read-nitro-contracts.sh && ./start-server.sh"] + command: ["./deploy-nitro-contracts.sh && ./start-server.sh"] volumes: - ../config/watcher-mobymask-v3/deploy-nitro-contracts.sh:/app/deploy-nitro-contracts.sh - ../config/watcher-mobymask-v3/deploy-nitro-contracts.ts:/app/deploy-nitro-contracts.ts - - ../config/watcher-mobymask-v3/read-nitro-contracts.sh:/app/read-nitro-contracts.sh - ../config/watcher-mobymask-v3/watcher-config-template.toml:/app/environments/watcher-config-template.toml - - ../config/watcher-mobymask-v2/start-server.sh:/app/start-server.sh + - ../config/watcher-mobymask-v3/watcher-config-rates.toml:/app/environments/rates.toml + - ../config/watcher-mobymask-v3/start-server.sh:/app/start-server.sh - peers_ids:/app/peers - nitro_addresses:/nitro - mobymask_deployment:/server diff --git a/app/data/config/watcher-mobymask-v3/deploy-nitro-contracts.sh b/app/data/config/watcher-mobymask-v3/deploy-nitro-contracts.sh index e22eae5c..7e575458 100755 --- a/app/data/config/watcher-mobymask-v3/deploy-nitro-contracts.sh +++ b/app/data/config/watcher-mobymask-v3/deploy-nitro-contracts.sh @@ -18,11 +18,11 @@ if [ -n "$CERC_NA_ADDRESS" ]; then echo "Using the above addresses and skipping Nitro contracts deployment" # Create the required JSON and write it to a file - nitro_addresses_json="{ - \"nitroAdjudicatorAddress\": \"$CERC_NA_ADDRESS\", - \"virtualPaymentAppAddress\": \"$CERC_VPA_ADDRESS\", - \"consensusAppAddress\": \"$CERC_CA_ADDRESS\" - }" + nitro_addresses_json=$(jq -n \ + --arg na "$CERC_NA_ADDRESS" \ + --arg vpa "$CERC_VPA_ADDRESS" \ + --arg ca "$CERC_CA_ADDRESS" \ + '.nitroAdjudicatorAddress = $na | .virtualPaymentAppAddress = $vpa | .consensusAppAddress = $ca') echo "$nitro_addresses_json" > "${NITRO_ADDRESSES_FILE_PATH}" exit diff --git a/app/data/config/watcher-mobymask-v3/read-nitro-contracts.sh b/app/data/config/watcher-mobymask-v3/read-nitro-contracts.sh deleted file mode 100755 index 93655e7c..00000000 --- a/app/data/config/watcher-mobymask-v3/read-nitro-contracts.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -set -e -if [ -n "$CERC_SCRIPT_DEBUG" ]; then - set -x -fi - -NITRO_ADDRESSES_FILE_PATH="/nitro/nitro-addresses.json" -DESTINATION_FILE_PATH="./src/nitro-addresses.json" - -# Check if the file exists -if [ -f "$NITRO_ADDRESSES_FILE_PATH" ]; then - cat "$NITRO_ADDRESSES_FILE_PATH" > "$DESTINATION_FILE_PATH" - echo "Nitro addresses set to ${DESTINATION_FILE_PATH}" -else - echo "File ${NITRO_ADDRESSES_FILE_PATH} does not exist" - exit 1 -fi diff --git a/app/data/config/watcher-mobymask-v3/start-server.sh b/app/data/config/watcher-mobymask-v3/start-server.sh new file mode 100755 index 00000000..dad426b8 --- /dev/null +++ b/app/data/config/watcher-mobymask-v3/start-server.sh @@ -0,0 +1,67 @@ +#!/bin/sh +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +CERC_L2_GETH_RPC="${CERC_L2_GETH_RPC:-${DEFAULT_CERC_L2_GETH_RPC}}" + +CERC_RELAY_PEERS="${CERC_RELAY_PEERS:-${DEFAULT_CERC_RELAY_PEERS}}" +CERC_DENY_MULTIADDRS="${CERC_DENY_MULTIADDRS:-${DEFAULT_CERC_DENY_MULTIADDRS}}" +CERC_PUBSUB="${CERC_PUBSUB:-${DEFAULT_CERC_PUBSUB}}" +CERC_RELAY_ANNOUNCE_DOMAIN="${CERC_RELAY_ANNOUNCE_DOMAIN:-${DEFAULT_CERC_RELAY_ANNOUNCE_DOMAIN}}" +CERC_ENABLE_PEER_L2_TXS="${CERC_ENABLE_PEER_L2_TXS:-${DEFAULT_CERC_ENABLE_PEER_L2_TXS}}" +CERC_DEPLOYED_CONTRACT="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_DEPLOYED_CONTRACT}}" + +NITRO_ADDRESSES_FILE_PATH="/nitro/nitro-addresses.json" +DESTINATION_FILE_PATH="./src/nitro-addresses.json" + +echo "Using L2 RPC endpoint ${CERC_L2_GETH_RPC}" + +# Use public domain for relay multiaddr in peer config if specified +# Otherwise, use the docker container's host IP +if [ -n "$CERC_RELAY_ANNOUNCE_DOMAIN" ]; then + CERC_RELAY_MULTIADDR="/dns4/${CERC_RELAY_ANNOUNCE_DOMAIN}/tcp/443/wss/p2p/$(jq -r '.id' /app/peers/relay-id.json)" +else + CERC_RELAY_MULTIADDR="/dns4/mobymask-watcher-server/tcp/9090/ws/p2p/$(jq -r '.id' /app/peers/relay-id.json)" +fi + +# Use contract address from environment variable or set from config.json in mounted volume +if [ -n "$CERC_DEPLOYED_CONTRACT" ]; then + CONTRACT_ADDRESS="${CERC_DEPLOYED_CONTRACT}" +else + # Assign deployed contract address from server config (created by mobymask container after deploying contract) + CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"') +fi + +# Copy the deployed Nitro addresses to the required path +if [ -f "$NITRO_ADDRESSES_FILE_PATH" ]; then + cat "$NITRO_ADDRESSES_FILE_PATH" > "$DESTINATION_FILE_PATH" + echo "Nitro addresses set to ${DESTINATION_FILE_PATH}" +else + echo "File ${NITRO_ADDRESSES_FILE_PATH} does not exist" + exit 1 +fi + +echo "Using CERC_PRIVATE_KEY_PEER (account with funds) from env for sending txs to L2" +echo "Using CERC_PRIVATE_KEY_NITRO from env for Nitro account" + +# Read in the config template TOML file and modify it +WATCHER_CONFIG_TEMPLATE=$(cat environments/watcher-config-template.toml) +WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \ + sed -E "s|REPLACE_WITH_CERC_RELAY_PEERS|${CERC_RELAY_PEERS}|g; \ + s|REPLACE_WITH_CERC_DENY_MULTIADDRS|${CERC_DENY_MULTIADDRS}|g; \ + s/REPLACE_WITH_CERC_PUBSUB/${CERC_PUBSUB}/g; \ + s/REPLACE_WITH_CERC_RELAY_ANNOUNCE_DOMAIN/${CERC_RELAY_ANNOUNCE_DOMAIN}/g; \ + s|REPLACE_WITH_CERC_RELAY_MULTIADDR|${CERC_RELAY_MULTIADDR}|g; \ + s/REPLACE_WITH_CERC_ENABLE_PEER_L2_TXS/${CERC_ENABLE_PEER_L2_TXS}/g; \ + s/REPLACE_WITH_CERC_PRIVATE_KEY_PEER/${CERC_PRIVATE_KEY_PEER}/g; \ + s/REPLACE_WITH_CERC_PRIVATE_KEY_NITRO/${CERC_PRIVATE_KEY_NITRO}/g; \ + s/REPLACE_WITH_CONTRACT_ADDRESS/${CONTRACT_ADDRESS}/g; \ + s|REPLACE_WITH_CERC_L2_GETH_RPC_ENDPOINT|${CERC_L2_GETH_RPC}| ") + +# Write the modified content to a new file +echo "$WATCHER_CONFIG" > environments/local.toml + +echo 'yarn server' +yarn server diff --git a/app/data/config/watcher-mobymask-v3/watcher-config-rates.toml b/app/data/config/watcher-mobymask-v3/watcher-config-rates.toml new file mode 100644 index 00000000..3dd4001f --- /dev/null +++ b/app/data/config/watcher-mobymask-v3/watcher-config-rates.toml @@ -0,0 +1,14 @@ +freeQueriesLimit = 10 + +freeQueriesList = [] + +[queries] + multiNonce = '' + _owner = '' + isRevoked = '' + isPhisher = '' + isMember = '' + +[mutations] + invoke = '' + revoke = '' diff --git a/app/data/config/watcher-mobymask-v3/watcher-config-template.toml b/app/data/config/watcher-mobymask-v3/watcher-config-template.toml index a0dd3b34..911dee74 100644 --- a/app/data/config/watcher-mobymask-v3/watcher-config-template.toml +++ b/app/data/config/watcher-mobymask-v3/watcher-config-template.toml @@ -46,6 +46,23 @@ privateKey = 'REPLACE_WITH_CERC_PRIVATE_KEY_PEER' contractAddress = 'REPLACE_WITH_CONTRACT_ADDRESS' + [server.p2p.nitro] + store = './out/nitro-db' + privateKey = 'REPLACE_WITH_CERC_PRIVATE_KEY_NITRO' + chainPrivateKey = 'REPLACE_WITH_CERC_PRIVATE_KEY_PEER' + + [server.p2p.nitro.payments] + ratesFile = './environments/rates.toml' + requestTimeoutInSecs = 10 + + [server.p2p.nitro.payments.cache] + maxAccounts = 1000 + accountTTLInSecs = 1800 + maxVouchersPerAccount = 1000 + voucherTTLInSecs = 300 + maxPaymentChannels = 10000 + paymentChannelTTLInSecs = 1800 + [metrics] host = "0.0.0.0" port = 9000 diff --git a/app/data/stacks/mobymask-v3/watcher.md b/app/data/stacks/mobymask-v3/watcher.md index 6ee069b3..8b171c0e 100644 --- a/app/data/stacks/mobymask-v3/watcher.md +++ b/app/data/stacks/mobymask-v3/watcher.md @@ -37,7 +37,6 @@ Create and update an env file to be used in the next step ([defaults](../../conf # OR # Specify the required account credentials CERC_PRIVATE_KEY_DEPLOYER= - CERC_PRIVATE_KEY_PEER= # Base URI for mobymask-app # (used for generating a root invite link after deploying the contract) @@ -65,6 +64,12 @@ Create and update an env file to be used in the next step ([defaults](../../conf CERC_NA_ADDRESS= CERC_VPA_ADDRESS= CERC_CA_ADDRESS= + + # Specify private key of a funded account for sending txs to L2 + CERC_PRIVATE_KEY_PEER= + + # Specify private key for the Nitro account + CERC_PRIVATE_KEY_NITRO= ``` * NOTE: If Optimism is running on the host machine, use `host.docker.internal` as the hostname to access the host port