fix(trie): use direct Merkle value for database keys
Changes
The problem is as follows in this example.
For a node A encoding to {1, 2}, its database key is {0, 0, 0, ..., 1, 2}. Another node B with > 32B encoding could (unlikely but still) hash to the same value {0, 0, 0, ..., 1, 2} as for A and that would conflict in the database.
The solution is to NOT force the database key to be 32B always, and to keep it plainly as the Merkle value of the node (32B or less). This should also occupy less space in the database eventually.
- Storage KV database node key has now the length of the Merkle value and is no longer forced to 32B
- Renaming
XXXHashesSettoXXXMerkleValuessince it's not just hashes - Renaming
deletedKeystodeletedMerkleValueToBlockNumberindot/state - Renaming methods
XXXNodeHashestoXXXMerkleValues
Tests
go test -tags integration github.com/ChainSafe/gossamer
Issues
Primary Reviewer
@timwu20
Codecov Report
Merging #2725 (c304159) into development (9dc11e4) will decrease coverage by
0.10%. The diff coverage is50.00%.
Additional details and impacted files
@@ Coverage Diff @@
## development #2725 +/- ##
===============================================
- Coverage 63.45% 63.34% -0.11%
===============================================
Files 217 217
Lines 27059 27058 -1
===============================================
- Hits 17170 17141 -29
- Misses 8327 8352 +25
- Partials 1562 1565 +3
It's enforced that the node value <= 32B yes? Seems like but just wanted to double check
It's enforced that the node value <= 32B yes? Seems like but just wanted to double check
The Merkle value is <= 32B (node scale encoding if it is smaller than 32B, otherwise the 32B blake2b hash digest of the node scale encoding)
Just looked at this. Great work!
:tada: This PR is included in version 0.7.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket: