Add a stack for Gelato watcher

This commit is contained in:
Prathamesh Musale 2023-05-12 14:35:21 +05:30
parent d26dd4b531
commit b5ea8221f5
13 changed files with 338 additions and 1 deletions

View File

@ -0,0 +1,85 @@
version: '3.2'
services:
# Starts the PostgreSQL database for watcher
gelato-watcher-db:
restart: unless-stopped
image: postgres:14-alpine
environment:
- POSTGRES_USER=vdbm
- POSTGRES_MULTIPLE_DATABASES=gelato-watcher,gelato-watcher-job-queue
- POSTGRES_EXTENSION=gelato-watcher-job-queue:pgcrypto
- POSTGRES_PASSWORD=password
volumes:
- ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh
- gelato_watcher_db_data:/var/lib/postgresql/data
ports:
- "0.0.0.0:15432:5432"
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "5432"]
interval: 20s
timeout: 5s
retries: 15
start_period: 10s
# Starts the gelato-watcher job runner
gelato-watcher-job-runner:
image: cerc/watcher-gelato:local
restart: unless-stopped
depends_on:
gelato-watcher-db:
condition: service_healthy
env_file:
- ../config/watcher-gelato/watcher-params.env
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
CERC_ETH_SERVER_GQL_ENDPOINT: ${CERC_ETH_SERVER_GQL_ENDPOINT}
CERC_ETH_SERVER_RPC_ENDPOINT: ${CERC_ETH_SERVER_RPC_ENDPOINT}
command: ["./start-job-runner.sh"]
volumes:
- ../config/watcher-gelato/watcher-config-template.toml:/app/environments/watcher-config-template.toml
- ../config/watcher-gelato/start-job-runner.sh:/app/start-job-runner.sh
ports:
- "0.0.0.0:9000:9000"
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "9000"]
interval: 20s
timeout: 5s
retries: 15
start_period: 5s
extra_hosts:
- "host.docker.internal:host-gateway"
# Starts the gelato-watcher server
gelato-watcher-server:
image: cerc/watcher-gelato:local
restart: unless-stopped
depends_on:
gelato-watcher-db:
condition: service_healthy
gelato-watcher-job-runner:
condition: service_healthy
env_file:
- ../config/watcher-gelato/watcher-params.env
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
CERC_ETH_SERVER_GQL_ENDPOINT: ${CERC_ETH_SERVER_GQL_ENDPOINT}
CERC_ETH_SERVER_RPC_ENDPOINT: ${CERC_ETH_SERVER_RPC_ENDPOINT}
command: ["./start-server.sh"]
volumes:
- ../config/watcher-gelato/watcher-config-template.toml:/app/environments/watcher-config-template.toml
- ../config/watcher-gelato/start-server.sh:/app/start-server.sh
ports:
- "0.0.0.0:3001:3001"
- "0.0.0.0:9001:9001"
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "3001"]
interval: 20s
timeout: 5s
retries: 15
start_period: 5s
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
gelato_watcher_db_data:

View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
CERC_ETH_SERVER_GQL_ENDPOINT="${CERC_ETH_SERVER_GQL_ENDPOINT:-${DEFAULT_CERC_ETH_SERVER_GQL_ENDPOINT}}"
CERC_ETH_SERVER_RPC_ENDPOINT="${CERC_ETH_SERVER_RPC_ENDPOINT:-${DEFAULT_CERC_ETH_SERVER_RPC_ENDPOINT}}"
echo "Using ETH server GQL endpoint ${CERC_ETH_SERVER_GQL_ENDPOINT}"
echo "Using ETH server RPC endpoint ${CERC_ETH_SERVER_RPC_ENDPOINT}"
# Read in the config template TOML file and modify it
WATCHER_CONFIG_TEMPLATE=$(cat environments/watcher-config-template.toml)
WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \
sed -E "s|REPLACE_WITH_ETH_SERVER_GQL_ENDPOINT|${CERC_ETH_SERVER_GQL_ENDPOINT}|g; \
s|REPLACE_WITH_ETH_SERVER_RPC_ENDPOINT|${CERC_ETH_SERVER_RPC_ENDPOINT}| ")
# Write the modified content to a new file
echo "$WATCHER_CONFIG" > environments/local.toml
echo "Running job-runner"
DEBUG=vulcanize:* exec node --enable-source-maps dist/job-runner.js

