Sitelet https://github.com/graphprotocol/graph-node/issues/377
Skip to content

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

Description

@timmclean

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).

Activity

  1. self-assigned this
    on Sep 17, 2018
  2. timmclean commented on Sep 17, 2018

    @timmclean
    ContributorAuthor

    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.
  3. timmclean commented on Sep 17, 2018

    @timmclean
    ContributorAuthor

    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.

  4. Jannis commented on Sep 17, 2018

    @Jannis
    Contributor

    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?

  5. timmclean commented on Sep 17, 2018

    @timmclean
    ContributorAuthor

    Filed issue ConsenSys-archive/ganache#906 about getting Key not found instead of null

  6. timmclean commented on Sep 17, 2018

    @timmclean
    ContributorAuthor

    @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?

  7. Jannis commented on Sep 17, 2018

    @Jannis
    Contributor

    @timmclean Works for me!

  8. ghost removed on Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions