Developers Forum for XinFin XDC Network

Yohan Nelson
Yohan Nelson

Posted on • Updated on

[WIP] Protocol Specific Subgraph

We have a protocol which has a subgraph. We are testing the protocol on XDC Testnet (apothem). Attaching my docker-compose.yml file here, I have made the necessary changes but the indexer does not index the contracts. Just gets stuck with no errors.

2024-01-31 09:41:37 INFO Resolve mapping, link: /ipfs/QmRz1zv8JYmSkMGSBXTz38cQXR5sAw3c46ZB4EPBC3NMQM, sgd: 4, subgraph_id: Qmd66MRVwDR9UarZ3KhKhN3o2kWR8zPjXGtWMPY4DJxQC9, component: SubgraphInstanceManager
2024-01-31 09:41:37 INFO Resolve ABI, link: /ipfs/QmcmbcnsRDQ2EoL6gpF6zqE11JJknbLypLBpCvrEs9nJgW, name: RandomNoManager, sgd: 4, subgraph_id: Qmd66MRVwDR9UarZ3KhKhN3o2kWR8zPjXGtWMPY4DJxQC9, component: SubgraphInstanceManager
2024-01-31 09:41:37 INFO Successfully resolved subgraph files using IPFS, sgd: 4, subgraph_id: Qmd66MRVwDR9UarZ3KhKhN3o2kWR8zPjXGtWMPY4DJxQC9, component: SubgraphInstanceManager
2024-01-31 09:41:37 INFO Data source count at start: 9, sgd: 4, subgraph_id: Qmd66MRVwDR9UarZ3KhKhN3o2kWR8zPjXGtWMPY4DJxQC9, component: SubgraphInstanceManager

docker-compose.yml

version: "3"
services:
  graph-node:
    image: graphprotocol/graph-node
    container_name: node
    ports:
      - "8000:8000"
      - "8001:8001"
      - "8020:8020"
      - "8030:8030"
      - "8040:8040"

    restart: unless-stopped
    depends_on:
      - ipfs
      - postgres
    environment:
      postgres_host: postgres
      postgres_user: graph-node
      postgres_pass: let-me-in
      postgres_db: graph-node
      ipfs: "ipfs:5001"
      ethereum: "apothem:traces,archive,no_eip1898:https://erpc.apothem.network"
      GRAPH_LOG: info
      ETHEREUM_REORG_THRESHOLD: 1
      GRAPH_ETHEREUM_FETCH_TXN_RECEIPTS_IN_BATCHES: "true"
      GRAPH_LOG_TIME_FORMAT: "%Y-%m-%d %H:%M:%S"

  ipfs:
    image: ipfs/go-ipfs:v0.4.23
    container_name: ipfs
    ports:
      - "5001:5001"
    volumes:
      - ./data/ipfs:/data/ipfs
  postgres:
    image: postgres
    container_name: postgres
    command:
      [
        "postgres",
        "-cshared_preload_libraries=pg_stat_statements"
      ]
    environment:
      POSTGRES_USER: graph-node
      POSTGRES_PASSWORD: let-me-in
      POSTGRES_DB: graph-node
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready" ]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
Enter fullscreen mode Exit fullscreen mode


.

I have a specific start block to begin indexing from. But the indexer just stops.

Dependancies used:
"dependencies": {
"@graphprotocol/graph-cli": "^0.49.0",
"@graphprotocol/graph-ts": "^0.30.0",
"@razor-network/contracts": "^1.0.2",
"mustache": "^4.2.0"
}
.

I see https://github.com/gzliudan/bad-token-subgraph, we have our own indexer with contract specific mappings and schema.
How do we get this to work?

xdc #subgraph #graph-node

Discussion (13)

Collapse
yohan profile image
Yohan Nelson Author • Edited on

Got this error now

2024-01-31 11:18:40 INFO Done processing trigger, gas_used: 0, data_source: BlockManager, handler: handleRoleGranted, total_ms: 5410, transaction: 0x0d43…0eb7, address: 0x970d…df38, signature: RoleGranted(indexed bytes32,indexed address,indexed address), sgd: 6, subgraph_id: QmbuYK56Hfhn78GpXeMUQYojHJxabgnuWdGTFVdvz7u35E, component: SubgraphInstanceManager
2024-01-31 11:18:40 INFO Possible reorg detected, retrying, error: failed to process trigger: block #59378446 (0x39ae…66f0), transaction 0d431e6d18bea21ffc2b4c676f1882f4e89205535d81683898557a002f0f0eb7: Ethereum node returned an error when calling function "maxAltBlocks" of contract "BlockManager": RPC error: Error { code: ServerError(-32000), message: "missing trie Node 7677072c2bc482aa00f30a1116973b631600adb6e753820b36bcc551125f3ea5 (path )", data: None }
wasm backtrace:
    0: 0x3823 - <unknown>!~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.SmartContract#call
    1: 0x90f6 - <unknown>!src/mappings/blockManager/handleRoleGranted
