Improve history and note commitment trees forking #2378
Labels
A-rust
Area: Updates to Rust code
C-enhancement
Category: This is an improvement
I-slow
Problems with performance or responsiveness
NU-3 Heartwood
Network Upgrade: Heartwood specific tasks
Motivation
ZIP-221 specifies a history tree (a Merkle Mountain Range) that is committed to in the block header. This history tree must be kept in memory/state and, when a fork happens in the non-finalized state, it must be reversed to the state it had at the tip of the fork.
The history tree was included in #2301 and it handles forks by rebuilding the history tree from the finalized state history tree. However, that can be improved since librustzcash (which we use for the tree) can handle removing nodes from the tree (though it's a bit tricky and that's why we went with the simpler option). That way we can simply remove nodes from the tree until we reach the state at the fork tip.
The same issue applies to note commitment trees.
Specifications
N/A
Designs
N/A
Solution
Use the librustzcash node removal in order to compute the history tree of the fork.
To remove a node from the tree, librustzcash requires "extra" nodes (each node corresponds to a block) which are required in order to carry out the removal. We will need to come up with an approach to load these extra nodes when required.
For note commitment trees, check if the
incrementalmerkletree
crate supports node removal (it probably does).Alternatives
Leave it as is, which will decrease performance when forks happen.
Related Work
Must be done after #2301
The text was updated successfully, but these errors were encountered: