From 45177bb2ce84117e5e6d5ad2c67730c842e9d2bd Mon Sep 17 00:00:00 2001 From: nabarun Date: Wed, 19 Jun 2024 10:29:22 +0000 Subject: [PATCH] Add stack for sushiswap route processor subgraph watcher (#13) Part of [Create an external stack for sushiswap subgraph watchers](https://www.notion.so/Create-an-external-stack-for-sushiswap-subgraph-watchers-932617e953b54193af25b24a578145b7) Co-authored-by: IshaVenikar Reviewed-on: https://git.vdb.to/cerc-io/sushiswap-watcher-ts/pulls/13 Co-authored-by: nabarun Co-committed-by: nabarun --- README.md | 2 + stacks/README.md | 9 ++ ...pose-watcher-sushiswap-route-processor.yml | 80 +++++++++++++ .../watcher-config-template.toml | 110 ++++++++++++++++++ .../sushiswap-route-processor/README.md | 104 +++++++++++++++++ .../sushiswap-route-processor/stack.yml | 8 ++ 6 files changed, 313 insertions(+) create mode 100644 stacks/README.md create mode 100644 stacks/stack-orchestrator/compose/docker-compose-watcher-sushiswap-route-processor.yml create mode 100644 stacks/stack-orchestrator/config/watcher-sushiswap-route-processor/watcher-config-template.toml create mode 100644 stacks/stack-orchestrator/stacks/sushiswap-route-processor/README.md create mode 100644 stacks/stack-orchestrator/stacks/sushiswap-route-processor/stack.yml diff --git a/README.md b/README.md index 288447d..d4f23b4 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Watchers for the [sushiswap-subgraphs](https://github.com/cerc-io/sushiswap-subgraphs/tree/watcher-ts) on Filecoin +[Stacks](stacks/README.md) for the sushiswap-watchers + ## Setup * Run the following command to install required packages: diff --git a/stacks/README.md b/stacks/README.md new file mode 100644 index 0000000..e0bd668 --- /dev/null +++ b/stacks/README.md @@ -0,0 +1,9 @@ +# sushiswap-watcher-stack + +Stacks to run watchers for sushiswap-subgraphs + +- [sushiswap-watcher](stack-orchestrator/stacks/sushiswap) +- [blocks-watcher](stack-orchestrator/stacks/sushiswap-blocks) +- [route-processor-watcher](stack-orchestrator/stacks/sushiswap-route-processor) +- [v2-watcher](stack-orchestrator/stacks/sushiswap-v2) +- [v3-watcher](stack-orchestrator/stacks/sushiswap-v3) diff --git a/stacks/stack-orchestrator/compose/docker-compose-watcher-sushiswap-route-processor.yml b/stacks/stack-orchestrator/compose/docker-compose-watcher-sushiswap-route-processor.yml new file mode 100644 index 0000000..ddd9096 --- /dev/null +++ b/stacks/stack-orchestrator/compose/docker-compose-watcher-sushiswap-route-processor.yml @@ -0,0 +1,80 @@ +version: '3.2' + +services: + sushiswap-route-processor-watcher-db: + restart: unless-stopped + image: postgres:14-alpine + environment: + - POSTGRES_USER=vdbm + - POSTGRES_MULTIPLE_DATABASES=sushiswap-route-processor-watcher,sushiswap-route-processor-watcher-job-queue + - POSTGRES_EXTENSION=sushiswap-route-processor-watcher-job-queue:pgcrypto + - POSTGRES_PASSWORD=password + volumes: + - ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh + - sushiswap_route-processor_watcher_db_data:/var/lib/postgresql/data + ports: + - "5432" + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "5432"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 10s + + sushiswap-route-processor-watcher-job-runner: + restart: unless-stopped + depends_on: + sushiswap-route-processor-watcher-db: + condition: service_healthy + image: cerc/watcher-sushiswap:local + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_ETH_RPC_ENDPOINTS: ${CERC_ETH_RPC_ENDPOINTS} + working_dir: /app/packages/route-processor-watcher + command: ["bash", "./start-job-runner.sh"] + volumes: + - ../config/watcher-sushiswap-route-processor/watcher-config-template.toml:/app/packages/route-processor-watcher/environments/watcher-config-template.toml + - ../config/common/start-job-runner.sh:/app/packages/route-processor-watcher/start-job-runner.sh + ports: + - "9000" + healthcheck: + test: ["CMD", "nc", "-vz", "127.0.0.1", "9000"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 5s + extra_hosts: + - "host.docker.internal:host-gateway" + + sushiswap-route-processor-watcher-server: + restart: unless-stopped + depends_on: + sushiswap-route-processor-watcher-db: + condition: service_healthy + sushiswap-route-processor-watcher-job-runner: + condition: service_healthy + image: cerc/watcher-sushiswap:local + environment: + CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} + CERC_ETH_RPC_ENDPOINTS: ${CERC_ETH_RPC_ENDPOINTS} + working_dir: /app/packages/route-processor-watcher + command: ["bash", "./start-server.sh"] + volumes: + - ../config/watcher-sushiswap-route-processor/watcher-config-template.toml:/app/packages/route-processor-watcher/environments/watcher-config-template.toml + - ../config/common/start-server.sh:/app/packages/route-processor-watcher/start-server.sh + - sushiswap_route-processor_watcher_gql_logs_data:/app/packages/route-processor-watcher/gql-logs + ports: + - "3008" + - "9001" + healthcheck: + test: ["CMD", "nc", "-vz", "127.0.0.1", "3008"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 5s + extra_hosts: + - "host.docker.internal:host-gateway" + +volumes: + sushiswap_route-processor_watcher_db_data: + sushiswap_route-processor_watcher_gql_logs_data: diff --git a/stacks/stack-orchestrator/config/watcher-sushiswap-route-processor/watcher-config-template.toml b/stacks/stack-orchestrator/config/watcher-sushiswap-route-processor/watcher-config-template.toml new file mode 100644 index 0000000..24723b0 --- /dev/null +++ b/stacks/stack-orchestrator/config/watcher-sushiswap-route-processor/watcher-config-template.toml @@ -0,0 +1,110 @@ +[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 = false + + subgraphPath = "./subgraph-build" + + # Interval to restart wasm instance periodically + wasmRestartBlocksInterval = 20 + + # Interval in number of blocks at which to clear entities cache. + clearEntitiesCacheInterval = 1000 + + # Flag to specify whether RPC endpoint supports block hash as block tag parameter + rpcSupportsBlockHashParam = false + + # Server GQL config + [server.gql] + path = "/graphql" + + # Max block range for which to return events in eventsInRange GQL query. + # Use -1 for skipping check on block range. + maxEventsBlockRange = 1000 + + # Log directory for GQL requests + logDir = "./gql-logs" + + # GQL cache settings + [server.gql.cache] + 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 = "sushiswap-route-processor-watcher-db" + port = 5432 + database = "sushiswap-route-processor-watcher" + username = "vdbm" + password = "password" + synchronize = true + logging = false + +[upstream] + [upstream.ethServer] + rpcProviderEndpoints = REPLACE_WITH_CERC_ETH_RPC_ENDPOINTS + + # Boolean flag to specify if rpc-eth-client should be used for RPC endpoint instead of ipld-eth-client (ipld-eth-server GQL client) + rpcClient = true + + # Boolean flag to specify if rpcProviderEndpoint is an FEVM RPC endpoint + isFEVM = true + + # Boolean flag to filter event logs by contracts + filterLogsByAddresses = true + # Boolean flag to filter event logs by topics + filterLogsByTopics = true + + [upstream.cache] + name = "requests" + enabled = false + deleteOnStart = false + +[jobQueue] + dbConnectionString = "postgres://vdbm:password@sushiswap-route-processor-watcher-db/sushiswap-route-processor-watcher-job-queue" + maxCompletionLagInSecs = 300 + jobDelayInMilliSecs = 100 + eventsInBatch = 50 + subgraphEventsOrder = true + # Filecoin block time: https://docs.filecoin.io/basics/the-blockchain/blocks-and-tipsets#blocktime + blockDelayInMilliSecs = 30000 + + # Number of blocks by which block processing lags behind head + blockProcessingOffset = 0 + + # Boolean to switch between modes of processing events when starting the server. + # Setting to true will fetch filtered events and required blocks in a range of blocks and then process them. + # Setting to false will fetch blocks consecutively with its events and then process them (Behaviour is followed in realtime processing near head). + useBlockRanges = true + + # Block range in which logs are fetched during historical blocks processing + historicalLogsBlockRange = 2000 + + # Max block range of historical processing after which it waits for completion of events processing + # If set to -1 historical processing does not wait for events processing and completes till latest canonical block + historicalMaxFetchAhead = 10000 + + # Max number of retries to fetch new block after which watcher will failover to other RPC endpoints + maxNewBlockRetries = 3 diff --git a/stacks/stack-orchestrator/stacks/sushiswap-route-processor/README.md b/stacks/stack-orchestrator/stacks/sushiswap-route-processor/README.md new file mode 100644 index 0000000..c2f6be5 --- /dev/null +++ b/stacks/stack-orchestrator/stacks/sushiswap-route-processor/README.md @@ -0,0 +1,104 @@ +# SushiSwap route-processor Watcher + +## Clone the stack repo + +```bash +laconic-so fetch-stack git.vdb.to/cerc-io/sushiswap-watcher-ts +``` + +## Build the container image + +```bash +laconic-so --stack ~/cerc/sushiswap-watcher-ts/stacks/stack-orchestrator/stacks/sushiswap-route-processor build-containers +``` + +## Create a spec file for the deployment + +```bash +laconic-so --stack ~/cerc/sushiswap-watcher-ts/stacks/stack-orchestrator/stacks/sushiswap-route-processor deploy init --output sushiswap-route-processor-spec.yml +``` + +### Ports + +Edit `network` in the spec file to map container ports to host ports as required: + +```yml +... +network: + ports: + sushiswap-route-processor-watcher-db: + - 15432:5432 + sushiswap-route-processor-watcher-job-runner: + - 9000:9000 + sushiswap-route-processor-watcher-server: + - 3008:3008 + - 9001:9001 +``` + +## Create a deployment from the spec file + +```bash +laconic-so --stack ~/cerc/sushiswap-watcher-ts/stacks/stack-orchestrator/stacks/sushiswap-route-processor deploy create --spec-file sushiswap-route-processor-spec.yml --deployment-dir sushiswap-route-processor-deployment +``` + +### Configuration + +Inside deployment directory, open the `config.env` file and set following env variables: + +```bash +# External Filecoin (ETH RPC) endpoint to point the watcher to +CERC_ETH_RPC_ENDPOINTS=https://example-lotus-endpoint-1/rpc/v1,https://example-lotus-endpoint-2/rpc/v1 +``` + +## Start the deployment + +```bash +laconic-so deployment --dir sushiswap-route-processor-deployment start +``` + +* To list down and monitor the running containers: + + ```bash + # With status + docker ps -a + + # Check logs for a container + docker logs -f + ``` + +* Open the GQL playground at + + ```graphql + # Example query + query { + _meta { + block { + hash + number + timestamp + } + deployment + hasIndexingErrors + } + ``` + +## Clean up + +Stop all the sushiswap-route-processor services running in background: + +```bash +# Only stop the docker containers +laconic-so deployment --dir sushiswap-route-processor-deployment stop + +# Run 'start' to restart the deployment +``` + +To stop all the sushiswap-route-processor services and also delete data: + +```bash +# Stop the docker containers +laconic-so deployment --dir sushiswap-route-processor-deployment stop --delete-volumes + +# Remove deployment directory (deployment will have to be recreated for a re-run) +rm -r sushiswap-route-processor-deployment +``` diff --git a/stacks/stack-orchestrator/stacks/sushiswap-route-processor/stack.yml b/stacks/stack-orchestrator/stacks/sushiswap-route-processor/stack.yml new file mode 100644 index 0000000..45fdb27 --- /dev/null +++ b/stacks/stack-orchestrator/stacks/sushiswap-route-processor/stack.yml @@ -0,0 +1,8 @@ +version: "1.0" +name: sushiswap-route-processor +description: "SushiSwap route processor watcher stack" +repos: +containers: + - cerc/watcher-sushiswap +pods: + - watcher-sushiswap-route-processor