Skip to content

Commit

Permalink
Include long value length in Trie#childrenSize
Browse files Browse the repository at this point in the history
  • Loading branch information
colltoaction authored and Diego López León committed Jul 5, 2019
1 parent 5eb16cc commit ce2c4b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion rskj-core/src/main/java/co/rsk/trie/NodeReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ public void serializeInto(ByteBuffer buffer) {
* Do not use.
*/
public long referenceSize() {
return getNode().map(trie -> trie.getChildrenSize().value).orElse(0L) + serializedLength();
return getNode().map(this::nodeSize).orElse(0L);
}

private long nodeSize(Trie trie) {
long externalValueLength = trie.hasLongValue() ? trie.getValueLength().intValue() : 0L;
return trie.getChildrenSize().value + externalValueLength + trie.getMessageLength();
}

public static NodeReference empty() {
Expand Down
4 changes: 2 additions & 2 deletions rskj-core/src/test/java/co/rsk/trie/TrieTreeSizeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public void childrenSizeShortValue() {
Trie trie = new Trie()
.put(new byte[]{0x00}, new byte[]{0x01})
.put(new byte[]{0x01}, new byte[32]);
Assert.assertThat(trie.getChildrenSize().value, is(37L));
Assert.assertThat(trie.getChildrenSize().value, is(35L));
}

@Test
public void childrenSizeLongValue() {
Trie trie = new Trie()
.put(new byte[]{0x00}, new byte[]{0x01})
.put(new byte[]{0x01}, new byte[33]);
Assert.assertThat(trie.getChildrenSize().value, is(40L));
Assert.assertThat(trie.getChildrenSize().value, is(71L));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public void testnetHashTest() {
RskContext rskContext = new RskTestContext(new String[]{ "--testnet" });
rskContext.getBlockchain(); // this triggers changes in the Genesis through the BlockChainLoader
Genesis genesis = rskContext.getGenesis();
assertThat(genesis.getHash(), is(new Keccak256("d72e1c76d7b4928acf9812fc3bb5bfddfd1f8d93e3a9a99894b3479a0190a9b0")));
assertThat(genesis.getHash(), is(new Keccak256("cabb7fbe88cd6d922042a32ffc08ce8b1fbb37d650b9d4e7dbfe2a7469adfa42")));
}
}

0 comments on commit ce2c4b6

Please sign in to comment.