-
Notifications
You must be signed in to change notification settings - Fork 992
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
[WIP] initial foray into storing optional "relative" kernels #1260
Conversation
@quentinlesceller this overlaps slightly with our need to handle versioned MMRs. |
Looking for some early feedback/comments on this approach @ignopeverell @yeastplume. |
Great job remembering the kernel will have to also sign the one it references :-) Ideally we'd store all the data together but I can't think of a way to do that that'd be better than the "extra". And the extra may be more generic and reusable overall (say to add optional data to outputs). So I'm good with the overall approach. |
956236b
to
d470d20
Compare
d470d20
to
5a39bf3
Compare
on tx_kernels (separate MMR file for optional data)
5a39bf3
to
f90d912
Compare
We may want to reference a previous kernel by its hash and not directly via the kernel excess for privacy reasons. Also the hash is 32 bytes vs 33 bytes for the excess, so the MMR of extra data would be a slightly smaller. Edit: the hash is also a lot harder to intentionally duplicate as we could take the signature into account when hashing. The excess itself can be trivially duplicated in another tx. |
This is now 6 months old and subject to a wide variety of merge conflicts. The biggest thing that came out of this work is the question around how t support variable length data in our PMMRs. Do we go with an approach like this with optional "extra" data to facilitate some limited flexibility around variable data? Or do we go further and actually support truly variable length data, presumably with variable offsets on a per position basis. I still lean toward supporting optional "extra" data, possibly in a more flexible way than proposed in this PR. i.e. A core kernel MMR containing all the required fields then support optional This would allow us to support -
And all within a set of MMR data files that all still assume fixed length data. Alternatively we could maintain a "length" associated with each data entry to account for the various optional data fields. And maybe "length" is maintained in one additional MMR data file (and not as a prefix on each entry). That way we can read the length MMR to determine how much data to read from the actual data MMR. This would allow us to read multiple values with a bit of indirection (read n lengths, calculate total length of data to read, finally read the bytes). Now that I think about this -
|
Closing this. We can always refer back to this for some context on the overall approach. |
For relative locktimes we need to be able to reference a prior kernel.
These will be optional and the vast majority of kernels will not need to reference a prior kernel.
Our MMR implementation only supports storing fixed length of bytes per entry so we cannot easily store optional data directly in the MMR.
So we will need to store "extra" data alongside the primary MMR.
I'm proposing storing these referenced kernel commitments in a data file alongside a
leaf_set
(bitmap) that represents the pos of kernels that include the optional referenced kernel commitment.So we will have something like the following -
We can determine offsets for reading the
/kernel_extra/pmmr_data.bin
via theleaf_set
.Reading/writing kernels gets a bit more complicated -
To achieve (3) the kernel MMR no longer takes kernels directly. We wrap a
TxKernel
in aTxKernelEntry
and store these in the kernel MMR (to serialize them correctly as fixed number of bytes, excluding the optional data).This is similar to how we serialize
OutputIdentifier
into the output MMR, and notOutput
directly.Why don't we do this with two full MMRs like we do with outputs and their corresponding rangeproofs?
We don't need a full MMR of hashes (the optional data is hashed into the kernel hashes themselves) so we only need a data file and a corresponding way of offsetting correctly into it.
TODO -
TxKernelEntry
and make itPMMRable
TxKernelEntry
for the kernel MMR (and not kernels directly)ExtraBackend
for optional related data (the reference kernel in this case)ExtraBackend
into the existing txhashset/kernel_mmrrewind
for the newExtraBackend
rel_kernel
through to wallet impl