From d74b3f0d2b2b243c26baf81ff95e3bea31d4e453 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 17:05:27 +0530 Subject: [PATCH 1/8] Add a healthcheck for ipld-eth-server --- app/deploy_system.py | 2 +- compose/docker-compose-ipld-eth-server.yml | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/deploy_system.py b/app/deploy_system.py index b3fb618a..91232094 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -73,7 +73,7 @@ def command(ctx, include, exclude, cluster, command, services): docker = DockerClient(compose_files=compose_files, compose_project_name=cluster) services_list = list(services) or None - + if not dry_run: if command == "up": if verbose: diff --git a/compose/docker-compose-ipld-eth-server.yml b/compose/docker-compose-ipld-eth-server.yml index 21dfd2b2..ee9c8885 100644 --- a/compose/docker-compose-ipld-eth-server.yml +++ b/compose/docker-compose-ipld-eth-server.yml @@ -30,4 +30,9 @@ services: ports: - "127.0.0.1:8081:8081" - "127.0.0.1:8082:8082" - + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "8081"] + interval: 20s + timeout: 5s + retries: 15 + start_period: 5s -- 2.45.2 From 82b08971b6015763b00c12cac11d050ccea79913 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 17:06:28 +0530 Subject: [PATCH 2/8] Update ipld-eth-server ports in mobymask watcher config --- config/watcher-mobymask/mobymask-watcher.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/watcher-mobymask/mobymask-watcher.toml b/config/watcher-mobymask/mobymask-watcher.toml index 4dba25b9..3e9b2db5 100644 --- a/config/watcher-mobymask/mobymask-watcher.toml +++ b/config/watcher-mobymask/mobymask-watcher.toml @@ -37,8 +37,8 @@ [upstream] [upstream.ethServer] - gqlApiEndpoint = "http://ipld-eth-server:8083/graphql" - rpcProviderEndpoint = "http://ipld-eth-server:8082" + gqlApiEndpoint = "http://ipld-eth-server:8082/graphql" + rpcProviderEndpoint = "http://ipld-eth-server:8081" blockDelayInMilliSecs = 60000 [upstream.cache] -- 2.45.2 From bcf595d1ac7c521ae94da330e6a4b89a98ed616b Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 17:07:50 +0530 Subject: [PATCH 3/8] Update clique period to 5s in geth-foundry config --- container-build/cerc-go-ethereum-foundry/genesis-automine.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-build/cerc-go-ethereum-foundry/genesis-automine.json b/container-build/cerc-go-ethereum-foundry/genesis-automine.json index a00a614e..6cbf7f26 100644 --- a/container-build/cerc-go-ethereum-foundry/genesis-automine.json +++ b/container-build/cerc-go-ethereum-foundry/genesis-automine.json @@ -10,7 +10,7 @@ "petersburgBlock": 0, "istanbulBlock": 0, "clique": { - "period": 2, + "period": 5, "epoch": 3000 } }, -- 2.45.2 From 633a72f5fa9afd59faf260a257c0ef2729fc9003 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 17:10:06 +0530 Subject: [PATCH 4/8] Add a stack for erc20 watcher --- app/data/container-image-list.txt | 1 + app/data/pod-list.txt | 1 + compose/docker-compose-watcher-erc20.yml | 49 +++++++++++++++++++ config/watcher-erc20/erc20-watcher.toml | 41 ++++++++++++++++ container-build/cerc-watcher-erc20/Dockerfile | 13 +++++ container-build/cerc-watcher-erc20/build.sh | 7 +++ stacks/erc20/README.md | 22 +++++++++ stacks/erc20/stack.yml | 18 +++++++ 8 files changed, 152 insertions(+) create mode 100644 compose/docker-compose-watcher-erc20.yml create mode 100644 config/watcher-erc20/erc20-watcher.toml create mode 100644 container-build/cerc-watcher-erc20/Dockerfile create mode 100755 container-build/cerc-watcher-erc20/build.sh create mode 100644 stacks/erc20/README.md create mode 100644 stacks/erc20/stack.yml diff --git a/app/data/container-image-list.txt b/app/data/container-image-list.txt index ba70e6f6..aa791460 100644 --- a/app/data/container-image-list.txt +++ b/app/data/container-image-list.txt @@ -13,6 +13,7 @@ cerc/laconic-cns-cli cerc/fixturenet-eth-geth cerc/fixturenet-eth-lighthouse cerc/watcher-mobymask +cerc/watcher-erc20 cerc/test-container cerc/eth-probe cerc/builder-js diff --git a/app/data/pod-list.txt b/app/data/pod-list.txt index a15507de..6b254cd3 100644 --- a/app/data/pod-list.txt +++ b/app/data/pod-list.txt @@ -11,6 +11,7 @@ laconicd fixturenet-laconicd fixturenet-eth watcher-mobymask +watcher-erc20 test eth-probe keycloak diff --git a/compose/docker-compose-watcher-erc20.yml b/compose/docker-compose-watcher-erc20.yml new file mode 100644 index 00000000..18beacb0 --- /dev/null +++ b/compose/docker-compose-watcher-erc20.yml @@ -0,0 +1,49 @@ +version: '3.2' + +services: + + watcher-db: + restart: unless-stopped + image: postgres:14-alpine + environment: + - POSTGRES_USER=vdbm + - POSTGRES_MULTIPLE_DATABASES=erc20-watcher,erc20-watcher-job-queue + - POSTGRES_EXTENSION=erc20-watcher-job-queue:pgcrypto + - POSTGRES_PASSWORD=password + volumes: + - ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh + - 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 + + erc20-watcher: + restart: unless-stopped + depends_on: + ipld-eth-server: + condition: service_healthy + watcher-db: + condition: service_healthy + image: cerc/watcher-erc20:local + environment: + - ETH_RPC_URL=http://go-ethereum:8545 + command: ["sh", "-c", "yarn server"] + volumes: + - ../config/watcher-erc20/erc20-watcher.toml:/app/packages/erc20-watcher/environments/local.toml + 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 + +volumes: + watcher_db_data: diff --git a/config/watcher-erc20/erc20-watcher.toml b/config/watcher-erc20/erc20-watcher.toml new file mode 100644 index 00000000..5b8b4ce5 --- /dev/null +++ b/config/watcher-erc20/erc20-watcher.toml @@ -0,0 +1,41 @@ +[server] + host = "0.0.0.0" + port = 3001 + mode = "storage" + kind = "lazy" + +[metrics] + host = "127.0.0.1" + port = 9000 + [metrics.gql] + port = 9001 + +[database] + type = "postgres" + host = "watcher-db" + port = 5432 + database = "erc20-watcher" + username = "vdbm" + password = "password" + synchronize = true + logging = false + maxQueryExecutionTime = 100 + +[upstream] + [upstream.ethServer] + gqlApiEndpoint = "http://ipld-eth-server:8082/graphql" + rpcProviderEndpoint = "http://ipld-eth-server:8081" + + [upstream.cache] + name = "requests" + enabled = false + deleteOnStart = false + +[jobQueue] + dbConnectionString = "postgres://vdbm:password@watcher-db:5432/erc20-watcher-job-queue" + maxCompletionLagInSecs = 300 + jobDelayInMilliSecs = 100 + eventsInBatch = 50 + blockDelayInMilliSecs = 2000 + prefetchBlocksInMem = true + prefetchBlockCount = 10 diff --git a/container-build/cerc-watcher-erc20/Dockerfile b/container-build/cerc-watcher-erc20/Dockerfile new file mode 100644 index 00000000..0a1ac2d0 --- /dev/null +++ b/container-build/cerc-watcher-erc20/Dockerfile @@ -0,0 +1,13 @@ +FROM node:16.17.1-alpine3.16 + +RUN apk --update --no-cache add git python3 alpine-sdk + +WORKDIR /app + +COPY . . + +RUN echo "Building watcher-ts" && \ + git checkout v0.2.18 && \ + yarn && yarn build + +WORKDIR /app/packages/erc20-watcher diff --git a/container-build/cerc-watcher-erc20/build.sh b/container-build/cerc-watcher-erc20/build.sh new file mode 100755 index 00000000..b800b73d --- /dev/null +++ b/container-build/cerc-watcher-erc20/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Build cerc/watcher-erc20 + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/watcher-erc20:local -f ${SCRIPT_DIR}/Dockerfile ${CERC_REPO_BASE_DIR}/watcher-ts diff --git a/stacks/erc20/README.md b/stacks/erc20/README.md new file mode 100644 index 00000000..416990b9 --- /dev/null +++ b/stacks/erc20/README.md @@ -0,0 +1,22 @@ +# ERC20 Watcher + +## Setup + +### Clone required repositories + +```bash +$ laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/watcher-ts +``` + +### Build the core and watcher containers + +```bash +$ laconic-so build-containers --include cerc/go-ethereum,cerc/go-ethereum-foundry,cerc/ipld-eth-db,cerc/ipld-eth-server,cerc/watcher-erc20 +``` + +### Deploy the stack + +```bash +$ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 up +``` + diff --git a/stacks/erc20/stack.yml b/stacks/erc20/stack.yml new file mode 100644 index 00000000..e9b0eb6d --- /dev/null +++ b/stacks/erc20/stack.yml @@ -0,0 +1,18 @@ +version: "1.0" +name: erc20-watcher +repos: + - cerc-io/go-ethereum + - cerc-io/ipld-eth-db + - cerc-io/ipld-eth-server + - cerc-io/watcher-ts +containers: + - cerc/go-ethereum + - cerc/go-ethereum-foundry + - cerc/ipld-eth-db + - cerc/ipld-eth-server + - cerc/watcher-erc20 +pods: + - go-ethereum-foundry + - db + - ipld-eth-server + - watcher-erc20 -- 2.45.2 From 01cc807a2ca9d82b6d00ca9cda96625abf3fd90e Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 17:10:32 +0530 Subject: [PATCH 5/8] Add a demo for erc20 watcher --- stacks/erc20/README.md | 131 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/stacks/erc20/README.md b/stacks/erc20/README.md index 416990b9..e19a2d90 100644 --- a/stacks/erc20/README.md +++ b/stacks/erc20/README.md @@ -20,3 +20,134 @@ $ laconic-so build-containers --include cerc/go-ethereum,cerc/go-ethereum-foundr $ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 up ``` +## Demo + +* Find the watcher container's id using `docker ps` and export it for later use: + + ```bash + $ export CONTAINER_ID= + ``` + +* Deploy an ERC20 token: + + ```bash + $ docker exec -it $CONTAINER_ID yarn token:deploy:docker + ``` + + Export the address of the deployed token to a shell variable for later use: + + ```bash + $ export TOKEN_ADDRESS= + ``` + +* Open `http://localhost:3001/graphql` (GraphQL Playground) in a browser window + +* Connect MetaMask to `http://localhost:8545` (with chain ID `99`) + +* Add the deployed token as an asset in MetaMask and check that the initial balance is zero + +* Export your MetaMask account (second account) address to a shell variable for later use: + + ```bash + $ export RECIPIENT_ADDRESS= + ``` + +* To get the primary account's address, run: + + ```bash + $ docker exec -it $CONTAINER_ID yarn account:docker + ``` + +* To get the current block hash at any time, run: + + ```bash + $ docker exec -it $CONTAINER_ID yarn block:latest:docker + ``` + +* Fire a GQL query in the playground to get the name, symbol and total supply of the deployed token: + + ```graphql + query { + name( + blockHash: "LATEST_BLOCK_HASH" + token: "TOKEN_ADDRESS" + ) { + value + proof { + data + } + } + + symbol( + blockHash: "LATEST_BLOCK_HASH" + token: "TOKEN_ADDRESS" + ) { + value + proof { + data + } + } + + totalSupply( + blockHash: "LATEST_BLOCK_HASH" + token: "TOKEN_ADDRESS" + ) { + value + proof { + data + } + } + } + ``` + +* Fire the following query to get balances for the primary and the recipient account at the latest block hash: + + ```graphql + query { + fromBalanceOf: balanceOf( + blockHash: "LATEST_BLOCK_HASH" + token: "TOKEN_ADDRESS", + # primary account having all the balance initially + owner: "PRIMARY_ADDRESS" + ) { + value + proof { + data + } + } + toBalanceOf: balanceOf( + blockHash: "LATEST_BLOCK_HASH" + token: "TOKEN_ADDRESS", + owner: "RECIPIENT_ADDRESS" + ) { + value + proof { + data + } + } + } + ``` + + * The initial balance for the primary account should be `1000000000000000000000` + * The initial balance for the recipient should be `0` + +* Transfer tokens to the recipient account: + + ```bash + $ docker exec -it $CONTAINER_ID yarn token:transfer:docker --token $TOKEN_ADDRESS --to $RECIPIENT_ADDRESS --amount 100 + ``` + +* Fire the above GQL query again with the latest block hash to get updated balances for the primary (`from`) and the recipient (`to`) account: + + * The balance for the primary account should be reduced by the transfer amount (`100`) + * The balance for the recipient account should be equal to the transfer amount (`100`) + +* Transfer funds between different accounts using MetaMask and use the playground to query the balance before and after the transfer. + +## Clean up + +* To stop all the services running in background run: + + ```bash + $ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 down + ``` -- 2.45.2 From 2d1c8cdfb86be2afe51d53119da8a705d8f69ff0 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 18:22:24 +0530 Subject: [PATCH 6/8] Upgrade watcher-ts version --- container-build/cerc-watcher-erc20/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-build/cerc-watcher-erc20/Dockerfile b/container-build/cerc-watcher-erc20/Dockerfile index 0a1ac2d0..5ec94987 100644 --- a/container-build/cerc-watcher-erc20/Dockerfile +++ b/container-build/cerc-watcher-erc20/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /app COPY . . RUN echo "Building watcher-ts" && \ - git checkout v0.2.18 && \ + git checkout v0.2.19 && \ yarn && yarn build WORKDIR /app/packages/erc20-watcher -- 2.45.2 From 6283aff0b93b9208b2d48011f275c6da60dccbc3 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 18:22:48 +0530 Subject: [PATCH 7/8] Update instructions --- stacks/erc20/README.md | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/stacks/erc20/README.md b/stacks/erc20/README.md index e19a2d90..f094cfe0 100644 --- a/stacks/erc20/README.md +++ b/stacks/erc20/README.md @@ -1,24 +1,28 @@ # ERC20 Watcher +Instructions to deploy a local ERC20 watcher stack (core + watcher) for demonstration and testing purposes using [laconic-stack-orchestrator](../../README.md#setup) + ## Setup -### Clone required repositories +* Clone required repositories: -```bash -$ laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/watcher-ts -``` + ```bash + $ laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/watcher-ts + ``` -### Build the core and watcher containers +* Build the core and watcher container images: -```bash -$ laconic-so build-containers --include cerc/go-ethereum,cerc/go-ethereum-foundry,cerc/ipld-eth-db,cerc/ipld-eth-server,cerc/watcher-erc20 -``` + ```bash + $ laconic-so build-containers --include cerc/go-ethereum,cerc/go-ethereum-foundry,cerc/ipld-eth-db,cerc/ipld-eth-server,cerc/watcher-erc20 + ``` -### Deploy the stack + This should create the required docker images in the local image registry. -```bash -$ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 up -``` +* Deploy the stack: + + ```bash + $ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 up + ``` ## Demo @@ -31,7 +35,7 @@ $ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watc * Deploy an ERC20 token: ```bash - $ docker exec -it $CONTAINER_ID yarn token:deploy:docker + $ docker exec $CONTAINER_ID yarn token:deploy:docker ``` Export the address of the deployed token to a shell variable for later use: @@ -55,13 +59,13 @@ $ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watc * To get the primary account's address, run: ```bash - $ docker exec -it $CONTAINER_ID yarn account:docker + $ docker exec $CONTAINER_ID yarn account:docker ``` * To get the current block hash at any time, run: ```bash - $ docker exec -it $CONTAINER_ID yarn block:latest:docker + $ docker exec $CONTAINER_ID yarn block:latest:docker ``` * Fire a GQL query in the playground to get the name, symbol and total supply of the deployed token: @@ -134,7 +138,7 @@ $ laconic-so deploy-system --include db,go-ethereum-foundry,ipld-eth-server,watc * Transfer tokens to the recipient account: ```bash - $ docker exec -it $CONTAINER_ID yarn token:transfer:docker --token $TOKEN_ADDRESS --to $RECIPIENT_ADDRESS --amount 100 + $ docker exec $CONTAINER_ID yarn token:transfer:docker --token $TOKEN_ADDRESS --to $RECIPIENT_ADDRESS --amount 100 ``` * Fire the above GQL query again with the latest block hash to get updated balances for the primary (`from`) and the recipient (`to`) account: -- 2.45.2 From cabab88ffe73277e70c2779c86f7121881ee3cf4 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 21 Dec 2022 20:16:59 +0530 Subject: [PATCH 8/8] Pass option to pull while setting up repos --- stacks/erc20/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stacks/erc20/README.md b/stacks/erc20/README.md index f094cfe0..eec3d9f4 100644 --- a/stacks/erc20/README.md +++ b/stacks/erc20/README.md @@ -4,10 +4,10 @@ Instructions to deploy a local ERC20 watcher stack (core + watcher) for demonstr ## Setup -* Clone required repositories: +* Clone / pull required repositories: ```bash - $ laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/watcher-ts + $ laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/watcher-ts --pull ``` * Build the core and watcher container images: -- 2.45.2