From da8bf00f78dc0d825e1f6755b9d076e8fa2f40f8 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Mon, 15 May 2023 14:26:48 +0530 Subject: [PATCH] Add commands to create and import a state checkpoint --- .../compose/docker-compose-watcher-gelato.yml | 6 ++++-- .../create-and-import-checkpoint.sh | 19 +++++++++++++++++-- app/data/stacks/gelato/README.md | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/data/compose/docker-compose-watcher-gelato.yml b/app/data/compose/docker-compose-watcher-gelato.yml index cce45b80..e2cb2801 100644 --- a/app/data/compose/docker-compose-watcher-gelato.yml +++ b/app/data/compose/docker-compose-watcher-gelato.yml @@ -73,11 +73,12 @@ services: - ../config/watcher-gelato/watcher-config-template.toml:/app/environments/watcher-config-template.toml - ../config/watcher-gelato/start-server.sh:/app/start-server.sh - ../config/watcher-gelato/create-and-import-checkpoint.sh:/app/create-and-import-checkpoint.sh + - gelato_watcher_state_gql:/app/state_checkpoint ports: - - "0.0.0.0:3001:3001" + - "0.0.0.0:3008:3008" - "0.0.0.0:9001:9001" healthcheck: - test: ["CMD", "nc", "-v", "localhost", "3001"] + test: ["CMD", "nc", "-v", "localhost", "3008"] interval: 20s timeout: 5s retries: 15 @@ -87,3 +88,4 @@ services: volumes: gelato_watcher_db_data: + gelato_watcher_state_gql: diff --git a/app/data/config/watcher-gelato/create-and-import-checkpoint.sh b/app/data/config/watcher-gelato/create-and-import-checkpoint.sh index 97f6c780..20b90503 100755 --- a/app/data/config/watcher-gelato/create-and-import-checkpoint.sh +++ b/app/data/config/watcher-gelato/create-and-import-checkpoint.sh @@ -7,7 +7,22 @@ fi CERC_SNAPSHOT_GQL_ENDPOINT="${CERC_SNAPSHOT_GQL_ENDPOINT:-${DEFAULT_CERC_SNAPSHOT_GQL_ENDPOINT}}" CERC_SNAPSHOT_BLOCKHASH="${CERC_SNAPSHOT_BLOCKHASH:-${DEFAULT_CERC_SNAPSHOT_BLOCKHASH}}" -# TODO Create a checkpoint using GQL endpoint (check and skip if snapshot file already exists) +CHECKPOINT_FILE_PATH="./state_checkpoint/state-gql-${CERC_SNAPSHOT_BLOCKHASH}" + +if [ -f "${CHECKPOINT_FILE_PATH}" ]; then + # Skip checkpoint creation if the file already exists + echo "File at ${CHECKPOINT_FILE_PATH} already exists, skipping checkpoint creation..." +else + # Create a checkpoint using GQL endpoint + echo "Creating a state checkpoint using GQL endpoint..." + yarn create-state-gql \ + --snapshot-block-hash "${CERC_SNAPSHOT_BLOCKHASH}" \ + --gql-endpoint "${CERC_SNAPSHOT_GQL_ENDPOINT}" \ + --output "${CHECKPOINT_FILE_PATH}" +fi echo "Initializing watcher using a state snapshot..." -# TODO Import the checkpoint + +# Import the state checkpoint +# (skips if snapshot block is already indexed) +yarn import-state --import-file "${CHECKPOINT_FILE_PATH}" diff --git a/app/data/stacks/gelato/README.md b/app/data/stacks/gelato/README.md index 0e4d7e30..3fb9708b 100644 --- a/app/data/stacks/gelato/README.md +++ b/app/data/stacks/gelato/README.md @@ -91,8 +91,8 @@ Clear volumes created by this stack: ```bash # List all relevant volumes -docker volume ls -q --filter "name=.*gelato_watcher_db_data" +docker volume ls -q --filter "name=.*gelato_watcher_db_data|.*gelato_watcher_state_gql" # Remove all the listed volumes -docker volume rm $(docker volume ls -q --filter "name=.*gelato_watcher_db_data") +docker volume rm $(docker volume ls -q --filter "name=.*gelato_watcher_db_data|.*gelato_watcher_state_gql") ```