Fix Nitro deployment script and add watcher container

This commit is contained in:
Prathamesh Musale 2023-09-15 12:38:31 +05:30
parent 9ccd2d7d43
commit c72070a080
11 changed files with 340 additions and 28 deletions

View File

@ -28,8 +28,7 @@ services:
image: cerc/mobymask:local image: cerc/mobymask:local
working_dir: /app/packages/server working_dir: /app/packages/server
env_file: env_file:
- ../config/watcher-mobymask-v2/optimism-params.env - ../config/watcher-mobymask-v3/mobymask-params.env
- ../config/watcher-mobymask-v2/mobymask-params.env
environment: environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
ENV: "PROD" ENV: "PROD"
@ -57,14 +56,65 @@ services:
restart: on-failure restart: on-failure
environment: environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
# working_dir: /app/packages/peer working_dir: /app/packages/peer
working_dir: /app/packages/ command: ["sh", "generate-peer-ids.sh"]
command: ["sh", "generate-peer-ids.sh && deploy-nitro-contracts.sh"]
volumes: volumes:
- ../config/watcher-mobymask-v2/generate-peer-ids.sh:/app/packages/peer/generate-peer-ids.sh - ../config/watcher-mobymask-v2/generate-peer-ids.sh:/app/packages/peer/generate-peer-ids.sh
- peers_ids:/peer-ids - peers_ids:/peer-ids
- ../config/watcher-mobymask-v3/deploy-nitro-contracts.sh:/app/packages/peer/deploy-nitro-contracts.sh
# Optionally deploys the Nitro contracts and sets them at the required path
# Starts the MobyMask v3 watcher server
mobymask-watcher-server:
image: cerc/watcher-mobymask-v3:local
restart: unless-stopped
depends_on:
mobymask-watcher-db:
condition: service_healthy
peer-ids-gen:
condition: service_completed_successfully
mobymask:
condition: service_completed_successfully
env_file:
- ../config/watcher-mobymask-v3/mobymask-params.env
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
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}
CERC_RELAY_ANNOUNCE_DOMAIN: ${CERC_RELAY_ANNOUNCE_DOMAIN}
CERC_ENABLE_PEER_L2_TXS: ${CERC_ENABLE_PEER_L2_TXS}
CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT}
CERC_NA_ADDRESS: ${CERC_NA_ADDRESS}
CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS}
CERC_CA_ADDRESS: ${CERC_CA_ADDRESS}
entrypoint: ["bash", "-c"]
command: ["./deploy-nitro-contracts.sh && ./read-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
- peers_ids:/app/peers
- nitro_addresses:/nitro - nitro_addresses:/nitro
- mobymask_deployment:/server
# Expose GQL, metrics and relay node ports
ports:
- "127.0.0.1:3001:3001"
- "127.0.0.1:9001:9001"
- "127.0.0.1:9090: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: volumes:
mobymask_watcher_db_data: mobymask_watcher_db_data:

View File

@ -4,17 +4,34 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x set -x
fi fi
CERC_L2_GETH_RPC="${CERC_L2_GETH_RPC:-${DEFAULT_CERC_L2_GETH_RPC}}" CERC_NA_ADDRESS="${CERC_NA_ADDRESS:-${DEFAULT_CERC_NA_ADDRESS}}"
CERC_L1_ACCOUNTS_CSV_URL="${CERC_L1_ACCOUNTS_CSV_URL:-${DEFAULT_CERC_L1_ACCOUNTS_CSV_URL}}" CERC_VPA_ADDRESS="${CERC_VPA_ADDRESS:-${DEFAULT_CERC_VPA_ADDRESS}}"
CERC_NITRO_CONTRACTS="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_NITRO_CONTRACTS}}" CERC_CA_ADDRESS="${CERC_CA_ADDRESS:-${DEFAULT_CERC_CA_ADDRESS}}"
NITRO_ADDRESSES_FILE_PATH="/nitro/nitro-addresses.json" NITRO_ADDRESSES_FILE_PATH="/nitro/nitro-addresses.json"
# Check if CERC_NITRO_CONTRACTS environment variable set to skip contract deployment # Check if CERC_NITRO_CONTRACTS environment variable set to skip contract deployment
if [ -n "$CERC_NITRO_CONTRACTS" ]; then if [ -n "$CERC_NA_ADDRESS" ]; then
echo "CERC_NITRO_CONTRACTS is set to '$CERC_NITRO_CONTRACTS'" echo "CERC_NA_ADDRESS is set to '$CERC_NA_ADDRESS'"
echo "Skipping Nitro contracts deployment" echo "CERC_VPA_ADDRESS is set to '$CERC_VPA_ADDRESS'"
exit 0 echo "CERC_CA_ADDRESS is set to '$CERC_CA_ADDRESS'"
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\"
}"
echo "$nitro_addresses_json" > "${NITRO_ADDRESSES_FILE_PATH}"
exit
fi
# Check and exit if a deployment already exists (on restarts)
if [ -f ${NITRO_ADDRESSES_FILE_PATH} ]; then
echo "${NITRO_ADDRESSES_FILE_PATH} already exists, skipping Nitro contracts deployment"
exit
fi fi
echo "Using L2 RPC endpoint ${CERC_L2_GETH_RPC}" echo "Using L2 RPC endpoint ${CERC_L2_GETH_RPC}"
@ -33,14 +50,8 @@ else
echo "Couldn't fetch L1 account credentials, using CERC_PRIVATE_KEY_DEPLOYER from env" echo "Couldn't fetch L1 account credentials, using CERC_PRIVATE_KEY_DEPLOYER from env"
fi fi
# Check and exit if a deployment already exists (on restarts) echo "RPC_URL=${CERC_L2_GETH_RPC}" > .env
if [ -f ${NITRO_ADDRESSES_FILE_PATH} ]; then echo "NITRO_ADDRESSES_FILE_PATH=${NITRO_ADDRESSES_FILE_PATH}" >> .env
echo "${NITRO_ADDRESSES_FILE_PATH} already exists, skipping Nitro contracts deployment" echo "PRIVATE_KEY=${CERC_PRIVATE_KEY_DEPLOYER}" >> .env
exit
fi
export RPC_URL="${CERC_L2_GETH_RPC}" yarn ts-node --esm deploy-nitro-contracts.ts
export NITRO_ADDRESSES_FILE_PATH="${NITRO_ADDRESSES_FILE_PATH}"
export PRIVATE_KEY="${CERC_PRIVATE_KEY_DEPLOYER}"
yarn ts-node --esm ./src/deploy-nitro-contracts.ts

View File

@ -1,3 +1,4 @@
import 'dotenv/config';
import fs from 'fs'; import fs from 'fs';
import { providers, Wallet } from 'ethers'; import { providers, Wallet } from 'ethers';
import { deployContracts } from '@cerc-io/nitro-util'; import { deployContracts } from '@cerc-io/nitro-util';

View File

@ -0,0 +1,37 @@
# Defaults
# Watcher endpoint
DEFAULT_CERC_APP_WATCHER_URL="http://localhost:3001"
# Set of relay peers to connect to from the relay node
DEFAULT_CERC_RELAY_PEERS=[]
# Domain to be used in the relay node's announce address
DEFAULT_CERC_RELAY_ANNOUNCE_DOMAIN=
# Base URI for mobymask-app (used for generating invite)
DEFAULT_CERC_MOBYMASK_APP_BASE_URI="http://127.0.0.1:3004/#"
# Set to false for disabling watcher peer to send txs to L2
DEFAULT_CERC_ENABLE_PEER_L2_TXS=true
# Set deployed MobyMask contract address to avoid deploying contract in stack
# mobymask-app will use this contract address in config if run separately
DEFAULT_CERC_DEPLOYED_CONTRACT=
# Chain ID is used by mobymask web-app for txs
DEFAULT_CERC_CHAIN_ID=42069
# Set of relay nodes to be used by web-apps
DEFAULT_CERC_RELAY_NODES=[]
# Set of multiaddrs to be avoided while dialling
DEFAULT_CERC_DENY_MULTIADDRS=[]
# Type of pubsub to be used
DEFAULT_CERC_PUBSUB=""
# Set deployed Nitro addresses to avoid deploying them in the stack
DEFAULT_CERC_NA_ADDRESS=
DEFAULT_CERC_VPA_ADDRESS=
DEFAULT_CERC_CA_ADDRESS=

