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

Problems getting blocks from Ganache #375

Closed
nenadjaja opened this issue Sep 17, 2018 · 16 comments
Closed

Problems getting blocks from Ganache #375

nenadjaja opened this issue Sep 17, 2018 · 16 comments
Assignees
Labels
bug Something isn't working chains/ethereum p3

Comments

@nenadjaja
Copy link
Contributor

nenadjaja commented Sep 17, 2018

I tried the following and all of these fail because it can't get the block from the blockchain:

Versions:
Ganache CLI v6.1.8 (ganache-core: 2.2.1)
Geth Version: 1.8.14-stable

@Jannis
Copy link
Contributor

Jannis commented Sep 17, 2018

We've received another report for Ganache:

Sep 17 15:33:40.443 WARN failed to poll for latest block: ErrorMessage { msg: "could not get block from Ethereum: Decoder error: Error(\"invalid length 1, expected a 0x-prefixed hex string with length of 40\", line: 0, column: 0)" }

being logged a lot. I'm fairly certain this particular error is specific to Ganache. When polling for the latest block in the Block Ingestor, Ganache must be returning something that we are not prepared for.

@Jannis
Copy link
Contributor

Jannis commented Sep 17, 2018

Identified one type of error:

Key not found in database

Error message

Sep 17 22:17:18.482 WARN failed to poll for latest block: ErrorMessage {
  msg: "could not get block from Ethereum: RPC error: Error {
    code: ServerError(-32000),
    message: \"Key not found in database\",
    data: Some(Object({\"stack\": String(\"NotFoundError: Key not found in database\\n    at /usr/local/lib/node_modules/ganache-cli/build/cli.node.js:2:773948\\n    at /usr/local/lib/node_modules/ganache-cli/build/cli.node.js:2:776500\\n    at /usr/local/lib/node_modules/ganache-cli/build/cli.node.js:2:748581\\n    at ReadFileContext.callback (/usr/local/lib/node_modules/ganache-cli/build/cli.node.js:2:750214)\\n    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:352:13)\"), \"name\": String(\"NotFoundError\")})) 
  }" 
}

Cause

The same network name (e.g. --ethereum-rpc ganache:...) was used with two different chains (e.g. two separate instances of Ganache; or one Ethereum mainnet and one testnet endpoint).

Why is the error thrown?

Doing this results in the Graph Node having an invalid latest block for this network. It will then get an error from Ethereum when calling eth_getBlockByHash with the hash of this block, which belongs to the previous chain but not the one in use at the time of the error.

@timmclean
Copy link
Contributor

timmclean commented Sep 17, 2018

Ahhh knew that would come up. We talked about checking for that in #168, but might be worth a new issue just for the UX improvement

Update: filed #377

@Jannis
Copy link
Contributor

Jannis commented Sep 17, 2018

Identified another type of error:

Invalid length 1, expected a 0x-prefixed hex string with length 40

Error message

 Sep 17 23:32:10.097 WARN failed to poll for latest block: ErrorMessage {
  msg: "could not get block from Ethereum: Decoder error: Error(\"invalid length 1, expected a 0x-prefixed hex string with length of 40\", line: 0, column: 0)"
}

Cause

Contract creation transactions have no to address. However, Ganache returns "to": "0x0" instead of "to": null. This causes rust-web3's deserialization of the Transaction object to fail (it has to: Option<H160>).

How to reproduce?

Set up Ganache with a migration that creates a contract or two. Make an eth_getBlockByHash request that includes transactions for a block that contains a contract creation transaction:

➜  subgraph git:(master) ✗ curl --insecure http://localhost:8545 \
                               -v \
                               -H "Content-Type: application/json" \
                               -d '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0xc9e41a85969b440b161ece21e81bc7ce01d99a5fb01c9f754d56e51614a0de54"],"id":106}'
* Rebuilt URL to: http://localhost:8545/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8545 (#0)
> POST / HTTP/1.1
> Host: localhost:8545
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 142
>
* upload completely sent off: 142 out of 142 bytes
< HTTP/1.1 200 OK
< Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: *
< Content-Type: application/json
< Date: Mon, 17 Sep 2018 22:42:09 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
{"id":106,"jsonrpc":"2.0","result":{"hash":"0xc9e41a85969b440b161ece21e81bc7ce01d99a5fb01c9f754d56e51614a0de54","nonce":"0x03","blockHash":"0xc151b5fc66c4f108f466fb3068bf0d3f09e72014d45dca8302a57cbcf558b08d","blockNumber":"0x04","transactionIndex":"0x00","from":"0xe207259495d9de39e92e8b280a85b4d845906ce6","to":"0x0","value":"0x0","gas":"0x6691b7" ...

The last line above has the incorrect "to": "0x0".

The Ethereum JSON-RPC API spec states that to should be null in case of a contract creation.

@leoyvens

This comment has been minimized.

@Jannis

This comment has been minimized.

@Jannis
Copy link
Contributor

Jannis commented Sep 17, 2018

There are two possible routes here:

  1. A fix in Ganache to return "to": null.
  2. Custom deserialization for the to field in rust-web3, translating "0x0" to None.

@leoyvens
Copy link
Collaborator

Given that Ganache is the side not conforming to the spec, I suppose the right thing to do would be to patch them.

@timmclean
Copy link
Contributor

timmclean commented Sep 17, 2018

I filed issue trufflesuite/ganache#907 in the ganache project repo about getting "to": "0x0" instead of "to": null

@fordN fordN added in progress and removed to do labels Sep 18, 2018
@Jannis Jannis assigned Jannis and unassigned fordN Sep 24, 2018
@Jannis Jannis added to do and removed in progress labels Sep 24, 2018
@Jannis Jannis changed the title Not able to get the blocks Problems getting blocks from Ganache Oct 1, 2018
@Jannis Jannis modified the milestones: ETHBerlin, ETHSanFrancisco Oct 1, 2018
@Jannis Jannis added the p3 label Oct 1, 2018
@fordN fordN added in progress and removed to do labels Oct 4, 2018
@timmclean
Copy link
Contributor

trufflesuite/ganache#907 is closed and fixed! 🎉

@Jannis Jannis assigned nenadjaja and unassigned Jannis Oct 22, 2018
@Jannis
Copy link
Contributor

Jannis commented Oct 22, 2018

@nenadjaja to revisit if Ganache works now (may need to install it from master if the fix is not in the latest release yet).

@nenadjaja
Copy link
Contributor Author

nenadjaja commented Oct 24, 2018

Ganache didn't release the fix, so I pulled the graph-cli repo and referenced to the Github graph-core in its package.json, but...
I am still getting this issue :-(
screen shot 2018-10-23 at 8 16 40 pm

@nenadjaja
Copy link
Contributor Author

nenadjaja commented Oct 24, 2018

Update - Ganache issue is fixed, but the fix is not in the latest release. To get it running locally, follow the steps:

  1. Pull ganache-core from https://github.com/trufflesuite/ganache-core
  2. Pull ganache-cli from https://github.com/trufflesuite/ganache-cli
  3. Edit package.json in your local ganache-cli to include this line: "ganache-core": "[email protected]:trufflesuite/ganache-core.git" (instead of "ganache-core": "2.2.1" under dependencies)
  4. Run npm install in both ganache-core and ganache-cli
  5. In your terminal tab access your local ganache-cli and run npm start to run the local node

Now ganache is running with the fix for this issue, and you can run graph-node with your subgraph.
NOTE: you can use this project for testing

@tsuberim
Copy link

tsuberim commented Oct 25, 2018

@nenadjaja Is it nessesry to clone both repos, since you alreay npm installed the remote repo on ganache-cli ? Also should't we take the develop branch instead of master?

@nenadjaja
Copy link
Contributor Author

nenadjaja commented Oct 29, 2018

Hi @tsuberim sorry for not responding earlier, I didn't see your comment. Yeah good point, you don't need to clone both repos, just ganache-cli. I originally cloned both, cause I pointed to my local repo for ganache-core, but that didn't work (I was running into npm install issues).
And yes, I am using the develop branch :)

@nenadjaja
Copy link
Contributor Author

nenadjaja commented Nov 19, 2018

Tested with the following:

  • new Ganache CLI release: ganache-cli 6.2.1 that's using ganache-core version 2.3.1
  • Our hackathon-scaffold project with "@graphprotocol/graph-cli": "^0.4.1" and "@graphprotocol/graph-ts": "^0.4.1"

This issue is fixed and can't be reproduced anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chains/ethereum p3
Projects
None yet
Development

No branches or pull requests

6 participants