Skip to content

[Storehouse] 001 - Add payloadless node and trie implementation#8569

Open
zhangchiqing wants to merge 1 commit into
leo/payloadless-basefrom
leo/payloadless
Open

[Storehouse] 001 - Add payloadless node and trie implementation#8569
zhangchiqing wants to merge 1 commit into
leo/payloadless-basefrom
leo/payloadless

Conversation

@zhangchiqing

@zhangchiqing zhangchiqing commented May 30, 2026

Copy link
Copy Markdown
Member

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

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f523b99-de94-4659-924a-76ea00184fc4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leo/payloadless

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

hasValue := len(values[i]) > 0
var newLeafHash hash.Hash
if hasValue {
newLeafHash = hash.HashLeaf(hash.Hash(paths[i]), values[i])

@zhangchiqing zhangchiqing May 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PayloadlessTrieProof is copied from ledger/trie.go#TrieProof.

The difference is the Payload field is changed to LeafHash field

@zhangchiqing zhangchiqing marked this pull request as ready for review June 3, 2026 18:23
@zhangchiqing zhangchiqing requested a review from a team as a code owner June 3, 2026 18:23
@zhangchiqing zhangchiqing requested review from AlexHentschel and janezpodhostnik and removed request for a team June 3, 2026 22:41
@zhangchiqing zhangchiqing changed the title [Storehouse] Add payloadless node and trie implementation [Storehouse] Spec 001 - Add payloadless node and trie implementation Jun 8, 2026
@zhangchiqing zhangchiqing changed the title [Storehouse] Spec 001 - Add payloadless node and trie implementation [Storehouse] 001 - Add payloadless node and trie implementation Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant