From e223db7599435574e2ca2499705f60d55a555b92 Mon Sep 17 00:00:00 2001 From: nabarun Date: Thu, 6 Apr 2023 11:55:49 +0530 Subject: [PATCH] Add code comments --- app/data/compose/docker-compose-mobymask-app.yml | 3 +++ app/data/compose/docker-compose-peer-test-app.yml | 1 + app/data/compose/docker-compose-watcher-mobymask-v2.yml | 6 ++++++ .../watcher-mobymask-v2/deploy-and-generate-invite.sh | 3 ++- .../config/watcher-mobymask-v2/mobymask-app-start.sh | 2 ++ app/data/config/watcher-mobymask-v2/mobymask-params.env | 3 +++ app/data/config/watcher-mobymask-v2/start-server.sh | 9 ++++++--- app/data/config/watcher-mobymask-v2/test-app-start.sh | 2 +- 8 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/data/compose/docker-compose-mobymask-app.yml b/app/data/compose/docker-compose-mobymask-app.yml index 818c158f..63c2ef8f 100644 --- a/app/data/compose/docker-compose-mobymask-app.yml +++ b/app/data/compose/docker-compose-mobymask-app.yml @@ -1,10 +1,13 @@ version: '3.2' services: + # Builds and serves the mobymask react-app mobymask-app: image: cerc/mobymask-ui:local env_file: - ../config/watcher-mobymask-v2/mobymask-params.env + # Waits for watcher server to be up before app build + # Required when running with watcher stack to get deployed contract address command: - sh - -c diff --git a/app/data/compose/docker-compose-peer-test-app.yml b/app/data/compose/docker-compose-peer-test-app.yml index 172633e8..3ddbd308 100644 --- a/app/data/compose/docker-compose-peer-test-app.yml +++ b/app/data/compose/docker-compose-peer-test-app.yml @@ -2,6 +2,7 @@ version: '3.2' services: peer-test-app: + # Builds and serves the peer-test react-app image: cerc/react-peer:local working_dir: /app/packages/test-app env_file: diff --git a/app/data/compose/docker-compose-watcher-mobymask-v2.yml b/app/data/compose/docker-compose-watcher-mobymask-v2.yml index 5397e049..3158737a 100644 --- a/app/data/compose/docker-compose-watcher-mobymask-v2.yml +++ b/app/data/compose/docker-compose-watcher-mobymask-v2.yml @@ -1,6 +1,7 @@ version: '3.2' services: + # Starts the postgres database for watcher mobymask-watcher-db: restart: unless-stopped image: postgres:14-alpine @@ -21,6 +22,8 @@ services: retries: 15 start_period: 10s + # Deploys mobymask contract and generates an invite link + # Deployment is skipped if DEPLOYED_CONTRACT env is already set mobymask: image: cerc/mobymask:local working_dir: /app/packages/server @@ -29,6 +32,7 @@ services: - ../config/watcher-mobymask-v2/mobymask-params.env environment: - ENV=PROD + # Waits for L2 Optimism Geth and Node servers to be up before deploying contract command: - sh - -c @@ -45,6 +49,7 @@ services: extra_hosts: - "host.docker.internal:host-gateway" + # Starts the mobymask-v2-watcher server mobymask-watcher-server: restart: unless-stopped depends_on: @@ -65,6 +70,7 @@ services: - ../config/watcher-mobymask-v2/start-server.sh:/app/packages/mobymask-v2-watcher/start-server.sh - mobymask_deployment:/server - fixturenet_geth_accounts:/geth-accounts:ro + # Expose GQL, metrics and relay node ports ports: - "0.0.0.0:3001:3001" - "0.0.0.0:9001:9001" diff --git a/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh b/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh index 97d362ee..743b1525 100755 --- a/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh +++ b/app/data/config/watcher-mobymask-v2/deploy-and-generate-invite.sh @@ -22,6 +22,7 @@ jq --arg rpcUrl "$L2_GETH_RPC" '.rpcUrl = $rpcUrl' secrets.json > secrets_update export RPC_URL="${L2_GETH_RPC}" +# Check if DEPLOYED_CONTRACT environment variable set to skip contract deployment if [[ -n "$DEPLOYED_CONTRACT" ]]; then echo "DEPLOYED_CONTRACT is set to '$DEPLOYED_CONTRACT'" echo "Exiting without deploying contract" @@ -46,7 +47,7 @@ if [ -f ./config.json ]; then fi fi -# Wait until balance for deployer account is reflected +# Wait until balance for deployer account is updated cd ../hardhat while true; do ACCOUNT_BALANCE=$(yarn balance --network optimism "$PRIVATE_KEY_DEPLOYER" | grep ETH) diff --git a/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh b/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh index e84fa3e5..680e2e8a 100755 --- a/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh +++ b/app/data/config/watcher-mobymask-v2/mobymask-app-start.sh @@ -4,6 +4,7 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi +# Use config from mounted volume if available (when running web-app along with watcher stack) if [ -f /server/config.json ]; then echo "Merging config for deployed contract from mounted volume" # Merging config files to get deployed contract address @@ -11,6 +12,7 @@ if [ -f /server/config.json ]; then else echo "Setting deployed contract details from env" + # Set config values from environment variables jq --arg address "$DEPLOYED_CONTRACT" \ --argjson chainId $CHAIN_ID \ --argjson relayNodes "$RELAY_NODES" \ diff --git a/app/data/config/watcher-mobymask-v2/mobymask-params.env b/app/data/config/watcher-mobymask-v2/mobymask-params.env index 8c6050fd..890c183b 100644 --- a/app/data/config/watcher-mobymask-v2/mobymask-params.env +++ b/app/data/config/watcher-mobymask-v2/mobymask-params.env @@ -7,5 +7,8 @@ APP_WATCHER_URL="http://localhost:3001" # mobymask-app will use this contract address in config if run separately DEPLOYED_CONTRACT= +# Chain ID is used by mobymask web-app for txs CHAIN_ID=42069 + +# Set relay nodes to be used by web-apps RELAY_NODES=["/ip4/127.0.0.1/tcp/9090/ws/p2p/12D3KooWSPCsVkHVyLQoCqhu2YRPvvM7o6r6NRYyLM5zeA6Uig5t"] diff --git a/app/data/config/watcher-mobymask-v2/start-server.sh b/app/data/config/watcher-mobymask-v2/start-server.sh index 569d74a0..4030e522 100755 --- a/app/data/config/watcher-mobymask-v2/start-server.sh +++ b/app/data/config/watcher-mobymask-v2/start-server.sh @@ -6,10 +6,11 @@ fi echo "Using L2 RPC endpoint ${L2_GETH_RPC}" +# Use contract address from environment variable or set from config.json in mounted volume if [ -n "$DEPLOYED_CONTRACT" ]; then CONTRACT_ADDRESS="${DEPLOYED_CONTRACT}" else - # Assign deployed contract address from server config + # 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 @@ -21,16 +22,18 @@ else echo "Using PRIVATE_KEY_PEER from env" fi +# Set private key and contract address for watcher peer txs to L2 only if PRIVATE_KEY_PEER variable is set if [ -n "$PRIVATE_KEY_PEER" ]; then - # Read in the original TOML file and modify it + # Read in config template TOML file and modify it CONTENT=$(cat environments/watcher-config-template.toml) NEW_CONTENT=$(echo "$CONTENT" | sed -E "/\[metrics\]/i \\\n\n [server.p2p.peer.l2TxConfig]\n privateKey = \"${PRIVATE_KEY_PEER}\"\n contractAddress = \"${CONTRACT_ADDRESS}\"\n") - # Write the modified content to a new file + # Write the modified content to a watcher config file echo "$NEW_CONTENT" > environments/local.toml sed -i 's|REPLACE_WITH_L2_GETH_RPC_ENDPOINT|'"${L2_GETH_RPC}"'|' environments/local.toml else + # Copy template config to watcher config without setting params for peer L2 txs cp environments/watcher-config-template.toml environments/local.toml fi diff --git a/app/data/config/watcher-mobymask-v2/test-app-start.sh b/app/data/config/watcher-mobymask-v2/test-app-start.sh index 6c76ef4b..de6ccc7c 100755 --- a/app/data/config/watcher-mobymask-v2/test-app-start.sh +++ b/app/data/config/watcher-mobymask-v2/test-app-start.sh @@ -4,7 +4,7 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi - +# Set relay nodes in config from RELAY_NODES environment variable jq --argjson relayNodes "$RELAY_NODES" \ '.relayNodes = $relayNodes' \ ./src/test-app-config.json > ./src/config.json