-
Notifications
You must be signed in to change notification settings - Fork 39
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: compound tree enhancements #78
Conversation
Previously, a compound merkle tree could represent a single merkle tree, but it added a single node at the top layer, which is not strictly necessary and changes the root hash.
Hmmmm. I really don't think we should need three tree types. I haven't fully thought this through, but here's a sketch of how I think it could work without too much complexity.
|
Addendum, since my previous reply was simplistic. I will leave it there, though. The detail which I skipped over is the need for the upper, compound tree to have potentially mixed arities. Presumably this was the point you're trying to work through, so I apologize for addressing the wrong concerns. Taking that into account, and a few broad possibilities suggest themselves:
The second option seems better, but in both cases, there is the problem of how to deal with an arbitrary number of arities with a static type signature. One way to get around this might be to formalize our assumptions about how compound trees should work. If we do that, then the 'shape' of the compound tree is fully determined by two parameters:
However, doing this accurately might require a lot of complexity doing compile-time math with typenums, and it might not be tractable (or even possible, not sure). In practice, we will only need compound trees with one or two layers. Assuming 4GiB subtrees, that would let us handle sizes of 4GiB to 128GiB, assuming a max arity of 8. Now a compound tree just needs to know:
I think this last suggestion is probably viable within the tradeoffs involved. I would focus on trying to see whether you can make that work. If it looks problematic or you want to discuss more, feel free to ping me. |
Thanks for the input. Much of it more or less sums up how the original compound merkle tree worked, and by extension how this works. The thing that isn't clear to me is how to define a recursive type in rust, specifically. I know rust generally doesn't allow that, but it would be convenient (though not functionally superior) if there was a way to collapse the types so that 'tree/sub-tree' and 'proof/sub-proof' are somehow the same type. The approaches I've already tried used parameterization, but ultimately did not eliminate the need for some recursive type. As for the flexibility of sector size composition, I believe all of the mentioned scenarios are covered by the existing PR (i.e. this is a work in progress, but it does work). |
I think you can use a box to include self references (type) and still have a size known at compile time. |
👍 I did see that as a recommendation online, but wasn't sure it was the approach to take. I'll take a look at that. |
yes, using |
Closed in favor of #79 |
In addition to existing compound tree enhancements, this adds functionality for having aggregations of compound trees, or compound compound trees in concept (poorly named as type CCompoundMerkleTree). This is work in progress as it would be ideal to not have a CCompoundMerkleTree and instead define a recursive CompoundMerkleTree type. I spent time investigating that route yesterday and today and haven't progressed, so I'm issuing this PR for reviews/ideas/suggestions on how to better solve that problem. I believe it solves the specific issue that we're looking at regarding tree compositions, but could also be improved since the naming is at best clunky. I'll continue to think about how to address this weekend as well, as this isn't intended to be merge ready as-is.