Conversation
This comment has been minimized.
This comment has been minimized.
|
Great to see the tests pass here, very cool! 😄 |
holgerd77
left a comment
There was a problem hiding this comment.
To be continued...
Can also be picked up (also partially).
| - [Trie and Patricia Trie Overview](https://www.youtube.com/watch?v=jXAHLqQthKw&t=26s) | ||
|
|
||
| # EthereumJS | ||
|
|
There was a problem hiding this comment.
Did an overall README check, everything covered, examples look good as well.
| } | ||
| } | ||
|
|
||
| go() |
There was a problem hiding this comment.
Tested both manually locally, updated benchmark suites at least run through. This seems to need more work to be usable - the checkpointing benchmark file e.g. is not taking the samples into account at all e.g., think due to a bug with a reused/side-used i counter variable as far as I see it - nothing for this PR though but just as a note.
There was a problem hiding this comment.
ah thanks for pointing out, I will give it a closer look.
| "browserify": "^16.5.0", | ||
| "husky": "^4.2.3", | ||
| "karma": "^4.4.1", | ||
| "karma-chrome-launcher": "^3.1.0", |
There was a problem hiding this comment.
package.json changes look good, types from removed libraries (async) removed as well.
| "readable-stream": "^3.6.0", | ||
| "rlp": "^2.2.3", | ||
| "semaphore": ">=1.0.1" | ||
| "semaphore-async-await": "^1.5.1" |
There was a problem hiding this comment.
| * @param {Buffer|String} [root] A hex `String` or `Buffer` for the root of a previously stored trie | ||
| * @prop {Buffer} root The current root of the `trie` | ||
| * @prop {Buffer} EMPTY_TRIE_ROOT the Root for an empty trie | ||
| * @param {Buffer} [root] - A `Buffer` for the root of a previously stored trie |
There was a problem hiding this comment.
Note: significant API change here, input limited to Buffer.
| const p = stack.map((stackElem) => { | ||
| return stackElem.serialize() | ||
| }) | ||
| return p |
| // then update | ||
| await this._updateNode(key, value, remaining, stack) | ||
| } | ||
| this.lock.signal() |
There was a problem hiding this comment.
This new async/await compatible locking is really great! Generally functions like the above (put) are so much more readable now, phew! 👍
Also thanks for all the small improvements like changing execution order on conditionals, rethinking the appliance of asserts, code cleanups,... 🎊
| foundNode = decodeNode(value) | ||
| } | ||
|
|
||
| return foundNode |
holgerd77
left a comment
There was a problem hiding this comment.
To be continued... (again: can also be (partly) taken over).
| * - node - the last node found | ||
| * - keyRemainder - the remaining key nibbles not accounted for | ||
| * - stack - an array of nodes that forms the path to node we are searching for | ||
| * @param {Buffer} key - the search key |
There was a problem hiding this comment.
For the record (and the release notes): significant API change here (limitation to Buffer).
| let targetKey = bufferToNibbles(key) | ||
|
|
||
| // walk trie and process nodes | ||
| await this._walkTrie(this.root, async (nodeRef, node, keyProgress, walkController) => { |
There was a problem hiding this comment.
Inlined processNode function, ok.
|
|
||
| // Resolve if _walkTrie finishes without finding any nodes | ||
| resolve({ node: null, remaining: [], stack }) | ||
| }) |
There was a problem hiding this comment.
Rest of findPath more or less same code in a somewhat changed structural form, ok.
| * @returns {Promise} | ||
| */ | ||
| _updateNode( | ||
| async _updateNode( |
There was a problem hiding this comment.
For the record: significant API change here (limit value input to Buffer).
| } else { | ||
| resolve() | ||
| } | ||
| }) |
There was a problem hiding this comment.
Whew, this is a biggy. I have to say that I just can't follow the changes here in _walkTrie, eventually someone else can give this another look (//cc @s1na @evertonfraga) For the moment I am not getting the whole picture.
There was a problem hiding this comment.
Ok, I think I finally got the replacement constructs, can give this a go now too. 😀
| }) | ||
| async checkRoot(root: Buffer): Promise<boolean> { | ||
| const value = await this._lookupNode(root) | ||
| return !!value |
There was a problem hiding this comment.
Phew, nice. 😀
Apart from walkTrie needing a second look the rest from baseTrie.js looks good.
| await this._exitCpMode(true) | ||
| } | ||
|
|
||
| this.lock.signal() |
| let scratch = scratchDb || this._scratch | ||
| if (!scratch) { | ||
| throw new Error('No scratch found to use') | ||
| } |
There was a problem hiding this comment.
For the record: new throw on "No scratch found to use".
| let scratch = scratchDb || this._scratch | ||
| if (!scratch) { | ||
| throw new Error('No scratch found to use') | ||
| } |
|
|
||
| this._leveldb.batch(opStack, ENCODING_OPTS, cb) | ||
| async batch(opStack: BatchDBOp[]): Promise<void> { | ||
| await this._leveldb.batch(opStack, ENCODING_OPTS) |
| }) | ||
| await walkController.next() | ||
| }) | ||
| this.push(null) |
| }) | ||
| await walkController.next() | ||
| }) | ||
| this.push(null) |
| async del(key: Buffer): Promise<void> { | ||
| const hash = keccak256(key) | ||
| super.del(hash, cb) | ||
| await super.del(hash) |
| return BranchNode.fromArray(raw) | ||
| } else if (raw.length === 2) { | ||
| const nibbles = stringToNibbles(raw[0]) | ||
| const nibbles = bufferToNibbles(raw[0]) |
| await trie.commit() | ||
| t.equal(trie.isCheckpoint, false) | ||
| t.equal(trie.root.toString('hex'), root.toString('hex')) | ||
| t.end() |
| await db.batch(ops) | ||
| const res = await db.get(k2) | ||
| st.ok(v2.equals(res!)) | ||
| st.end() |
There was a problem hiding this comment.
db.spec.ts ok.
General (file unspecific) remark: the error cases in this library seem to be not very well tested, might be a field for some future improvements.
| t.equal(Object.keys(expectedNodes).length, 0) | ||
| stream.on('end', () => { | ||
| let keys = Object.keys(expectedNodes) | ||
| t.equal(keys.length, 0) |
There was a problem hiding this comment.
Rest of the tests look good. 😄
| } | ||
|
|
||
| asyncFirstSeries(getDBs, dbGet, cb) | ||
| return value |
There was a problem hiding this comment.
Leave scratch.ts also open since not seeing through. Maybe will have a look with some fresh eyes in the following days myself, too tired right now, or otherwise open for a look from someone else as well (//cc @s1na @evertonfraga).
There was a problem hiding this comment.
Ok, finally got this whole construct decomposition. Phew. 😛 Extremely valuable to have this simplified on such a level, thanks Ryan for working yourself through stuff like this. This was really over-the-top complex and extremely hard to grasp before.
holgerd77
left a comment
There was a problem hiding this comment.
LGTM. 😄
Will approve and directly merge.
| } | ||
|
|
||
| asyncFirstSeries(getDBs, dbGet, cb) | ||
| return value |
There was a problem hiding this comment.
Ok, finally got this whole construct decomposition. Phew. 😛 Extremely valuable to have this simplified on such a level, thanks Ryan for working yourself through stuff like this. This was really over-the-top complex and extremely hard to grasp before.
| } else { | ||
| resolve() | ||
| } | ||
| }) |
There was a problem hiding this comment.
Ok, I think I finally got the replacement constructs, can give this a go now too. 😀
| const childRef = node.getBranch(childIndex) | ||
| if (!childRef) { | ||
| throw new Error('Could not get branch of childIndex') | ||
| } |
There was a problem hiding this comment.
For the record: new "Could not get branch of childIndex" error thrown here.
This PR:
Closes #66
Pending TODOs:
_formatNodedoes not use theremoveparam inside the method (lost in a prior refactor?)