From c488d2031d85cb08ac14067713872fb2f3decb3a Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 12 Oct 2023 16:45:14 +0530 Subject: [PATCH] Setup ipld-eth-server to run in-process Nitro node --- .../docker-compose-ipld-eth-server.yml | 22 +++++++ app/data/config/ipld-eth-server/entrypoint.sh | 57 +++++++++++++++++++ app/data/stacks/fixturenet-payments/stack.yml | 3 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100755 app/data/config/ipld-eth-server/entrypoint.sh diff --git a/app/data/compose/docker-compose-ipld-eth-server.yml b/app/data/compose/docker-compose-ipld-eth-server.yml index a408dff1..ca5d0e02 100644 --- a/app/data/compose/docker-compose-ipld-eth-server.yml +++ b/app/data/compose/docker-compose-ipld-eth-server.yml @@ -5,6 +5,9 @@ services: depends_on: ipld-eth-db: condition: service_healthy + # Wait for Nitro contracts to be deployed + nitro-contracts: + condition: service_completed_successfully image: cerc/ipld-eth-server:local environment: SERVER_HTTP_PATH: 0.0.0.0:8081 @@ -27,18 +30,37 @@ services: PROM_HTTP_PORT: "8090" LOG_LEVEL: "debug" CERC_REMOTE_DEBUG: ${CERC_REMOTE_DEBUG:-true} + NITRO_PK: ${CERC_NITRO_PK:-2d999770f7b5d49b694080f987b82bbc9fc9ac2b4dcc10b0f8aba7d700f69c6d} + NITRO_CHAIN_PK: ${CERC_NITRO_CHAIN_PK:-570b909da9669b2f35a0b1ac70b8358516d55ae1b5b3710e95e9a94395090597} + NITRO_CHAIN_URL: ${CERC_NITRO_CHAIN_URL:-ws://fixturenet-eth-geth-1:8546} + NITRO_USE_DURABLE_STORE: ${CERC_NITRO_USE_DURABLE_STORE:-false} + NITRO_DURABLE_STORE_FOLDER: ${CERC_NITRO_DURABLE_STORE_FOLDER:-/app/data/nitro-store} + CERC_NA_ADDRESS: ${CERC_NA_ADDRESS} + CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS} + CERC_CA_ADDRESS: ${CERC_CA_ADDRESS} + entrypoint: ["bash", "-c", "/app/entrypoint.sh"] volumes: - type: bind source: ../config/ipld-eth-server/chain.json target: /tmp/chain.json + - eth_server_nitro_data:/app/data + - nitro_deployment:/app/deployment + - ../config/ipld-eth-server/entrypoint.sh:/app/entrypoint.sh ports: - "8081" - "8082" - "8090" - "40000" + - "3005" + - "4005:4005" + - "5005:5005" healthcheck: test: ["CMD", "nc", "-v", "localhost", "8081"] interval: 20s timeout: 5s retries: 15 start_period: 5s + +volumes: + eth_server_nitro_data: + nitro_deployment: diff --git a/app/data/config/ipld-eth-server/entrypoint.sh b/app/data/config/ipld-eth-server/entrypoint.sh new file mode 100755 index 00000000..92422ce1 --- /dev/null +++ b/app/data/config/ipld-eth-server/entrypoint.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +nitro_addresses_file="/app/deployment/nitro-addresses.json" + +# Check if CERC_NA_ADDRESS environment variable is set +if [ -n "$CERC_NA_ADDRESS" ]; then + echo "CERC_NA_ADDRESS is set to '$CERC_NA_ADDRESS'" + echo "CERC_VPA_ADDRESS is set to '$CERC_VPA_ADDRESS'" + echo "CERC_CA_ADDRESS is set to '$CERC_CA_ADDRESS'" + echo "Using the above Nitro addresses" + + export NITRO_NA_ADDRESS=${CERC_NA_ADDRESS} + export NITRO_VPA_ADDRESS=${CERC_VPA_ADDRESS} + export NITRO_CA_ADDRESS=${CERC_CA_ADDRESS} +elif [ -f ${nitro_addresses_file} ]; then + echo "Reading Nitro addresses from ${nitro_addresses_file}" + + export NITRO_NA_ADDRESS=$(jq -r '.nitroAdjudicatorAddress' ${nitro_addresses_file}) + export NITRO_VPA_ADDRESS=$(jq -r '.virtualPaymentAppAddress' ${nitro_addresses_file}) + export NITRO_CA_ADDRESS=$(jq -r '.consensusAppAddress' ${nitro_addresses_file}) +else + echo "File ${nitro_addresses_file} not found" + exit 1 +fi + +# Wait till chain endpoint is available +retry_interval=5 +while true; do + # Assuming NITRO_CHAIN_URL is of format ://host:port + ws_host=$(echo "$NITRO_CHAIN_URL" | awk -F '://' '{print $2}' | cut -d ':' -f 1) + ws_port=$(echo "$NITRO_CHAIN_URL" | awk -F '://' '{print $2}' | cut -d ':' -f 2) + nc -z -w 1 "$ws_host" "$ws_port" + + if [ $? -eq 0 ]; then + echo "Chain endpoint is available" + break + fi + + echo "Chain endpoint not yet available, retrying in $retry_interval seconds..." + sleep $retry_interval +done + +echo "Beginning the ipld-eth-server process" + +START_CMD="./ipld-eth-server" +if [ "true" == "$CERC_REMOTE_DEBUG" ] && [ -x "/usr/local/bin/dlv" ]; then + START_CMD="/usr/local/bin/dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec `pwd`/ipld-eth-server --continue --" +fi + +echo running: $START_CMD ${VDB_COMMAND} --config=`pwd`/config.toml +$START_CMD ${VDB_COMMAND} --config=`pwd`/config.toml +rv=$? + +if [ $rv != 0 ]; then + echo "ipld-eth-server startup failed" + exit 1 +fi \ No newline at end of file diff --git a/app/data/stacks/fixturenet-payments/stack.yml b/app/data/stacks/fixturenet-payments/stack.yml index ec52b577..3a0050af 100644 --- a/app/data/stacks/fixturenet-payments/stack.yml +++ b/app/data/stacks/fixturenet-payments/stack.yml @@ -6,7 +6,8 @@ repos: - git.vdb.to/cerc-io/go-ethereum@v1.11.6-statediff-v5 - git.vdb.to/cerc-io/lighthouse - git.vdb.to/cerc-io/ipld-eth-db@v5 - - git.vdb.to/cerc-io/ipld-eth-server@v1.11.6-statediff-v5 + # - git.vdb.to/cerc-io/ipld-eth-server@v1.11.6-statediff-v5 + - git.vdb.to/deep-stack/ipld-eth-server@pm-integrate-go-nitro # nitro repos - github.com/cerc-io/ts-nitro@v0.1.13 - github.com/cerc-io/go-nitro@v0.1.1-ts-port-0.1.5