ethereumjs/merkle-patricia-tree

emit error on missing node

kumavis opened this issue · 10 comments

just blows up

/Users/kumavis/Development/Node/vapor-db/node_modules/merkle-patricia-tree/index.js:220
    if (node.type === 'leaf') {
            ^
TypeError: Cannot read property 'type' of null
    at processNode (/Users/kumavis/Development/Node/vapor-db/node_modules/merkle-patricia-tree/index.js:220:13)
    at /Users/kumavis/Development/Node/vapor-db/node_modules/merkle-patricia-tree/index.js:560:9
    at dispatchError (/Users/kumavis/Development/Node/vapor-db/node_modules/level/node_modules/level-packager/node_modules/levelup/lib/util.js:59:35)
    at /Users/kumavis/Development/Node/vapor-db/node_modules/level/node_modules/level-packager/node_modules/levelup/lib/levelup.js:222:14

npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/share/npm/bin/npm" "start"
npm ERR! node v0.12.0
npm ERR! npm  v2.9.1
npm ERR! code ELIFECYCLE
npm ERR! vapor-db@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the vapor-db@1.0.0 start script 'node index.js'.
npm ERR! This is most likely a problem with the vapor-db package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls vapor-db
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/kumavis/Development/Node/vapor-db/npm-debug.log

triggered by

new Trie(stateDb, '0000000000000000000000000000000000000000000000000000000000000000')
trie.createReadStream().pipe(out)

of course I dont expect that to work, but i dont expect it to crash my program either

right that won't work because the stateRoot '0000000000000000000000000000000000000000000000000000000000000000' doesn't exsist.

@kumavis do you have any opoins on the expected behavior here?

should throw an error on a non-existing state root, no?

with the exception of the empty rlp stateRoot

axic commented

Is this sorted?

no. I think we just need a better error message here

related #12

Behavior of the current state of the library is to check for correctness of the provided stateRoot value and then initialize a trie with the stateRoot as the new root. Will close here.

Example code run:

import { BaseTrie as Trie } from 'merkle-patricia-tree'
const trie = new Trie(null, Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'))
stream.on('data', (d: any) => {
  console.log(d.key.toString())
  console.log(d.value.toString())
})
stream.on('end', () => {
  console.log('The end.')
})

Feel free to reopen if I haven't understand something correctly about the issue semantics.