View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
CERC_ETH_SERVER_GQL_ENDPOINT="${CERC_ETH_SERVER_GQL_ENDPOINT:-${DEFAULT_CERC_ETH_SERVER_GQL_ENDPOINT}}"
CERC_ETH_SERVER_RPC_ENDPOINT="${CERC_ETH_SERVER_RPC_ENDPOINT:-${DEFAULT_CERC_ETH_SERVER_RPC_ENDPOINT}}"
echo "Using ETH server GQL endpoint ${CERC_ETH_SERVER_GQL_ENDPOINT}"
echo "Using ETH server RPC endpoint ${CERC_ETH_SERVER_RPC_ENDPOINT}"
# Read in the config template TOML file and modify it
WATCHER_CONFIG_TEMPLATE=$(cat environments/watcher-config-template.toml)
WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \
sed -E "s|REPLACE_WITH_ETH_SERVER_GQL_ENDPOINT|${CERC_ETH_SERVER_GQL_ENDPOINT}|g; \
s|REPLACE_WITH_ETH_SERVER_RPC_ENDPOINT|${CERC_ETH_SERVER_RPC_ENDPOINT}| ")
# Write the modified content to a new file
echo "$WATCHER_CONFIG" > environments/local.toml
echo "Initializing watcher..."
yarn fill --start-block $DEFAULT_CERC_GELATO_START_BLOCK --end-block $DEFAULT_CERC_GELATO_START_BLOCK
echo "Running active server"
DEBUG=vulcanize:* exec node --enable-source-maps dist/server.js

View File

@ -0,0 +1,75 @@
[server]
host = "0.0.0.0"
port = 3008
kind = "active"
# Checkpointing state.
checkpointing = true
# Checkpoint interval in number of blocks.
checkpointInterval = 2000
# Enable state creation
# CAUTION: Disable only if state creation is not desired or can be filled subsequently
enableState = true
subgraphPath = "./subgraph"
# Interval to restart wasm instance periodically
wasmRestartBlocksInterval = 20
# Interval in number of blocks at which to clear entities cache.
clearEntitiesCacheInterval = 1000
# 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 = 1000
# GQL cache settings
[server.gqlCache]
enabled = true
# Max in-memory cache size (in bytes) (default 8 MB)
# maxCacheSize
# GQL cache-control max-age settings (in seconds)
maxAge = 15
timeTravelMaxAge = 86400 # 1 day
[metrics]
host = "0.0.0.0"
port = 9000
[metrics.gql]
port = 9001
[database]
type = "postgres"
host = "gelato-watcher-db"
port = 5432
database = "gelato-watcher"
username = "vdbm"
password = "password"
synchronize = true
logging = false
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "REPLACE_WITH_ETH_SERVER_GQL_ENDPOINT"
rpcProviderEndpoint = "REPLACE_WITH_ETH_SERVER_RPC_ENDPOINT"
[upstream.cache]
name = "requests"
enabled = false
deleteOnStart = false
[jobQueue]
dbConnectionString = "postgres://vdbm:password@gelato-watcher-db/gelato-watcher-job-queue"
maxCompletionLagInSecs = 300
jobDelayInMilliSecs = 100
eventsInBatch = 50
blockDelayInMilliSecs = 2000
prefetchBlocksInMem = true
prefetchBlockCount = 10

View File

@ -0,0 +1,6 @@
# ipld-eth-server endpoints
DEFAULT_CERC_ETH_SERVER_GQL_ENDPOINT="http://ipld-eth-server:8083/graphql"
DEFAULT_CERC_ETH_SERVER_RPC_ENDPOINT="http://ipld-eth-server:8082"
# Gelato start block
DEFAULT_CERC_GELATO_START_BLOCK=11361987

View File

@ -0,0 +1,12 @@
FROM node:18.15.0-alpine3.16
RUN apk --update --no-cache add git python3 alpine-sdk bash
WORKDIR /app
COPY . .
RUN echo "Building gelato-watcher-ts" && \
yarn && yarn build
WORKDIR /app

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Build cerc/watcher-gelato
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-gelato:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/gelato-watcher-ts

View File

@ -15,6 +15,6 @@ WORKDIR /app
COPY . . COPY . .
RUN echo "Building mobymask-v2-watcher-ts" && \ RUN echo "Building mobymask-v2-watcher-ts" && \
yarn && yarn build yarn && yarn build
WORKDIR /app WORKDIR /app

View File

@ -39,3 +39,4 @@ cerc/optimism-op-proposer
cerc/pocket cerc/pocket
cerc/watcher-azimuth cerc/watcher-azimuth
cerc/ipld-eth-state-snapshot cerc/ipld-eth-state-snapshot
cerc/watcher-gelato

View File

@ -26,3 +26,4 @@ foundry
fixturenet-optimism fixturenet-optimism
fixturenet-pocket fixturenet-pocket
watcher-azimuth watcher-azimuth
watcher-gelato

View File

@ -31,3 +31,4 @@ pokt-network/pocket-core
pokt-network/pocket-core-deployments pokt-network/pocket-core-deployments
cerc-io/azimuth-watcher-ts cerc-io/azimuth-watcher-ts
cerc-io/ipld-eth-state-snapshot cerc-io/ipld-eth-state-snapshot
cerc-io/gelato-watcher-ts

View File

@ -0,0 +1,90 @@
# Gelato watcher
Instructions to setup and deploy Gelato watcher using [laconic-stack-orchestrator](/README.md#install)
## Setup
Prerequisite: `ipld-eth-server` endpoints
Clone required repositories:
```bash
laconic-so --stack gelato setup-repositories
# If this throws an error as a result of being already checked out to a branch/tag in a repo, remove the repositories mentioned below and re-run the command
```
Checkout to required version in the repo:
```bash
# gelato-watcher-ts
cd ~/cerc/gelato-watcher-ts
git checkout v0.1.0
```
Build the container images:
```bash
laconic-so --stack gelato build-containers
```
This should create the required docker images in the local image registry.
## Deploy
### Configuration
Create and update an env file to be used in the next step ([defaults](../../config/watcher-gelato/watcher-params.env)):
```bash
# External ipld-eth-server endpoints
CERC_ETH_SERVER_GQL_ENDPOINT=
CERC_ETH_SERVER_RPC_ENDPOINT=
```
* NOTE: If `ipld-eth-server` is running on the host machine, use `host.docker.internal` as the hostname to access the host port(s)
### Deploy the stack
```bash
laconic-so --stack gelato deploy --env-file <PATH_TO_ENV_FILE> up
```
To list down and monitor the running containers:
```bash
laconic-so --stack gelato deploy ps
# With status
docker ps
# Check logs for a container
docker logs -f <CONTAINER_ID>
```
The stack runs an active watcher with following endpoints exposed on the host ports:
* `3008`: watcher endpoint
* `9000`: watcher metrics
* `9001`: watcher GQL metrics
## Web Apps
TODO
## Clean up
Stop all services running in the background:
```bash
laconic-so --stack gelato deploy down
```
Clear volumes created by this stack:
```bash
# List all relevant volumes
docker volume ls -q --filter "name=.*gelato_watcher_db_data"
# Remove all the listed volumes
docker volume rm $(docker volume ls -q --filter "name=.*gelato_watcher_db_data")
```

View File

@ -0,0 +1,8 @@
version: "1.0"
name: gelato
repos:
- cerc-io/gelato-watcher-ts
containers:
- cerc/watcher-gelato
pods:
- watcher-gelato