[WIP] block height per output maintained in pmmr #580
Closed
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.
Alternative approach to solving the "coinbase maturity needs to be fork aware" issue in #559.
#215 attempts to solve this by committing to lock_heights in outputs (and revealing lock_heights in inputs).
The problem with this is discussed in #215. tl;dr introduces something like "output malleability" where a commitment can refer to multiple different output versions (on different forks).
This PR attempts to solve the issue by taking a step back and maintaining block heights in one of the sumtree pmmrs, specifically the rproof_pmmr (referred to as "witness data" here).
The rangeproof pmmr (I'm calling this witness data here, but this may not be technically correct for height info) was originally storing
NullSum
sum values (we had no need to sum anything).We can use the sums here to store block heights.
The block height for an individual output is the height of the block that produced the output.
A sum of block heights is a range, represented by
[lower_height ... upper_height]
so any non-leaf node in the pmmr maintains the range of block heights for all nodes below it.It is not immediately clear to me that this is a useful sum value. We only really care about heights for leaf nodes (outputs). But knowing the range of block heights might be useful for something for subsets of the pmmr?
To find the height of the block producing an output for a given commitment we can simply look in the rproof_pmmr at the same pos and retrieve the sum.
This has the benefit of being fully compatible with multiple forks. Whenever we rewind a pmmr and reapply blocks we rebuild the rproof_pmmr and reconstruct the necessary block heights in memory in the sumtree extension mechanism.
The block heights for the current chain are persisted in the pmmr to disk.
Summary of changes -
WitnessData
in the pmmrTODO -
This is exploratory - mainly to see if we could leverage the sumtree/pmmr to include useful information in the sum values.
I'm not taking a position on whether we should...
Thoughts? @ignopeverell @yeastplume