Developers Forum for XinFin XDC Network

Yohan Nelson
Yohan Nelson

Posted on

[WIP] eth_call returns an error from RPC

Running an graph-node on the XDC Apothem Testnet, any contract read calls made from the event handlers throws an error.

The handleEvent function is as follows:

export function handleRoleGranted(event: RoleGranted): void {
  const ID = `Block-RoleGranted-${event.address.toHexString()}-${
    event.block.timestamp
  }`;
  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();// FAILS HERE
  parameter.blockReward = contract.blockReward();
  parameter.buffer = contract.buffer();
  parameter.save();

  roleGranted.role = event.params.role;
  roleGranted.account = event.params.account;
  roleGranted.sender = event.params.sender;
  roleGranted.save();

  indexRole(
    event.address,
    "BlockManager",
    event.params.role,
    event.params.account,
    false
  );
}
Enter fullscreen mode Exit fullscreen mode

This is an eth_call made to the contract address to get the value of a parameter that is set.

The error on graph-node:

Done processing trigger, gas_used: 0, data_source: BlockManager, handler: handleRoleGranted, total_ms: 3525, transaction: 0x0d43…0eb7, address: 0x970d…df38, signature: RoleGranted(indexed bytes32,indexed address,indexed address), sgd: 1, subgraph_id: QmQevJNXrsC86HEsSnKCU1M9M46ycwJrDwFVom3VbjwU6L, component: SubgraphInstanceManager
2024-02-01 08:38:51 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: InvalidParams, message: "invalid argument 1: hex string without 0x prefix", data: None }
wasm backtrace:
    0: 0x3823 - <unknown>!~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.SmartContract#call
    1: 0x90e1 - <unknown>!src/mappings/blockManager/handleRoleGranted
Enter fullscreen mode Exit fullscreen mode

My docker-compose.yml

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: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.10.0
    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: graph-node being used is gzliudan/graph-node:v0.32.0.

Using the https://arpc.apothem.network/ always returns an 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

but using https://erpc.apothem.network/ does not throw this error.

xdc #subgraph #graph-node #blocker

Discussion (2)

Collapse
gzliudan profile image
Daniel Liu • Edited on

For testnet, you can use the official imge graphprotocol/graph-node, my image gzliudan/graph-node is no longer maintained now.

Please change:

ethereum: "apothem:traces,archive:https://erpc.apothem.network/"
Enter fullscreen mode Exit fullscreen mode

to

ethereum: "apothem:traces,archive,no_eip1898:https://earpc.apothem.network"
Enter fullscreen mode Exit fullscreen mode

Please refer to the document.

Collapse
gzliudan profile image
Daniel Liu • Edited on

I tested my subgraph project again. It also includes eth_call and it works fine.