Skip to content

tr: use stack allocation in TrSpendInfo - #1052

Open
vadim-anfv wants to merge 3 commits into
rust-bitcoin:masterfrom
vadim-anfv:refactor/tr-spend-info-stack
Open

vadim-anfv wants to merge 3 commits into
rust-bitcoin:masterfrom
vadim-anfv:refactor/tr-spend-info-stack

Conversation

@vadim-anfv

Copy link
Copy Markdown
Contributor

Supersedes #891.

Keeps the original commit and addresses the review on top of it: the unreachable checks in ParentStack::push are gone, the stack is split into a BitStack128 and an index array (2 KiB down to 1 KiB), and TAPROOT_CONTROL_MAX_NODE_COUNT replaces the literal 128, here and in TrSpendInfo::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.

push still takes a tuple and destructures it right away. Two parameters would read better, but that touches the call sites, so I left it out.

lmorett1 and others added 3 commits September 23, 2026 21:43
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`.
@apoelstra

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants