Skip to content

Commit

Permalink
Merge pull request #93 from RainBlock/updateHash
Browse files Browse the repository at this point in the history
Update merkle node hash computation
  • Loading branch information
SoujanyaPonnapalli authored Apr 15, 2019
2 parents 4797bfc + 6a84574 commit 6ba3b01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rainblock/merkle-patricia-tree",
"version": "4.6.0",
"version": "4.7.0",
"description": "An implementation of the modified merkle patricia tree used in Ethereum, optimized for in-memory usage",
"main": "build/src/index.js",
"types": "build/src/index.d.js",
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ export class BranchNode<V> extends MerklePatriciaTreeNode<V> {
for (const [idx, branch] of this.branches.entries()) {
if (branch === undefined) {
hashedBranches[idx] = Buffer.from([]);
} else if (branch instanceof HashNode) {
hashedBranches[idx] = toBufferBE(branch.nodeHash, 32);
} else if (
branch instanceof BranchNode || (branch.nibbles.length / 2) > 30) {
// Will be >32 when RLP serialized, so just hash
Expand Down Expand Up @@ -512,7 +514,12 @@ export class ExtensionNode<V> extends MerklePatriciaTreeNode<V> {

/** @inheritdoc */
serialize(options: MerklePatriciaTreeOptions<{}, V>) {
const serialized = this.nextNode!.serialize(options);
let serialized: RlpItem;
if (this.nextNode instanceof HashNode) {
serialized = toBufferBE(this.nextNode.nodeHash, 32);
} else {
serialized = this.nextNode!.serialize(options);
}
const rlpEncodeNextNode = this.nextNode!.getRlpNodeEncoding(options);
return [
MerklePatriciaTreeNode.toBuffer(this.nibbles, this.prefix),
Expand Down

0 comments on commit 6ba3b01

Please sign in to comment.