, block_hash: 0x39ae05638d82c8d9968ff7ed2b268e9825445bb6f3dd86c701027af6c84066f0, block_number: 59378446, sgd: 6, subgraph_id: QmbuYK56Hfhn78GpXeMUQYojHJxabgnuWdGTFVdvz7u35E, component: SubgraphInstanceManager
Enter fullscreen mode Exit fullscreen mode

this happens due to a contract call being made in the handler function like so

let contract = BlockManager.bind(event.address);
  let roleGranted = new RoleGrantedEvent(ID);

  let parameter = Parameter.load("Parameter");
  if (!parameter) {
    parameter = new Parameter("Parameter");
  }

  parameter.maxAltBlocks = contract.maxAltBlocks();
  parameter.blockReward = contract.blockReward();
  parameter.buffer = contract.buffer();
  parameter.save();
Enter fullscreen mode Exit fullscreen mode
Collapse
rushabh_parmar profile image
Rushabh Parmar • Edited on

Please make sure you are using Archive node RPC Endpoint

Archive Node RPC with 0x Prefix: arpc.apothem.network
Archive Node Websocket with 0x Prefix: wss://aws.apothem.network

Collapse
yohan profile image
Yohan Nelson Author • Edited on

I have switched to this RPC, but I get the error here on my indexer


2024-01-31 11:18:40 INFO Done processing trigger, gas_used: 0, data_source: BlockManager, handler: handleRoleGranted, total_ms: 5410, transaction: 0x0d43…0eb7, address: 0x970d…df38, signature: RoleGranted(indexed bytes32,indexed address,indexed address), sgd: 6, subgraph_id: QmbuYK56Hfhn78GpXeMUQYojHJxabgnuWdGTFVdvz7u35E, component: SubgraphInstanceManager
2024-01-31 11:18:40 INFO Possible reorg detected, retrying, error: failed to process trigger: block #59378446 (0x39ae…66f0), transaction 0d431e6d18bea21ffc2b4c676f1882f4e89205535d81683898557a002f0f0eb7: Ethereum node returned an error when calling function "maxAltBlocks" of contract "BlockManager": RPC error: Error { code: ServerError(-32000), message: "missing trie Node 7677072c2bc482aa00f30a1116973b631600adb6e753820b36bcc551125f3ea5 (path )", data: None }
wasm backtrace:
    0: 0x3823 - <unknown>!~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.SmartContract#call
    1: 0x90f6 - <unknown>!src/mappings/blockManager/handleRoleGranted
, block_hash: 0x39ae05638d82c8d9968ff7ed2b268e9825445bb6f3dd86c701027af6c84066f0, block_number: 59378446, sgd: 6, subgraph_id: QmbuYK56Hfhn78GpXeMUQYojHJxabgnuWdGTFVdvz7u35E, component: SubgraphInstanceManager
Enter fullscreen mode Exit fullscreen mode

This is when I run a local instance on docker. I am testing out our indexer. It might not be available on graph.apothem.network I have a specific usecase for the indexer and handlers are customised to the protocols requirements @rushabh_parmar

Thread Thread
rushabh_parmar profile image
Rushabh Parmar

If you want the customise changes in the indexer and handlers for that you will have to setup your own dedicated graph node

please check out the detail guide on How to setup a dedicated graph node github.com/Carry-So/graph-node/blo...

Thread Thread
yohan profile image
Yohan Nelson Author • Edited on

I mean handlers for the events that are logged by the indexer. For eg, running a custom frontend, so updating for eg user related data that I receive from the events emitted. I have a graph-indexer implemented. Is there some custom changes required for the XDC Testnet network to be compatible ? The same indexer runs on mumbai and sepolia for eg, other EVM chains seem to be fine. Are there some changes I need to handle ? @rushabh_parmar

Use case:
A Uniswap like implementation, building an indexer for historical trades for the events emitted when using the dapp.

Collapse
yohan profile image
Yohan Nelson Author

@rushabh_parmar This RPC gave me the same error

UNCAUGHT EXCEPTION: Error: Failed to deploy to Graph node http://localhost:8020/: subgraph validation error: [the specified block must exist on the Ethereum network]
Enter fullscreen mode Exit fullscreen mode

only erpc.apothem.network RPC does not throw this error

Collapse
yohan profile image
Yohan Nelson Author
Collapse
gzliudan profile image
Daniel Liu

Please post your current file docker-compose.yml.

Collapse
yohan profile image
Yohan Nelson Author • Edited on

this is my file.

