Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Christmas trie #236

Merged
merged 5 commits into from Dec 29, 2022
Merged

Christmas trie #236

merged 5 commits into from Dec 29, 2022

Conversation

rameight
Copy link
Contributor

@rameight rameight commented Dec 21, 2022

Dedicated hasher/committer

The previous hasher.go, was a generic implementation which was used by both Commit and Hash. It does a
couple of things:

  • Walk the un-hashed / dirty trie towards the leafs,
  • Hash the tree on the return path,
  • Create one new shadow-trie containing the new hashes, cached, which will replace the old root,
  • Create one new collapsed-trie containing the hashing-preimages, which is incrementally used to create higher order hash values.
  • Call store, if commit is being performed, to send nodes to the database, and also to the onleaf handler (for Commit)

This means that for every Hash or Commit, every processed node was duplicated twice, using copy. When I split this in two, it was possible to remove a lot of redundant allocs.

Commit

The Commit operation is basically read-only, with the exception of setting the dirty-flag to false.

  • This means that we can skip the whole 'create-new-shadow-tree-for-new-root' creation, and cut allocs in half.
  • We very seldon need to do any hashing in Commit (but sometimes still do), we can skip rlp-encoding most of the times.
  • The database insertion path needs the size of a node for tracking purposes, but that can be estimated instead
  • of calculated strictly.
  • Sending items to onleaf and db has been split off into a separate thread, and instead this PR send those tasks via a channel.

This commit update the trie package to commit 5a9c96454e04673124eedf681ae3aa0a58ffc843 of go-thereum.

@rameight rameight linked an issue Dec 21, 2022 that may be closed by this pull request
@rameight rameight changed the title trie: handle removing the freshest node too Update trie package Dec 22, 2022
@rameight rameight removed a link to an issue Dec 22, 2022
@rameight rameight linked an issue Dec 22, 2022 that may be closed by this pull request
3 tasks
* core/state: minor optimization in state onleaf allocation
* trie: implement dedicated committer and hasher
* trie: use dedicated committer/hasher
* trie: linter nitpicks
* core/state, trie: avoid unnecessary storage trie load+commit
* trie: review feedback, mainly docs + minor changes
* trie: start deprecating old hasher
* trie: fix misspell+lint
* trie: deprecate hasher.go, make proof framework use new hasher
* trie: rename pure_committer/hasher to committer/hasher
* trie, core/state: fix review concerns
* trie: more review concerns
* trie: make commit collapse into hashnode, don't touch dirtyness
* trie: goimports fixes
* trie: remove panics
@rameight rameight changed the title Update trie package Update trie: Christmas Trie Dec 26, 2022
@rameight rameight mentioned this pull request Dec 27, 2022
@rameight rameight changed the title Update trie: Christmas Trie Christmas trie Dec 27, 2022
@trinhdn97
Copy link
Contributor

We should separate the Iterator interface and implementation of the key-value DB into another PR, not to mess with the trie stuffs.
Also I haven't figured out how it's relevant to the trie package updates. Could you clarify why we need to implement the new methods of Iterator?

@rameight
Copy link
Contributor Author

rameight commented Dec 29, 2022

We should separate the Iterator interface and implementation of the key-value DB into another PR, not to mess with the trie stuffs.

I will do that in next PRs. Thanks

Also I haven't figured out how it's relevant to the trie package updates. Could you clarify why we need to implement the new methods of Iterator?

The changes of Iterator in kai/kaidb is irrelevant to trie changes. I just want to update the kaidb to the corresponding version which we have in Ethereum at the time of "Christmas Trie" PR was made. Next time, I'll split PRs to avoid confusion.

@rameight rameight merged commit ea36ade into kardiachain:master Dec 29, 2022
@rameight rameight mentioned this pull request Dec 29, 2022
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.

Optimize & Improve Trie, Preparing for state trie pruner
3 participants