From be519e9ca0af09cf11e3b726db315024d0a18884 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Tue, 26 Sep 2023 17:31:00 +0530 Subject: [PATCH] Split graph-node stack to run independently (#541) * Split graph-node stack to run independently * Fix sushiswap subgraph config in fixturenet stack --- .../compose/docker-compose-graph-node.yml | 9 +- .../lotus-fixturenet.js.template | 4 +- .../stacks/fixturenet-graph-node/README.md | 3 - .../stacks/fixturenet-graph-node/stack.yml | 12 -- .../fixturenet-sushiswap-subgraph/README.md | 49 ++++-- app/data/stacks/graph-node/README.md | 153 ++++++++++++++++++ app/data/stacks/graph-node/stack.yml | 9 ++ 7 files changed, 206 insertions(+), 33 deletions(-) delete mode 100644 app/data/stacks/fixturenet-graph-node/README.md delete mode 100644 app/data/stacks/fixturenet-graph-node/stack.yml create mode 100644 app/data/stacks/graph-node/README.md create mode 100644 app/data/stacks/graph-node/stack.yml diff --git a/app/data/compose/docker-compose-graph-node.yml b/app/data/compose/docker-compose-graph-node.yml index 278af02a..e35ff494 100644 --- a/app/data/compose/docker-compose-graph-node.yml +++ b/app/data/compose/docker-compose-graph-node.yml @@ -6,9 +6,6 @@ services: condition: service_healthy ipfs: condition: service_healthy - # Uncomment when running against fixturenet-lotus to wait for the Lotus node to come up - # lotus-node-1: - # condition: service_healthy extra_hosts: - host.docker.internal:host-gateway environment: @@ -18,9 +15,13 @@ services: postgres_user: graph-node postgres_pass: password postgres_db: graph-node - ethereum: ${NETWORK:-filecoin}:${ETH_RPC_ENDPOINT:-https://archive.lotus.vdb.to/rpc/v1} + ethereum: ${ETH_NETWORKS:-lotus-fixturenet:http://lotus-node-1:1234/rpc/v1} GRAPH_LOG: debug ETHEREUM_REORG_THRESHOLD: 3 + entrypoint: ["bash", "-c"] + # Wait for ETH RPC endpoint to be up when running with fixturenet-lotus + command: | + "wait_for ${ETH_RPC_HOST:-lotus-node-1}:${ETH_RPC_PORT:-1234} -t 1800 -- start" ports: - "8000" - "8001" diff --git a/app/data/config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template b/app/data/config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template index 6a8da152..94bfb6d8 100644 --- a/app/data/config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template +++ b/app/data/config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template @@ -17,8 +17,8 @@ module.exports = { whitelistedTokenAddresses: [ 'NATIVE_ADDRESS', ], - stableTokenAddresses: [ - ], + stableTokenAddresses: [], + nativePricePool: '0x0000000000000000000000000000000000000000', minimumEthLocked: 1.5 } } diff --git a/app/data/stacks/fixturenet-graph-node/README.md b/app/data/stacks/fixturenet-graph-node/README.md deleted file mode 100644 index 6e010b50..00000000 --- a/app/data/stacks/fixturenet-graph-node/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Graph-Node Fixturenet - -Experimental \ No newline at end of file diff --git a/app/data/stacks/fixturenet-graph-node/stack.yml b/app/data/stacks/fixturenet-graph-node/stack.yml deleted file mode 100644 index 20073d86..00000000 --- a/app/data/stacks/fixturenet-graph-node/stack.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: "1.0" -name: fixturenet-graph-node -description: "A graph-node fixturenet" -repos: - - github.com/filecoin-project/lotus - - github.com/graphprotocol/graph-node -containers: - - cerc/lotus - - cerc/graph-node -pods: - - fixturenet-lotus - - graph-node diff --git a/app/data/stacks/fixturenet-sushiswap-subgraph/README.md b/app/data/stacks/fixturenet-sushiswap-subgraph/README.md index 17b07635..b1151271 100644 --- a/app/data/stacks/fixturenet-sushiswap-subgraph/README.md +++ b/app/data/stacks/fixturenet-sushiswap-subgraph/README.md @@ -32,21 +32,10 @@ laconic-so --stack fixturenet-sushiswap-subgraph build-containers ## Deploy - -Create an env file with the following contents to be used in the next step: - -```bash -# Network and ETH RPC endpoint to run graph-node against -NETWORK=lotus-fixturenet -ETH_RPC_ENDPOINT=http://lotus-node-1:1234/rpc/v1 -``` - -Uncomment the dependency on `lotus-node-1` in the [graph-node compose file](../../compose/docker-compose-graph-node.yml) - Deploy the stack: ```bash -laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph --env-file up +laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph up # Note: Remove any existing volumes for the cluster for a fresh start ``` @@ -154,6 +143,42 @@ http://127.0.0.1:/subgraphs/name/sushiswap/v3-lotus/graphql docker exec -it sushigraph-sushiswap-v3-core-1 pnpm run pool:burn:docker --pool $POOL_ADDRESS --amount 10 ``` +* Query the sushiswap v3-lotus subgraph GQL after running above commands + + ```graphql + { + _meta { + block { + number + } + deployment + hasIndexingErrors + } + + factories { + poolCount + id + } + + pools { + id + token0 { + id + name + symbol + } + mints { + id + owner + } + burns { + id + owner + } + } + } + ``` + ## Clean up Stop all the services running in background run: diff --git a/app/data/stacks/graph-node/README.md b/app/data/stacks/graph-node/README.md new file mode 100644 index 00000000..3bcbf8a1 --- /dev/null +++ b/app/data/stacks/graph-node/README.md @@ -0,0 +1,153 @@ +# Graph Node + +## Setup + +Clone required repositories: + +```bash +laconic-so --stack graph-node setup-repositories --pull +``` + +Checkout to a non-default branch in the cloned repos if required: + +```bash +# Default repo base dir +cd ~/cerc + +# Example +cd graph-node +git checkout && git pull + +# Remove the corresponding docker image if it already exists +docker image rm cerc/graph-node:local +# Remove any dangling images +docker image prune +``` + +Build the container images: + +```bash +laconic-so --stack graph-node build-containers +``` + +## Create a deployment + +Initialize deployment and create "spec" file: + +```bash +laconic-so --stack graph-node deploy init --output graph-node-spec.yml +``` + +We need to assign a fixed port `8000` for subgraph GQL endpoint and `8020` for subgraph deployment. The values can be +customized by editing the "spec" file generated by `laconic-so deploy init`. +``` +$ cat graph-node-spec.yml +stack: graph-node +ports: + graph-node: + - '8000:8000' + - '8001' + - '8020:8020' + - '8030' +... +``` + +Create deployment: + +```bash +laconic-so deploy create --spec-file graph-node-spec.yml --deployment-dir graph-node-deployment +``` + +## Start the stack + +Create an env file with the following values to be set before starting the stack: + +```bash +# Set ETH RPC endpoint the graph node will use + +# Host and port of the ETH RPC endpoint to check before starting graph-node +export ETH_RPC_HOST= +export ETH_RPC_PORT= + +# The etherum network(s) graph-node will connect to +# Set this to a space-separated list of the networks where each entry has the form NAME:URL +export ETH_NETWORKS= +``` + +Example env file: + +```bash +export ETH_RPC_HOST=filecoin.chainup.net +export ETH_RPC_PORT=443 + +export ETH_NETWORKS=filecoin:https://filecoin.chainup.net/rpc/v1 +``` + +Set the environment variables: + +```bash +source +``` + +Deploy the stack: + +```bash +laconic-so deployment --dir graph-node-deployment start + +# Note: Remove any existing volumes in the cluster for a fresh start +``` + +After all services have started, follow `graph-node` logs: + +```bash +laconic-so deployment --dir graph-node-deployment logs -f graph-node +``` + +Subgraphs can now be deployed to the graph-node. +Follow [Deploy the Subgraph](https://github.com/graphprotocol/graph-node/blob/v0.32.0/docs/getting-started.md#24-deploy-the-subgraph) section in graph-node docs for an existing subgraph. + +## Set environment variables + +* The graph-node environment variable `ETHEREUM_REORG_THRESHOLD` can be set in the deployment compose file + ```bash + $ cat graph-node-deployment/compose/docker-compose-graph-node.yml + services: + graph-node: + image: cerc/graph-node:local + ... + environment: + ... + GRAPH_LOG: debug + ETHEREUM_REORG_THRESHOLD: 3 + ``` + Change `ETHEREUM_REORG_THRESHOLD` to desired value + + * To restart graph-node with updated values + * Stop the stack first + ```bash + laconic-so deployment --dir graph-node-deployment stop + ``` + * Start the stack again + ``` + laconic-so deployment --dir graph-node-deployment start + ``` + * To check if environment variable has been updated in graph-node container + ```bash + $ laconic-so deployment --dir graph-node-deployment exec graph-node bash + root@dc4d3abe1615:/# echo $ETHEREUM_REORG_THRESHOLD + 16 + ``` + +## Clean up + +Stop all the services running in background run: + +```bash +laconic-so deployment --dir graph-node-deployment stop +``` + +Clear volumes created by this stack: + +```bash +laconic-so deployment --dir graph-node-deployment stop --delete-volumes +``` diff --git a/app/data/stacks/graph-node/stack.yml b/app/data/stacks/graph-node/stack.yml new file mode 100644 index 00000000..ce45e965 --- /dev/null +++ b/app/data/stacks/graph-node/stack.yml @@ -0,0 +1,9 @@ +version: "1.0" +name: graph-node +description: "Stack for running graph-node" +repos: + - github.com/graphprotocol/graph-node +containers: + - cerc/graph-node +pods: + - graph-node