version: "3"
services:
  graph-node:
    image: gzliudan/graph-node:v0.32.0
    container_name: node
    ports:
      - "8000:8000"
      - "8001:8001"
      - "8020:8020"
      - "8030:8030"
      - "8040:8040"

    restart: unless-stopped
    depends_on:
      - ipfs
      - postgres
    environment:
      postgres_host: postgres
      postgres_user: graph-node
      postgres_pass: let-me-in
      postgres_db: graph-node
      ipfs: "ipfs:5001"
      ethereum: "apothem:traces,archive,no_eip1898:https://earpc.apothem.network"
      GRAPH_LOG: info
      ETHEREUM_REORG_THRESHOLD: 1
      GRAPH_ETHEREUM_FETCH_TXN_RECEIPTS_IN_BATCHES: "true"
      GRAPH_LOG_TIME_FORMAT: "%Y-%m-%d %H:%M:%S"

  ipfs:
    image: ipfs/go-ipfs:v0.4.23
    ports:
      - '5001:5001'
    volumes:
      - ./data/ipfs:/data/ipfs
  postgres:
    image: postgres:14
    ports:
      - '5432:5432'
    command:
      [
        "postgres",
        "-cshared_preload_libraries=pg_stat_statements"
      ]
    environment:
      POSTGRES_USER: graph-node
      POSTGRES_PASSWORD: let-me-in
      POSTGRES_DB: graph-node
      PGDATA: "/var/lib/postgresql/data"
      POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
Enter fullscreen mode Exit fullscreen mode

Note: The indexer runs, but it seems to index only the first few events then stops. The graphql explorer always shows the same Deployment ID and the block.number stays the same it does not increase while the indexer is syncing ie (_meta query), no data is showing on the graphql explorer that is spun up (localhost:8000/subgraphs/name/app/app).

@gzliudan

Thread Thread
gzliudan profile image
Daniel Liu • Edited on

For testnet, you can use the official file docker-compose.yml, except below changes:

      ethereum: "apothem:traces,archive,no_eip1898:https://earpc.apothem.network"
      ETHEREUM_REORG_THRESHOLD: 1
      GRAPH_ETHEREUM_FETCH_TXN_RECEIPTS_IN_BATCHES: true
      GRAPH_LOG: info
      GRAPH_LOG_TIME_FORMAT: "%Y-%m-%d %H:%M:%S"
Enter fullscreen mode Exit fullscreen mode

Please refer to the document.

Thread Thread
gzliudan profile image
Daniel Liu

I tested my below subgraph projects without any problem:

below is my file docker-compose-apothem.yml:

version: '3'
services:
  graph-node:
    image: graphprotocol/graph-node
    ports:
      - '8000:8000'
      - '8001:8001'
      - '8020:8020'
      - '8030:8030'
      - '8040:8040'
    depends_on:
      - ipfs
      - postgres
    extra_hosts:
      - host.docker.internal:host-gateway
    environment:
      postgres_host: postgres
      postgres_user: graph-node
      postgres_pass: let-me-in
      postgres_db: graph-node
      ipfs: 'ipfs:5001'
      ethereum: "apothem:traces,archive,no_eip1898:https://earpc.apothem.network"
      ETHEREUM_REORG_THRESHOLD: 1
      GRAPH_ETHEREUM_FETCH_TXN_RECEIPTS_IN_BATCHES: true
      GRAPH_LOG: info
      GRAPH_LOG_TIME_FORMAT: "%Y-%m-%d %H:%M:%S"
  ipfs:
    image: ipfs/kubo:v0.14.0
    ports:
      - '5001:5001'
    volumes:
      - ./data/ipfs:/data/ipfs
  postgres:
    image: postgres:14
    ports:
      - '5432:5432'
    command:
      [
        "postgres",
        "-cshared_preload_libraries=pg_stat_statements",
        "-cmax_connections=200"
      ]
    environment:
      POSTGRES_USER: graph-node
      POSTGRES_PASSWORD: let-me-in
      POSTGRES_DB: graph-node
      # FIXME: remove this env. var. which we shouldn't need. Introduced by
      # <https://github.com/graphprotocol/graph-node/pull/3511>, maybe as a
      # workaround for https://github.com/docker/for-mac/issues/6270?
      PGDATA: "/var/lib/postgresql/data"
      POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
Enter fullscreen mode Exit fullscreen mode

BTW, you can upload your subgraph project to GitHub. Then I can test it for you.

Collapse
rushabh_parmar profile image
Rushabh Parmar

Can you please use below graph node endpoints

graph.apothem.network
graphql.apothem.network
wss://graphql-ws.apothem.network

Collapse
yohan profile image
Yohan Nelson Author • Edited on

@rushabh_parmar Got this error for both https endpoints above. The block most definitely exists on the XDC Apothem Testnet

UNCAUGHT EXCEPTION: Error: Failed to deploy to Graph node http://localhost:8020/: subgraph validation error: [the specified block must exist on the Ethereum network]
Enter fullscreen mode Exit fullscreen mode