Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Error - Question] Failed To get Entities from the store - Subgraph query error while trying to run graph-node and harhdat locally. #4871

Closed
1 of 3 tasks
RafaDSan opened this issue Sep 15, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@RafaDSan
Copy link

RafaDSan commented Sep 15, 2023

Bug report

Basic explanation of the problem

I'm currently working on a local subgraph for tracking events on an Ethereum smart contract. I aim to query specific entities, but I'm encountering an error when attempting to do so. The error message I'm receiving is: '"message": "Failed to get entities from store: Odd number of digits, query = from \"sgd2\".\"task_created\"[*]{id = 1} order none first 100 at 0 query_id 7316f7c8141c25f5-6dc8c4ef99f8cc6a"'" . I am honestly pretty noob on this, so I would greatly appreciate your help.

Steps to reproduce the problem

  1. Started a local blockchain with npx hardhat node --hostname 0.0.0.0

  2. Configured my hardhat.config.ts as follows:

    localhost: {
    chainId: 1337,
    url: "htpp://0.0.0.0:8545"

  3. Compiled my smart contract and deployed it to the hardhat node, which generated the following message:

Contract deployment: Web3Task
Contract address: 0xec20dcbf0380f1c9856ee345af41f62ee45a95a1
Transaction: 0xf8f0de6b1a4a2895dffc30db1f7dc56853c1b94570190ea43e2aa331b9dd3214
From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
Value: 0 ETH
Gas used: 4006332 of 4006332
Block #38359529: 0x50ae5ffd41dee3d39dbc32ae9d5fcc95fac9830d2d7d1700795977e7027305ef

  1. I cloned the graph-node repository inside my main contracts directory

  2. in docker/docker-compose.yml I configured the file as follows:

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: "mainnet:http://host.docker.internal:8545"
GRAPH_LOG: info
ETHEREUM_REORG_THRESHOLD: 1
ETHEREUM_ANCESTOR_COUNT: 1
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
# #3511, maybe as a
# workaround for docker/for-mac#6270?
PGDATA: "/var/lib/postgresql/data"
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
volumes:
- ./data/postgres:/var/lib/postgresql/data

  1. Run the command docker-compose up (log in Relevant log output)

  2. And the hardhat log keeps going with the same values in a loop.

eth_getBlockByNumber
eth_getBlockByHash
eth_getBlockByNumber (2)
eth_getLogs
eth_getBlockByHash
eth_getBlockByNumber (2)

  1. And then I upload my subgraph with:
    npm run create-local
    npm run deploy-local

which shows:
**Build completed: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY

Deployed to http://localhost:8000/subgraphs/name/web3task_subraph/graphql

Subgraph endpoints:
Queries (HTTP): http://localhost:8000/subgraphs/name/web3task_subraph**

  1. My schema.graphql looks as follows: (this is not the whole file, I just kept some of the events in order to not make it so long)
type TaskCreated @entity(immutable: true) {
  id: Bytes!
  taskId: BigInt! # uint256
  creator: Bytes! # address
  assignee: Bytes! # address
  reward: BigInt! # uint256
  endDate: BigInt! # uint256
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}

type TaskStarted @entity(immutable: true) {
  id: Bytes!
  taskId: BigInt! # uint256
  assignee: Bytes! # address
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}


10. And then my query and the error:

image

I tried to run some local tests to generate traffic to query it.

How do I solve this error and what is causing it?

Edit:

My subgraph.yaml:

specVersion: 0.0.5
schema:
  file: ./schema.graphql
dataSources:
  - kind: ethereum
    name: Web3Task
    network: mainnet
    source:
      address: "0xec20dcbf0380f1c9856ee345af41f62ee45a95a1"
      abi: Web3Task
      startBlock: 1
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.7
      language: wasm/assemblyscript
      entities:
        - Approval
        - ApprovalForAll
        - AuthorizedOperator
        - AuthorizedPersonnel
        - TaskCreated
        - TaskStarted
        - TaskUpdated
        - Transfer
      abis:
        - name: Web3Task
          file: ./abis/Web3Task.json
      eventHandlers:
        - event: Approval(indexed address,indexed address,indexed uint256)
          handler: handleApproval
        - event: ApprovalForAll(indexed address,indexed address,bool)
          handler: handleApprovalForAll
        - event: AuthorizedOperator(indexed uint256,indexed bytes4)
          handler: handleAuthorizedOperator
        - event: AuthorizedPersonnel(indexed uint256,indexed address,bool)
          handler: handleAuthorizedPersonnel
        - event: TaskCreated(indexed uint256,indexed address,indexed address,uint256,uint256)
          handler: handleTaskCreated
        - event: TaskStarted(indexed uint256,indexed address)
          handler: handleTaskStarted
        - event: TaskUpdated(indexed uint256,uint8)
          handler: handleTaskUpdated
        - event: Transfer(indexed address,indexed address,indexed uint256)
          handler: handleTransfer
      file: ./src/web-3-task.ts

Relevant log output

graph-node_1  | Sep 15 16:18:49.114 INFO Scanning blocks [2133112, 2135111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:49.482 INFO Scanning blocks [2135112, 2137111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:49.815 INFO Scanning blocks [2137112, 2139111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:50.180 INFO Scanning blocks [2139112, 2141111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:50.519 INFO Scanning blocks [2141112, 2143111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:50.882 INFO Scanning blocks [2143112, 2145111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:51.237 INFO Scanning blocks [2145112, 2147111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:51.569 INFO Scanning blocks [2147112, 2149111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:51.904 INFO Scanning blocks [2149112, 2151111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream
graph-node_1  | Sep 15 16:18:52.263 INFO Scanning blocks [2151112, 2153111], range_size: 2000, sgd: 2, subgraph_id: QmS2ppDqbW1Lg3B2DSkd8nK51vepDgdwsuCFg7vKufntHY, component: BlockStream

IPFS hash

No response

Subgraph name or link to explorer

No response

Some information to help us out

  • Tick this box if this bug is caused by a regression found in the latest release.
  • Tick this box if this bug is specific to the hosted service.
  • I have searched the issue tracker to make sure this issue is not a duplicate.

OS information

None

@RafaDSan RafaDSan added the bug Something isn't working label Sep 15, 2023
@azf20
Copy link
Contributor

azf20 commented Sep 22, 2023

@lutter any clues? I haven't seen that "odd number of digits" error before

@lutter
Copy link
Collaborator

lutter commented Sep 27, 2023

I've never seen that before, either. I assume that it is caused by somehow having a string with a hex value in it with an odd number of digits (i.e., 0xbee instead of 0xbeef) But I have no idea how that could happen

@RafaDSan
Copy link
Author

I found the problem.

It happened when in my schema.graphql I assign id: ID! for an entity and in the mapping.ts the id is not a string.

So with the following line et id = event.transaction.hash .toHexString() .concat("-") .concat(event.logIndex.toString());

I stopped having this issue.

Now I am just getting the result as "null" tho. Any Idea why? I am stuck on this result.

@lutter @azf20

@azf20
Copy link
Contributor

azf20 commented Oct 9, 2023

ok thanks @RafaDSan - when you say Now I am just getting the result as "null" do you mean that nothing is returned when you query the subgraph?

@RafaDSan
Copy link
Author

ok thanks @RafaDSan - when you say Now I am just getting the result as "null" do you mean that nothing is returned when you query the subgraph?

@azf20 it returned like:

{ "data": { "taskCreated": null } }

But I solved the problem. I was triggering the task-created events wrong, which is why I received the null result when trying to query it.

Now it is working fine! Should I post something more about it to close the issue?

@azf20
Copy link
Contributor

azf20 commented Oct 17, 2023

Got it - glad you solved it, closing this issue

@azf20 azf20 closed this as completed Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants