* 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
Examplecontract: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
.envfile, setEXAMPLE_CONTRACT_ADDRESSto theEXAMPLE_ADDRESS. -
In packages/graph-node/test/subgraph/example1/subgraph.yaml, set the source address for
Example1datasource to theEXAMPLE_ADDRESS.
yarn build:example -
-
In
packages/codegen, create aconfig.yamlfile 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/buildReference: 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-queueEnable the
pgcryptoextension.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 serveryarn 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
Testevent by calling example contract method:cd packages/graph-node yarn example:test --address $EXAMPLE_ADDRESSA
Testevent shall be visible in the subscription at endpoint. -
Run the
getStatequery at the endpoint to get the latestIPLDBlockforEXAMPLE_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 } } -
diffIPLDBlocks get created corresponding to thediff_stagedblocks when their respectiveeth_blocks reach the pruned region. -
In
packages/demo-example-watcher:-
After the
diffblock has been created, create acheckpoint:cd packages/demo-example-watcher yarn checkpoint --address $EXAMPLE_ADDRESS-
A
checkpointIPLDBlock should be created at the latest canonical block hash. -
Run the
getStatequery again at the endpoint with the outputblockHashand kindcheckpoint.
-
-
-
All the
IPLDBlockentries can be seen inpg-adminin tableipld_block. -
All the
diffandcheckpointIPLDBlocks should be pushed toIPFS. -
Open IPFS WebUI http://127.0.0.1:5001/webui and search for
IPLDBlocks using theirCIDs.