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

Show helpful error when node is run on a different network but with same network name #377

Closed
timmclean opened this issue Sep 17, 2018 · 6 comments
Assignees

Comments

@timmclean
Copy link
Contributor

When the same network name (e.g. --ethereum-rpc ganache:...) is used with two different chains (e.g. two separate instances of Ganache; or one Ethereum mainnet and one testnet endpoint), the following warning will be logged:

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\")})) 
  }" 
}

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.

Discovered in #375 (comment)

Users shouldn't do this, but we should detect this mistake and show a more helpful error (and panic).

@timmclean
Copy link
Contributor Author

Detecting this isn't straightforward because we want to allow users to switch between Ethereum node addresses without resetting their database.

A few ideas for detecting this on block ingestor start-up:

  • Check if the net_version has changed but the network name is the same.
  • Ask the Ethereum node for the hash of the block at a specific (fixed) number (e.g. block 1). If the block is old enough, the hash should never change
  • Get the head block hash from database, and request that block from the Ethereum node. Detect the "Key not found in database" error. Note: unclear if we can rely on the error code being -32000, might be implementation-specific.

@timmclean
Copy link
Contributor Author

It looks like the "Key not found in database" error is Ganache-specific. The Eth RPC spec says that eth_getBlockByHash should return null if the block is not found.

@Jannis
Copy link
Contributor

Jannis commented Sep 17, 2018

A combination of the first two checks could do it. Let's use the genesis block. Would we have to store that in the network entry in the database as well for comparison?

@timmclean
Copy link
Contributor Author

timmclean commented Sep 17, 2018

Filed issue trufflesuite/ganache#906 about getting Key not found instead of null

@timmclean
Copy link
Contributor Author

@Jannis Cool. Yup, I'm picturing that would go in the ethereum_networks table. Two new columns, how about net_version and genesis_block_hash?

@Jannis
Copy link
Contributor

Jannis commented Sep 17, 2018

@timmclean Works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants