From 2659b8739085d854c2bb351f31848f29b3da5fb1 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 20 Feb 2024 18:00:45 +0530 Subject: [PATCH] Setup three watchers running in consensus --- ...ocker-compose-watcher-mobymask-v3-demo.yml | 76 ++++++++++++++++++- .../watcher-mobymask-v3-demo/start-server.sh | 11 ++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/stack_orchestrator/data/compose/docker-compose-watcher-mobymask-v3-demo.yml b/stack_orchestrator/data/compose/docker-compose-watcher-mobymask-v3-demo.yml index 3876ab23..5bb5f03a 100644 --- a/stack_orchestrator/data/compose/docker-compose-watcher-mobymask-v3-demo.yml +++ b/stack_orchestrator/data/compose/docker-compose-watcher-mobymask-v3-demo.yml @@ -41,7 +41,7 @@ services: extra_hosts: - "host.docker.internal:host-gateway" - # Starts the MobyMask v3 watcher server + # Starts a MobyMask v3 watcher server #1 mobymask-watcher-1-server: image: cerc/watcher-mobymask-v3:local restart: unless-stopped @@ -81,6 +81,80 @@ services: extra_hosts: - "host.docker.internal:host-gateway" + # Starts a MobyMask v3 watcher server #2 + mobymask-watcher-2-server: + image: cerc/watcher-mobymask-v3:local + restart: unless-stopped + depends_on: + mobymask-watcher-1-server: + condition: service_healthy + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_WATCHER_INDEX: 2 + CERC_ETH_RPC_QUERY_ENDPOINT: ${CERC_ETH_RPC_QUERY_ENDPOINT} + CERC_ETH_RPC_MUTATION_ENDPOINT: ${CERC_ETH_RPC_MUTATION_ENDPOINT} + CERC_NITRO_CHAIN_URL: ${CERC_NITRO_CHAIN_URL} + command: ["bash", "./start-server.sh"] + volumes: + - ../config/watcher-mobymask-v3-demo/watcher-config-template.toml:/app/environments/watcher-config-template.toml + - ../config/watcher-mobymask-v3-demo/watcher-config-rates.toml:/app/environments/rates.toml + - ../config/watcher-mobymask-v3-demo/local/keys:/app/keys + - ../config/watcher-mobymask-v3-demo/start-server.sh:/app/start-server.sh + - watcher_nitro_data:/app/out/nitro-db + - nitro_deployment:/nitro + - mobymask_deployment:/server + # Expose GQL, metrics and relay node ports + ports: + - "3001" + - "9001" + - "9090" + healthcheck: + test: ["CMD", "busybox", "nc", "localhost", "9090"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 5s + extra_hosts: + - "host.docker.internal:host-gateway" + + # Starts a MobyMask v3 watcher server #3 + mobymask-watcher-3-server: + image: cerc/watcher-mobymask-v3:local + restart: unless-stopped + depends_on: + mobymask-watcher-1-server: + condition: service_healthy + mobymask-watcher-2-server: + condition: service_healthy + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_WATCHER_INDEX: 3 + CERC_ETH_RPC_QUERY_ENDPOINT: ${CERC_ETH_RPC_QUERY_ENDPOINT} + CERC_ETH_RPC_MUTATION_ENDPOINT: ${CERC_ETH_RPC_MUTATION_ENDPOINT} + CERC_NITRO_CHAIN_URL: ${CERC_NITRO_CHAIN_URL} + command: ["bash", "./start-server.sh"] + volumes: + - ../config/watcher-mobymask-v3-demo/watcher-config-template.toml:/app/environments/watcher-config-template.toml + - ../config/watcher-mobymask-v3-demo/watcher-config-rates.toml:/app/environments/rates.toml + - ../config/watcher-mobymask-v3-demo/local/keys:/app/keys + - ../config/watcher-mobymask-v3-demo/start-server.sh:/app/start-server.sh + - watcher_nitro_data:/app/out/nitro-db + - nitro_deployment:/nitro + - mobymask_deployment:/server + # Expose GQL, metrics and relay node ports + ports: + - "3001" + - "9001" + - "9090" + healthcheck: + test: ["CMD", "busybox", "nc", "localhost", "9090"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 5s + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: mobymask_watcher_db_data: mobymask_deployment: diff --git a/stack_orchestrator/data/config/watcher-mobymask-v3-demo/start-server.sh b/stack_orchestrator/data/config/watcher-mobymask-v3-demo/start-server.sh index 96a982bf..978911c0 100755 --- a/stack_orchestrator/data/config/watcher-mobymask-v3-demo/start-server.sh +++ b/stack_orchestrator/data/config/watcher-mobymask-v3-demo/start-server.sh @@ -15,7 +15,7 @@ echo "Using Nitro chain URL ${CERC_NITRO_CHAIN_URL}" WATCHER_DB="mobymask-watcher-${CERC_WATCHER_INDEX}" # Use the docker container's host IP for relay multiaddr in peer config -CERC_RELAY_MULTIADDR="/dns4/mobymask-watcher-${CERC_WATCHER_INDEX}-server/tcp/9090/ws/p2p/$(jq -r '.relayPeerId.id' /app/keys/watcher-${CERC_WATCHER_INDEX}.json)" +CERC_RELAY_MULTIADDR="/dns4/mobymask-watcher-${CERC_WATCHER_INDEX}-server/tcp/9090/ws/p2p/$(jq -r '.relayPeerId.id' ${watcher_keys_dir}/watcher-${CERC_WATCHER_INDEX}.json)" # Assign deployed contract address from server config (created by mobymask container after deploying contract) CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"') @@ -85,8 +85,15 @@ watcher_parties_json=$(printf '%s\n' "${watcher_parties[@]}" | jq -s .) echo "$watcher_parties_json" > "${WATCHER_PARTY_PEERS_FILE}" echo "Watcher party peers exported to ${WATCHER_PARTY_PEERS_FILE}" -# TODO: Configure +# Configure relay peers for watcher 2 and 3 CERC_RELAY_PEERS=[] +if [ "${CERC_WATCHER_INDEX}" = "2" ]; then + # 2 -> 1 + CERC_RELAY_PEERS="['/dns4/mobymask-watcher-1-server/tcp/9090/ws/p2p/$(jq -r '.relayPeerId.id' ${watcher_keys_dir}/watcher-1.json)']" +elif [ "${CERC_WATCHER_INDEX}" = "3" ]; then + # 3 -> 1, 2 + CERC_RELAY_PEERS="['/dns4/mobymask-watcher-1-server/tcp/9090/ws/p2p/$(jq -r '.relayPeerId.id' ${watcher_keys_dir}/watcher-1.json)', '/dns4/mobymask-watcher-2-server/tcp/9090/ws/p2p/$(jq -r '.relayPeerId.id' ${watcher_keys_dir}/watcher-2.json)']" +fi # Read in the config template TOML file and modify it WATCHER_CONFIG_TEMPLATE=$(cat environments/watcher-config-template.toml)