* Clear cache of latest entities on event processing error * Remove lighthouse-watcher and update ethersjs version * Handle GraphDecimal type in state entity * Add option for comparing all entities using paginate * Clear pruned cached entities at intervals * Move ipld-demo to graph-node package and remove reset-dbs script * Implement changes in all watchers and codegen
4.5 KiB
Demo for IPLD statediff and checkpointing
-
In the root of
watcher-ts
, run:yarn && yarn build
-
In console, run the IPFS daemon:
# Verify ipfs version ipfs version # ipfs version 0.12.2 ipfs daemon
-
The following services should be running to work with watcher:
- vulcanize/go-ethereum (v1.10.17-statediff-3.2.0) on port 8545.
- vulcanize/ipld-eth-server (v3.0.0) with native GQL API enabled on port 8082 and RPC API enabled on port 8081.
-
Deploy
Example
contract:cd packages/graph-node yarn example:deploy
-
Set the returned address to the variable
$EXAMPLE_ADDRESS
:EXAMPLE_ADDRESS=
-
In
packages/graph-node
, run:cp .env.example .env
-
In
.env
file, setEXAMPLE_CONTRACT_ADDRESS
to theEXAMPLE_ADDRESS
. -
In packages/graph-node/test/subgraph/example1/subgraph.yaml, set the source address for
Example1
datasource to theEXAMPLE_ADDRESS
.
yarn build:example
-
-
In
packages/codegen
, create aconfig.yaml
file with the following contents:contracts: - name: Example path: ../graph-node/test/contracts/Example.sol kind: Example1 outputFolder: ../demo-example-watcher mode: all kind: active port: 3008 flatten: true subgraphPath: ../graph-node/test/subgraph/example1/build
Reference: packages/codegen/README.md
-
Generate watcher:
cd packages/codegen yarn codegen --config-file ./config.yaml
-
In
packages/demo-example-watcher
, run:yarn
-
Create dbs:
sudo su - postgres # Delete databases if they already exist. dropdb demo-example-watcher dropdb demo-example-watcher-job-queue # Create databases createdb demo-example-watcher createdb demo-example-watcher-job-queue
Enable the
pgcrypto
extension.psql -U postgres -h localhost demo-example-watcher-job-queue demo-example-watcher-job-queue=# CREATE EXTENSION pgcrypto; demo-example-watcher-job-queue=# exit
-
In a new terminal, in
packages/demo-example-watcher
, run:yarn server
yarn job-runner
-
Run the following GQL subscription at the graphql endpoint:
subscription { onEvent { event { __typename ... on TestEvent { param1 param2 param3 }, }, block { number hash } } }
-
Trigger the
Test
event by calling example contract method:cd packages/graph-node yarn example:test --address $EXAMPLE_ADDRESS
A
Test
event shall be visible in the subscription at endpoint. -
Run the
getState
query at the endpoint to get the latestIPLDBlock
forEXAMPLE_ADDRESS
:query { getState ( blockHash: "EVENT_BLOCK_HASH" contractAddress: "EXAMPLE_ADDRESS" kind: "diff_staged" ) { cid block { cid hash number timestamp parentHash } contractAddress data } }
-
Run the query for entity at the endpoint:
query { author ( block: { hash: "EVENT_BLOCK_HASH" } id: "0xdc7d7a8920c8eecc098da5b7522a5f31509b5bfc" ) { __typename name paramInt paramBigInt paramBytes } }
-
diff
IPLDBlocks get created corresponding to thediff_staged
blocks when their respectiveeth_block
s reach the pruned region. -
In
packages/demo-example-watcher
:-
After the
diff
block has been created, create acheckpoint
:cd packages/demo-example-watcher yarn checkpoint --address $EXAMPLE_ADDRESS
-
A
checkpoint
IPLDBlock should be created at the latest canonical block hash. -
Run the
getState
query again at the endpoint with the outputblockHash
and kindcheckpoint
.
-
-
-
All the
IPLDBlock
entries can be seen inpg-admin
in tableipld_block
. -
All the
diff
andcheckpoint
IPLDBlocks should be pushed toIPFS
. -
Open IPFS WebUI http://127.0.0.1:5001/webui and search for
IPLDBlock
s using theirCID
s.