Trie values returning null after reboot? #2056
-
Indeed me being dense the root has to be manually restored. Maybe this could be improved by introducing a decorator like So I'm attempting to use the trie package to store some persistent data that I need to access as soon as my application launches but something seems to be amiss here, probably me being dense. I'm creating a const { SecureTrie, LevelDB } = require('@ethereumjs/trie')
const { ClassicLevel } = require('classic-level')
const level = new ClassicLevel('./db')
const root = new SecureTrie({ db: new LevelDB(level) })
async function test() {
// the first time we run this script this should be 'null'
// the second time we run this script it should be 'one' (because of the 'put' call) but it isn't
console.log(await root.get(Buffer.from('key'))) // null
await root.put(Buffer.from('key'), Buffer.from('one'))
console.log((await root.get(Buffer.from('key'))).toString()) // one
}
test() The value can be accessed directly via Level so it is in the database. I assume it's because the root is not set after relaunching so it falls back to the try {
console.log(await level.get(Buffer.from('401fb497d3e347e3d480e3137b1372491314d54a46f764e0bf00336649feb6c6', 'hex')));
} catch(e) {
console.log(e)
} I'm probably just being dense and not seeing what's wrong or is it right that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
From looking at the base |
Beta Was this translation helpful? Give feedback.
From looking at the base
trie
class constructor, you need to pass in a root hash or it defaults toKECCAK256_RLP
. There's no logic in thetrie
class for finding the previously set root in the DB at present.