[Storehouse] 001 - Add payloadless node and trie implementation#8569
[Storehouse] 001 - Add payloadless node and trie implementation#8569zhangchiqing wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| hasValue := len(values[i]) > 0 | ||
| var newLeafHash hash.Hash | ||
| if hasValue { | ||
| newLeafHash = hash.HashLeaf(hash.Hash(paths[i]), values[i]) |
There was a problem hiding this comment.
leaf hash is computed here to be shared in the next if and else branches
| root *node.Node | ||
| root *Node | ||
| regCount uint64 // number of registers allocated in the trie | ||
| regSize uint64 // size of registers allocated in the trie |
There was a problem hiding this comment.
regSize is removed from the trie, because we won't be able to know the actual size. When updating an existing register, we know the new size, but we don't know the old size, so we can't update the regSize with correct value. Given that, this field is removed. Currently the regSize is used by metrics reporting only.
| // allocatedRegCountDelta and allocatedRegSizeDelta should both be 0 | ||
| return n, 0, 0, nodeHeight | ||
| // no compact leaf node from its ancester, it means we are storing a value on a new path, | ||
| n = NewLeaf(paths[0], values[0], nodeHeight) |
There was a problem hiding this comment.
Why DeepCopy is not needed here?
The original mtrie needs DeepCopy to protect the payload value slice from being mutated. But for the payloadless trie, the leaf hash is computed from the payload value (HashLeaf), so the leaf no longer reference any shared byte slices with the caller. A DeepCopy would be wasteful.
| // for retrieving the original value separately if needed. | ||
| type PayloadlessTrieProof struct { | ||
| Path Path // path | ||
| LeafHash *hash.Hash // leaf hash HashLeaf(path, value); nil for empty leaves and non-inclusion proofs |
There was a problem hiding this comment.
The PayloadlessTrieProof is copied from ledger/trie.go#TrieProof.
The difference is the Payload field is changed to LeafHash field
This PR adds the payloadless node and trie implementation. The base branch already contains a copy of the mtrie code in the payloadless package, so this PR's diff shows only the payloadless-specific changes, making review easier.
Test cases are created in #8572
Find Spec