-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add demo for graph-watcher IPLD statediff and checkpointing
- Loading branch information
Showing
9 changed files
with
336 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
# Demo for IPLD statediff and checkpointing | ||
|
||
* In the root of `graph-watcher-ts`, run: | ||
|
||
```bash | ||
yarn && yarn build | ||
``` | ||
|
||
* In console, run the IPFS daemon: | ||
|
||
```bash | ||
# 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](https://github.com/vulcanize/go-ethereum) on port 8545. | ||
* [vulcanize/ipld-eth-server](https://github.com/vulcanize/ipld-eth-server) with native GQL API enabled on port 8082 and RPC API enabled on port 8081. | ||
* [postgraphile](https://github.com/vulcanize/postgraphile) on the `vulcanize/ipld-eth-server` database, on port 5000 | ||
|
||
* Deploy `Example` contract: | ||
|
||
```bash | ||
cd packages/graph-node | ||
|
||
yarn example:deploy | ||
``` | ||
|
||
* Set the returned address to the variable `$EXAMPLE_ADDRESS`: | ||
|
||
```bash | ||
EXAMPLE_ADDRESS= | ||
``` | ||
|
||
* In `packages/graph-node`, run: | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
* In `.env` file, set `EXAMPLE_CONTRACT_ADDRESS` to the `EXAMPLE_ADDRESS`. | ||
|
||
* In [packages/graph-node/test/subgraph/example1/subgraph.yaml](./packages/graph-node/test/subgraph/example1/subgraph.yaml), set the source address for `Example1` datasource to the `EXAMPLE_ADDRESS`. | ||
|
||
```bash | ||
yarn build:example | ||
``` | ||
|
||
* In `packages/codegen`, create a `config.yaml` file with the following contents: | ||
|
||
```yaml | ||
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](./packages/codegen/README.md#run) | ||
|
||
* Generate watcher: | ||
|
||
```bash | ||
cd packages/codegen | ||
|
||
yarn codegen --config-file ./config.yaml | ||
``` | ||
|
||
* In `packages/demo-example-watcher`, run: | ||
|
||
```bash | ||
yarn | ||
``` | ||
|
||
* Create dbs: | ||
|
||
```bash | ||
sudo su - postgres | ||
postgres@tesla:~$ createdb demo-example-watcher | ||
postgres@tesla:~$ createdb demo-example-watcher-job-queue | ||
``` | ||
|
||
``` | ||
postgres@tesla:~$ 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: | ||
|
||
```bash | ||
yarn server | ||
``` | ||
|
||
```bash | ||
yarn job-runner | ||
``` | ||
|
||
* Run the following GQL subscription at the [graphql endpoint](http://127.0.0.1:3008/graphql): | ||
|
||
```graphql | ||
subscription { | ||
onEvent { | ||
event { | ||
__typename | ||
... on TestEvent { | ||
param1 | ||
param2 | ||
param3 | ||
}, | ||
}, | ||
block { | ||
number | ||
hash | ||
} | ||
} | ||
} | ||
``` | ||
|
||
* Trigger the `Test` event by calling example contract method: | ||
|
||
```bash | ||
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 latest `IPLDBlock` for `EXAMPLE_ADDRESS`: | ||
|
||
```graphql | ||
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: | ||
|
||
```graphql | ||
query { | ||
author ( | ||
block: { | ||
hash: "EVENT_BLOCK_HASH" | ||
} | ||
id: "0xdc7d7a8920c8eecc098da5b7522a5f31509b5bfc" | ||
) { | ||
__typename | ||
name | ||
paramInt | ||
paramBigInt | ||
paramBytes | ||
} | ||
} | ||
``` | ||
|
||
* `diff` IPLDBlocks get created corresponding to the `diff_staged` blocks when their respective `eth_block`s reach the pruned region. | ||
|
||
* In `packages/demo-example-watcher`: | ||
|
||
* After the `diff` block has been created, create a `checkpoint`: | ||
|
||
```bash | ||
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 output `blockHash` and kind `checkpoint`. | ||
|
||
* All the `IPLDBlock` entries can be seen in `pg-admin` in table `ipld_block`. | ||
|
||
* All the `diff` and `checkpoint` IPLDBlocks should be pushed to `IPFS`. | ||
|
||
* Open IPFS WebUI http://127.0.0.1:5001/webui and search for `IPLDBlock`s using their `CID`s. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
import { task, types } from 'hardhat/config'; | ||
import '@nomiclabs/hardhat-ethers'; | ||
import { ContractTransaction } from 'ethers'; | ||
|
||
task('example-test', 'Trigger Test event') | ||
.addParam('address', 'Contract address', undefined, types.string) | ||
.setAction(async (args, hre) => { | ||
const { address } = args; | ||
await hre.run('compile'); | ||
const Example = await hre.ethers.getContractFactory('Example'); | ||
const example = Example.attach(address); | ||
|
||
const transaction: ContractTransaction = await example.emitEvent(); | ||
|
||
const receipt = await transaction.wait(); | ||
|
||
if (receipt.events) { | ||
const TestEvent = receipt.events.find(el => el.event === 'Test'); | ||
|
||
if (TestEvent && TestEvent.args) { | ||
console.log('Test Event'); | ||
console.log('param1:', TestEvent.args.param1.toString()); | ||
console.log('param2:', TestEvent.args.param2.toString()); | ||
console.log('param3:', TestEvent.args.param3.toString()); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.