feat(trie): Proof Rewrite: Support partial proofs#20336
Conversation
Co-authored-by: YK <chiayongkang@hotmail.com>
…pher/proof-rewrite-benches
…f-rewrite-benches
| skip_all, | ||
| fields(prefix=?sub_trie_targets.prefix), | ||
| )] | ||
| fn proof_subtrie<'a>( |
There was a problem hiding this comment.
proof_subtrie has essentially replaced the previous proof_inner implementation; proof_inner previously drove the calculation of the trie for the entire trie, now proof_subtrie drives the calculation of a single sub-trie using roughly the same logic. proof_inner instead now loops over each sub-trie and calls on proof_subtrie on each.
| // forward to 0xabc2 (because all children will have been visited already). At this | ||
| // point the target for 0xabc2 will not match the branch due to its prefix, but any of | ||
| // the other targets would, so we need to check those as well. | ||
| if lower.key.starts_with(path) { |
There was a problem hiding this comment.
i see, with min_len this basically allows should_retain to filter which nodes is sent for proof output?
i.e which nodes are already cached and what nodes are needed
There was a problem hiding this comment.
Right, we can use this to not retain nodes which are already known. In addition we are using min_len to not bother constructing portions of the trie which are already known (or not needed) in the first place.
There was a problem hiding this comment.
ahh i see, its pretty neat that this is the core and its simple 💯
yongkangc
left a comment
There was a problem hiding this comment.
LGTM! logic wise it makes sense to me and its quite minimal changes compared to what i would have expected
…6-proof-rewrite-partial-proofs
mattsse
left a comment
There was a problem hiding this comment.
cool, all of this makes sense, even for me
The key change here is the addition of the
Targettype, which wraps a B256 key to hold also amin_len. When a node's path length is less than themin_lenthen we do not retain it for that target.Given a set of Targets we then intelligently determine which sub-tries of the overall trie actually need to be computed, so we don't waste time computing portions of the trie which no target could possibly match anyway. The method for determining sub-tries is a bit complex, but is heavily documented in the code with examples; more docs/examples can be added if necessary.
The actual algorithms for building the trie from leaves+cached branches has not significantly changed, except to add boundary checks for the sub-tries.
Closes #19516