View File

@ -0,0 +1,18 @@
#!/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

View File

@ -0,0 +1,80 @@
[server]
host = "0.0.0.0"
port = 3001
kind = "lazy"
# Checkpointing state.
checkpointing = true
# Checkpoint interval in number of blocks.
checkpointInterval = 2000
# Enable state creation
enableState = true
# Boolean to filter logs by contract.
filterLogs = true
# Max block range for which to return events in eventsInRange GQL query.
# Use -1 for skipping check on block range.
maxEventsBlockRange = -1
[server.p2p]
enableRelay = true
enablePeer = true
[server.p2p.relay]
host = "0.0.0.0"
port = 9090
relayPeers = REPLACE_WITH_CERC_RELAY_PEERS
denyMultiaddrs = REPLACE_WITH_CERC_DENY_MULTIADDRS
peerIdFile = './peers/relay-id.json'
announce = 'REPLACE_WITH_CERC_RELAY_ANNOUNCE_DOMAIN'
pubsub = 'REPLACE_WITH_CERC_PUBSUB'
enableDebugInfo = true
[server.p2p.peer]
relayMultiaddr = 'REPLACE_WITH_CERC_RELAY_MULTIADDR'
pubSubTopic = 'mobymask'
denyMultiaddrs = REPLACE_WITH_CERC_DENY_MULTIADDRS
peerIdFile = './peers/peer-id.json'
pubsub = 'REPLACE_WITH_CERC_PUBSUB'
enableDebugInfo = true
enableL2Txs = REPLACE_WITH_CERC_ENABLE_PEER_L2_TXS
[server.p2p.peer.l2TxsConfig]
privateKey = 'REPLACE_WITH_CERC_PRIVATE_KEY_PEER'
contractAddress = 'REPLACE_WITH_CONTRACT_ADDRESS'
[metrics]
host = "0.0.0.0"
port = 9000
[metrics.gql]
port = 9001
[database]
type = "postgres"
host = "mobymask-watcher-db"
port = 5432
database = "mobymask-watcher"
username = "vdbm"
password = "password"
synchronize = true
logging = false
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "http://ipld-eth-server:8083/graphql"
rpcProviderEndpoint = "REPLACE_WITH_CERC_L2_GETH_RPC_ENDPOINT"
blockDelayInMilliSecs = 60000
[upstream.cache]
name = "requests"
enabled = false
deleteOnStart = false
[jobQueue]
dbConnectionString = "postgres://vdbm:password@mobymask-watcher-db/mobymask-watcher-job-queue"
maxCompletionLagInSecs = 300
jobDelayInMilliSecs = 100
eventsInBatch = 50

View File

@ -0,0 +1,20 @@
FROM ubuntu:22.04
RUN apt-get update \
&& apt-get install -y curl wget gnupg build-essential \
&& curl --silent --location https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get update \
&& apt-get install -y nodejs git busybox jq \
&& node -v
RUN corepack enable \
&& yarn --version
WORKDIR /app
COPY . .
RUN echo "Building mobymask-v2-watcher-ts" && \
yarn && yarn build
WORKDIR /app

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Build cerc/watcher-mobymask-v3
source ${CERC_CONTAINER_BASE_DIR}/build-base.sh
# See: https://stackoverflow.com/a/246128/1701505
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
docker build -t cerc/watcher-mobymask-v3:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/mobymask-v2-watcher-ts

View File

@ -50,3 +50,4 @@ cerc/watcher-sushiswap
cerc/graph-node cerc/graph-node
cerc/sushiswap-subgraphs cerc/sushiswap-subgraphs
cerc/webapp-base cerc/webapp-base
cerc/watcher-mobymask-v3

View File

@ -8,9 +8,9 @@ repos:
- github.com/cerc-io/mobymask-ui - github.com/cerc-io/mobymask-ui
containers: containers:
- cerc/watcher-ts - cerc/watcher-ts
- cerc/watcher-mobymask-v2 - cerc/watcher-mobymask-v3
- cerc/mobymask-ui
- cerc/mobymask - cerc/mobymask
- cerc/mobymask-ui
pods: pods:
- watcher-mobymask-v3 - watcher-mobymask-v3
- mobymask-app-v3 # - mobymask-app-v3

View File

@ -5,13 +5,98 @@
Clone required repositories: Clone required repositories:
```bash ```bash
laconic-so --stack mobymask-v3 setup-repositories laconic-so --stack mobymask-v3 setup-repositories --pull --exclude github.com/cerc-io/mobymask-ui
``` ```
Build the container images: Build the container images:
```bash ```bash
laconic-so --stack mobymask-v3 build-containers laconic-so --stack mobymask-v3 build-containers --exclude cerc/mobymask-ui
``` ```
## Deploy ## Deploy
### Configuration
Create and update an env file to be used in the next step ([defaults](../../config/watcher-mobymask-v3/mobymask-params.env)):
```bash
# External L2 endpoints
CERC_L2_GETH_RPC=
# Endpoints waited on before contract deployment
CERC_L2_GETH_HOST=
CERC_L2_GETH_PORT=
CERC_L2_NODE_HOST=
CERC_L2_NODE_PORT=
# URL (fixturenet-eth-bootnode-lighthouse) to get CSV with credentials for accounts on L1 to perform txs on L2
CERC_L1_ACCOUNTS_CSV_URL=
# 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)
CERC_MOBYMASK_APP_BASE_URI="http://127.0.0.1:3004/#"
# (Optional) Domain to be used in the relay node's announce address
CERC_RELAY_ANNOUNCE_DOMAIN=
# (Optional) Set of relay peers to connect to from the relay node
CERC_RELAY_PEERS=[]
# (Optional) Set of multiaddrs to be avoided while dialling
CERC_DENY_MULTIADDRS=[]
# (Optional) Type of pubsub to be used
CERC_PUBSUB=""
# Set to false for disabling watcher peer to send txs to L2
CERC_ENABLE_PEER_L2_TXS=true
# (Optional) Set already deployed MobyMask contract address to avoid deploying contract in the stack
CERC_DEPLOYED_CONTRACT=
# (Optional) Set already deployed Nitro addresses to avoid deploying them in the stack
CERC_NA_ADDRESS=
CERC_VPA_ADDRESS=
CERC_CA_ADDRESS=
```
* NOTE: If Optimism is running on the host machine, use `host.docker.internal` as the hostname to access the host port
### Deploy the stack
```bash
laconic-so --stack mobymask-v3 deploy --cluster mobymask_v3 --include watcher-mobymask-v3 --env-file <PATH_TO_ENV_FILE> up
```
* To list down and monitor the running containers:
```bash
laconic-so --stack mobymask-v3 deploy --cluster mobymask_v3 --include watcher-mobymask-v3 ps
# With status
docker ps -a
# Check logs for a container
docker logs -f <CONTAINER_ID>
```
* The watcher endpoint is exposed on host port `3001` and the relay node endpoint is exposed on host port `9090`
* Check the logs of the MobyMask contract deployment container to get the deployed contract's address and generated root invite link:
```bash
docker logs -f $(docker ps -aq --filter name="mobymask-1")
```
* Check the logs of the watcher server container to get the deployed Nitro contracts' addresses:
```bash
docker exec -it $(docker ps -q --filter name="mobymask-watcher-server") bash -c "cat /nitro/nitro-addresses.json"
```