Repository navigation
merkle: skip the leaf fetch when the read value identifies the leaf - #950
Draft
citizen-stig wants to merge 1 commit into
Draft
citizen-stig wants to merge 1 commit into
citizen-stig wants to merge 1 commit into
Conversation
…fetch Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
Author
|
breaking API and concern for ZK security |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During the merkle update, every key's seek ends with a beatree fetch of the terminal leaf's key and value hash. For a key the caller read and passed to
Session::finishasRead(Some(v))orReadThenWrite(Some(v), _), that data is already known: if the terminal leaf ishash_leaf(key, hash(v)), it is this key's own leaf. This PR resolves it without I/O in that case.Changes
merkle::KeyReadWrite::ReadandReadThenWritenow carry the hash of the read value.nomt::KeyReadWrite::to_compactcomputes it next to the written value hash. The actuals are not modified, so the rollback delta still sees the read values, whether or not it is finalized before compaction.Seeker::pushtakes an optionalknown_value_hash. The merkle range workers pass the read value hash. Warm-up andprovepassNone.RequestState::resolve_leafcomparesH::hash_leaf(LeafData { key, known_value_hash })with the node. If they match, the request completes with that leaf data. Otherwise, or with no known value, it falls back to the existingbegin_leaf_fetch.The public API doesn't change. A matching leaf hash commits to exactly the key and value hash that a fetch would return, so the seek result (and the witness) is the same. A key that was absent, or a read value that doesn't match the trie, falls back to the normal fetch.
Trade-off: read values are now hashed in
Session::finishon the calling thread, which used to hash only written values. #951 spreads that hashing across threads.Performance impact
TODO: to be filled in after benchmarking.