From 192e6feee348e60ff2b75223d045a0fb2c9ff80d Mon Sep 17 00:00:00 2001 From: Isha Venikar <145848618+IshaVenikar@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:18:24 +0530 Subject: [PATCH] Update nitro-node stack to use public IP from config (#3) * Rename nitro-node stack * Add flag for setting public IP * Log values in the nitro-node script * Add command to install nitro-rpc-client * Fix directory name * Set default value for public IP --- README.md | 2 +- .../compose/docker-compose-go-nitro.yml | 1 + .../docker-compose-nitro-contracts.yml | 3 +-- .../docker-compose-nitro-rpc-client.yml | 10 ++++---- .../config/go-nitro/run-nitro-node.sh | 24 ++++++++++++++++++- .../config/nitro-contracts/deploy.sh | 2 +- .../cerc-nitro-rpc-client/Dockerfile | 3 +++ .../go-nitro => stacks/nitro-node}/README.md | 21 ++++++++-------- .../go-nitro => stacks/nitro-node}/stack.yml | 2 -- 9 files changed, 46 insertions(+), 22 deletions(-) rename stack-orchestrator/{stack/go-nitro => stacks/nitro-node}/README.md (80%) rename stack-orchestrator/{stack/go-nitro => stacks/nitro-node}/stack.yml (84%) diff --git a/README.md b/README.md index 4cc9f63..305267f 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# nitro-stack \ No newline at end of file +# nitro-stack diff --git a/stack-orchestrator/compose/docker-compose-go-nitro.yml b/stack-orchestrator/compose/docker-compose-go-nitro.yml index fd9a46a..7c20600 100644 --- a/stack-orchestrator/compose/docker-compose-go-nitro.yml +++ b/stack-orchestrator/compose/docker-compose-go-nitro.yml @@ -15,6 +15,7 @@ services: CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS} CERC_CA_ADDRESS: ${CERC_CA_ADDRESS} CERC_BOOT_PEERS: ${CERC_BOOT_PEERS} + CERC_PUBLIC_IP: ${CERC_PUBLIC_IP:-127.0.0.1} entrypoint: ["bash", "-c", "/app/run-nitro-node.sh"] volumes: - ../config/go-nitro/run-nitro-node.sh:/app/run-nitro-node.sh diff --git a/stack-orchestrator/compose/docker-compose-nitro-contracts.yml b/stack-orchestrator/compose/docker-compose-nitro-contracts.yml index 09d6d7d..5af8d26 100644 --- a/stack-orchestrator/compose/docker-compose-nitro-contracts.yml +++ b/stack-orchestrator/compose/docker-compose-nitro-contracts.yml @@ -15,8 +15,7 @@ services: CERC_OPTIMISM_DEPLOYER_PK: ${CERC_GETH_DEPLOYER_PK} CERC_DISABLE_DETERMINISTIC_DEPLOYMENT: true volumes: - - ../config/nitro-contracts/deploy.sh:/app/deploy.sh + - ../config/nitro-contracts/deploy.sh:/app/deploy.sh command: ["bash", "-c", "/app/deploy.sh"] extra_hosts: - "host.docker.internal:host-gateway" - diff --git a/stack-orchestrator/compose/docker-compose-nitro-rpc-client.yml b/stack-orchestrator/compose/docker-compose-nitro-rpc-client.yml index f05895e..a5ceac9 100644 --- a/stack-orchestrator/compose/docker-compose-nitro-rpc-client.yml +++ b/stack-orchestrator/compose/docker-compose-nitro-rpc-client.yml @@ -1,8 +1,8 @@ name: nitro-rpc-client services: - nitro-rpc-client: - image: cerc/nitro-rpc-client:local - hostname: nitro-rpc-client - restart: on-failure - command: ["bash", "-c", "tail -f /dev/null"] + nitro-rpc-client: + image: cerc/nitro-rpc-client:local + hostname: nitro-rpc-client + restart: on-failure + command: ["bash", "-c", "tail -f /dev/null"] diff --git a/stack-orchestrator/config/go-nitro/run-nitro-node.sh b/stack-orchestrator/config/go-nitro/run-nitro-node.sh index 819c293..ab98e52 100755 --- a/stack-orchestrator/config/go-nitro/run-nitro-node.sh +++ b/stack-orchestrator/config/go-nitro/run-nitro-node.sh @@ -5,4 +5,26 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -./nitro -chainurl ${CERC_NITRO_CHAIN_URL} -msgport ${CERC_NITRO_MSG_PORT} -rpcport ${CERC_NITRO_RPC_PORT} -pk ${CERC_NITRO_PK} -chainpk ${CERC_NITRO_CHAIN_PK} -naaddress ${CERC_NA_ADDRESS} -vpaaddress ${CERC_VPA_ADDRESS} -caaddress ${CERC_CA_ADDRESS} +if [ -z "$CERC_NA_ADDRESS" ]; then + echo "Error: NA_ADDRESS is not present" + exit 1 +fi + +if [ -z "$CERC_VPA_ADDRESS" ]; then + echo "Error: VPA_ADDRESS is not present" + exit 1 +fi + +if [ -z "$CERC_CA_ADDRESS" ]; then + echo "Error: CA_ADDRESS is not present" + exit 1 +fi + +echo "CERC_NITRO_CHAIN_URL: ${CERC_NITRO_CHAIN_URL}" +echo "CERC_NITRO_MSG_PORT: ${CERC_NITRO_MSG_PORT}" +echo "CERC_NITRO_RPC_PORT: ${CERC_NITRO_RPC_PORT}" +echo "CERC_NITRO_PK: ${CERC_NITRO_PK}" +echo "CERC_NITRO_CHAIN_PK: ${CERC_NITRO_CHAIN_PK}" +echo "CERC_PUBLIC_IP: ${CERC_PUBLIC_IP}" + +./nitro -chainurl ${CERC_NITRO_CHAIN_URL} -msgport ${CERC_NITRO_MSG_PORT} -rpcport ${CERC_NITRO_RPC_PORT} -pk ${CERC_NITRO_PK} -chainpk ${CERC_NITRO_CHAIN_PK} -naaddress ${CERC_NA_ADDRESS} -vpaaddress ${CERC_VPA_ADDRESS} -caaddress ${CERC_CA_ADDRESS} -publicip ${CERC_PUBLIC_IP} diff --git a/stack-orchestrator/config/nitro-contracts/deploy.sh b/stack-orchestrator/config/nitro-contracts/deploy.sh index 42bb9ea..e99d12a 100755 --- a/stack-orchestrator/config/nitro-contracts/deploy.sh +++ b/stack-orchestrator/config/nitro-contracts/deploy.sh @@ -25,4 +25,4 @@ export OPTIMISM_DEPLOYER_PK=$GETH_DEPLOYER_PK export DISABLE_DETERMINISTIC_DEPLOYMENT=true yarn contracts:deploy-geth -yarn contracts:deploy-optimism \ No newline at end of file +yarn contracts:deploy-optimism diff --git a/stack-orchestrator/container-build/cerc-nitro-rpc-client/Dockerfile b/stack-orchestrator/container-build/cerc-nitro-rpc-client/Dockerfile index 26f722d..1ef8a0e 100644 --- a/stack-orchestrator/container-build/cerc-nitro-rpc-client/Dockerfile +++ b/stack-orchestrator/container-build/cerc-nitro-rpc-client/Dockerfile @@ -9,4 +9,7 @@ COPY . . RUN echo "Installing dependencies" && \ yarn & yarn build +RUN echo "Installing nitro-rpc-client package" && \ + npm install -g /app/packages/nitro-rpc-client + WORKDIR /app/packages/nitro-rpc-client diff --git a/stack-orchestrator/stack/go-nitro/README.md b/stack-orchestrator/stacks/nitro-node/README.md similarity index 80% rename from stack-orchestrator/stack/go-nitro/README.md rename to stack-orchestrator/stacks/nitro-node/README.md index 28cf34f..7843a10 100644 --- a/stack-orchestrator/stack/go-nitro/README.md +++ b/stack-orchestrator/stacks/nitro-node/README.md @@ -11,14 +11,15 @@ - Clone required repositories ```bash - laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stack/go-nitro setup-repositories + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node setup-repositories ``` + Note: Replace path to nitro stack with actual path - Build the container image ```bash - laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stack/go-nitro build-containers + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node build-containers ``` ## Create a deployment @@ -26,7 +27,7 @@ - Create a spec file ```bash - laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stack/go-nitro deploy init --output go-nitro-spec.yml + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy init --output nitro-node-spec.yml ``` - TODO: Edit `network` in the spec file to map container ports to host ports as required: @@ -41,14 +42,14 @@ ``` - Create deployment - + ```bash - laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stack/go-nitro deploy create --spec-file go-nitro-spec.yml --deployment-dir go-nitro-deployment + laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file nitro-node-spec.yml --deployment-dir nitro-node-deployment ``` ## Configuration -* Inside the `go-nitro-deployment` deployment directory, open `config.env` file and set following env variables: +- Inside the `nitro-node-deployment` deployment directory, open `config.env` file and set following env variables: ```bash # URL endpoint of the chain (Example: ws://host.docker.internal:8545) @@ -56,16 +57,16 @@ # Private key of account to be used by Nitro node (derived address is used as Nitro address) CERC_NITRO_PK= - + # Private key of the account on chain that is used for funding channels in Nitro node CERC_NITRO_CHAIN_PK= - + # Port to be used by P2P message service (Example: 3009) CERC_NITRO_MSG_PORT= # Port to be used by RPC server (Example: 4009) CERC_NITRO_RPC_PORT=4009 - + # Optional # Contract addresses of NitroAdjudicator, VirtualPaymentApp and ConsensusApp # TODO: Contracts are deployed if addresses are not set @@ -77,5 +78,5 @@ ## Start the deployment ```bash -laconic-so deployment --dir go-nitro-deployment start +laconic-so deployment --dir nitro-node-deployment start ``` diff --git a/stack-orchestrator/stack/go-nitro/stack.yml b/stack-orchestrator/stacks/nitro-node/stack.yml similarity index 84% rename from stack-orchestrator/stack/go-nitro/stack.yml rename to stack-orchestrator/stacks/nitro-node/stack.yml index 02f4b23..068b95a 100644 --- a/stack-orchestrator/stack/go-nitro/stack.yml +++ b/stack-orchestrator/stacks/nitro-node/stack.yml @@ -4,10 +4,8 @@ description: "Stack to demonstrate payments between various services" repos: - github.com/cerc-io/go-nitro containers: - - cerc/nitro-contracts - cerc/go-nitro # - cerc/nitro-rpc-client pods: - go-nitro - - nitro-contracts # - nitro-rpc-client