tr: use stack allocation in TrSpendInfo - #1052
Open
vadim-anfv wants to merge 3 commits into
Open
vadim-anfv wants to merge 3 commits into
vadim-anfv wants to merge 3 commits into
Conversation
A `TapTree` cannot have leaves deeper than `TAPROOT_CONTROL_MAX_NODE_COUNT`, so the check never fired. An out-of-range write would panic anyway.
A `(bool, usize)` element is padded to 16 bytes on a 64-bit platform, so the array took 2 KiB. Keeping the flags in a `BitStack128` and only the indices in the array halves that to 1 KiB. There is no separate length: `BitStack128::height` is the single source of truth for both halves, so they cannot get out of sync. The array is now sized by `TAPROOT_CONTROL_MAX_NODE_COUNT` rather than a literal 128, matching the bounds check in `taptree.rs`.
Member
|
Could you squash these changes together? You can stick a 'Co-authored-by:' tag on the commit to preserve the original author's attribution. But I'd prefer that each commit be correct on its own, and having "the commit from 891" followed by "a commit that rips it up" is hard to review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Supersedes #891.
Keeps the original commit and addresses the review on top of it: the unreachable checks in
ParentStack::pushare gone, the stack is split into aBitStack128and an index array (2 KiB down to 1 KiB), andTAPROOT_CONTROL_MAX_NODE_COUNTreplaces the literal 128, here and inTrSpendInfo::leaves.No test for the maximum-depth case: the bound is enforced when the tree is built, so nothing changes for valid input. Happy to add one if you want.
pushstill takes a tuple and destructures it right away. Two parameters would read better, but that touches the call sites, so I left it out.