I agree the O(n²) cost of reading a whole witness with btck_witness_stack_get_item_at needs fixing. I'm less sure a new callback type is the best way to do it which #36909 is doing. Instead we could expose the witness's serialized bytes and let the bindings or caller decide how to decode them, this also follows the *_to_bytes functions we already have in the API.
kernel: add `btck_witness_stack_to_bytes` #36911
pull yuvicc wants to merge 2 commits into bitcoin:master from yuvicc:kernel-witness-stack-to-bytes changing 4 files +39 −0-
yuvicc commented at 5:13 AM on November 19, 2026: contributor
-
1df6615612
kernel: add btck_witness_stack_to_bytes
Expose the consensus serialization of a witness stack, so all of its items can be read in a single call.
-
test: check witness stack serialization in test_kernel 97d464fec3
- DrahtBot added the label Validation on Nov 19, 2026
-
DrahtBot commented at 5:13 AM on November 19, 2026: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
External sites
- Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36911
- Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36911.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36911#author-ralph
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline and AI policy for information on the review process. A summary of reviews will appear here.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
-
pzafonte commented at 6:58 PM on November 19, 2026: contributor
Yuvicc, thanks for putting this up. It looks like it comes down to where the items are decoded.
btck_witness_stack_get_itemsdecodes them in the kernel and returns pointers that are valid for the duration of the existence of the witness stack andbtck_witness_stack_to_bytesreturns the serialization and each binding would decode the items themselves.What I'm trying to accomplish is to make an efficient form of the design that the API already has (
btck_witness_stack_get_item_at) and to decode once in the kernel so that consumers don't need to reimplement consensus parsing.