Ganache-cli: TypeError: Cannot read property 'pop' of undefined when restarting from existing `--db`

Created on 26 Nov 2018  路  8Comments  路  Source: trufflesuite/ganache-cli

Expected Behavior

Ganache should behave exactly the same after restarting from an existing db as if it were not restarted at all.

Current Behavior

ganache-cli does not behave the same when starting from an existing db directory. It wrongly rejects a transaction with correct nonce and crashes when given the nonce it (wrongly) expects.

Steps to Reproduce (for bugs)

  1. git clone https://github.com/tsuberim/ganache-bug.git
  2. npm install
  3. npm run ganache - start ganache command in one terminal tab for the first time (creating db directory ./asdf)
  4. node crash.js - run a simple script in another tab sending 1 ether to an account.
  5. Stop ganache.
  6. npm run ganache - start ganache again (now using existing db).
  7. node crash.js - run simple script again.
  8. The script fails with:
    Error: Returned error: the tx doesn't have the correct nonce. account has nonce of: 0 tx has nonce of: 1 at Object.ErrorResponse (/home/tsuberim/projects/ganache-test/node_modules/web3-core-helpers/src/errors.js:29:16) at /home/tsuberim/projects/ganache-test/node_modules/web3-core-requestmanager/src/index.js:140:36 at XMLHttpRequest.request.onreadystatechange (/home/tsuberim/projects/ganache-test/node_modules/web3-providers-http/src/index.js:91:13) at XMLHttpRequestEventTarget.dispatchEvent (/home/tsuberim/projects/ganache-test/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22) at XMLHttpRequest._setReadyState (/home/tsuberim/projects/ganache-test/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14) at XMLHttpRequest._onHttpResponseEnd (/home/tsuberim/projects/ganache-test/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14) at IncomingMessage.<anonymous> (/home/tsuberim/projects/ganache-test/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61) at IncomingMessage.emit (events.js:187:15) at endReadableNT (_stream_readable.js:1094:12) at process._tickCallback (internal/process/next_tick.js:63:19)
  9. If using nonce: 0, ganache fails with:
    TypeError: Cannot read property 'pop' of undefined at CheckpointTrie.Trie._updateNode (/home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:360:24) at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:107:16 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:461:14 at processNode (/home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:471:23) at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:457:5 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:180:7 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/util.js:75:7 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:52:16 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:269:32 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:44:16 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/util.js:71:7 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:157:9 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/lib/database/levelupobjectadapter.js:41:16 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/level-sublevel/shell.js:101:15 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/level-sublevel/nut.js:121:19 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/encoding-down/index.js:51:21 at /home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/node_modules/cachedown/index.js:58:21 at ReadFileContext.callback (/home/tsuberim/projects/ganache-test/node_modules/ganache-cli/node_modules/ganache-core/lib/database/filedown.js:26:14) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:235:13)

Note: The script succeeds when not restarting ganache midway.

Your Environment

  • Version used: Ganache CLI v6.2.3 (ganache-core: 2.3.1)
  • Version of Truffle/Remix/Other tools used: [email protected]
  • NodeJS Version: v10.13.0
  • Operating System and version (include distro if Linux):
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic
  • Link to your project or repro gist: https://github.com/tsuberim/ganache-bug
  • Commit hash to use with above link for reproduction: 606cccd494479e88f25cfbb22cd683d842e61b27
  • I intend to submit a pull request to fix this issue: [ ]
bug priority-high

Most helpful comment

Fix for this inbound. Was a silly mistake that resulted in a rather hard to diagnose error.

All 8 comments

I think I encountered the same problem when using --blockTime.

$ mkdir ganache-db
$ ganache-cli --db ganache-db --blockTime 1
# Quit the process CTRL-C
$ ganache-cli --db ganache-db --blockTime 1

The first launch works correctly, but when launching the second time I get the usual output and then, after 1 second:

TypeError: Cannot read property 'pop' of undefined
    at CheckpointTrie.Trie._updateNode (/Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:360:24)
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:107:16
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:461:14
    at processNode (/Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:471:23)
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:457:5
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:180:7
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/util.js:75:7
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:52:16
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:269:32
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:44:16
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/util.js:71:7
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:157:9
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/lib/database/levelupobjectadapter.js:41:16
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/level-sublevel/shell.js:101:15
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/level-sublevel/nut.js:121:19
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/encoding-down/index.js:51:21
    at /Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/node_modules/cachedown/index.js:58:21
    at ReadFileContext.callback (/Users/koirikivi/.nvm/versions/node/v8.11.2/lib/node_modules/ganache-cli/node_modules/ganache-core/lib/database/filedown.js:26:14)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)

This happens with at least the following ganache versions:

  • Ganache CLI v6.2.3 (ganache-core: 2.3.1).
  • Ganache CLI v6.2.0 (ganache-core: 2.3.0)

Doesn't happen with 6.1.8.

My OS is macOS High Sierra 10.13.5 (17F77) and nodejs v8.11.2 if that matters. Installing ganache with npm install -g ganache-cli@<insert version>.

@tsuberim, @koirikivi. Thanks for the info! I'll try to track this issue down today.

@tsuberim and @koirikivi Thanks for reporting this issue. I was able to confirm the crashes and will look into a fix soon.

This seems to be a duplicate of #407 - let's track this fix over there.

Apologies, I spoke too soon on this issue, it's not a dupe of #407.

Leaving this issue open until we have a fix, but we've reverted the change which causes this problem.

Fix for this inbound. Was a silly mistake that resulted in a rather hard to diagnose error.

I'm getting this error on ganache-cli v6.12.1 on Node v15.4.0
the command I'm using is:

ganache-cli -d --db ./blockchain/db -i 1 --accounts 700 --deterministic -l 1000000000000000 -e 10000000 -g 1500000 -q --mnemonic="MY MNEMONIC"

the error:

TypeError: cannot read property 'pop' of undefined at e.value (/FULL/PATH/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:219266)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SCBuergel picture SCBuergel  路  5Comments

axic picture axic  路  5Comments

DavidKuennen picture DavidKuennen  路  4Comments

lastperson picture lastperson  路  4Comments

dekz picture dekz  路  5Comments