Skip to content

UTXO cursor#176

Draft
l0rinc wants to merge 17 commits into
masterfrom
detached535
Draft

UTXO cursor#176
l0rinc wants to merge 17 commits into
masterfrom
detached535

Conversation

@l0rinc
Copy link
Copy Markdown
Owner

@l0rinc l0rinc commented May 19, 2026

No description provided.

jrakibi and others added 14 commits May 3, 2026 15:03
…HA-256 ARM intrinsics

ARM SHA256 intrinsics take state in natural order: ABCD + EFGH
(hash_abcd/hash_efgh). The code already uses that layout, only the
ABEF_SAVE/CDGH_SAVE names were wrong. Rename to ABCD_SAVE/EFGH_SAVE.
No logic change.

Docs: https://developer.arm.com/architectures/instruction-sets/intrinsics/#f:@navigationhierarchiesinstructiongroup=[Cryptography,SHA256]
Fix in original C code (Jeffrey): noloader/SHA-Intrinsics#14

-BEGIN VERIFY SCRIPT-
perl -pi -e 's/\bABEF_SAVE([AB])?\b/ABCD_SAVE$1/g' src/crypto/sha256_arm_shani.cpp
perl -pi -e 's/\bCDGH_SAVE([AB])?\b/EFGH_SAVE$1/g' src/crypto/sha256_arm_shani.cpp
-END VERIFY SCRIPT-
and cleanup some comments

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
`CalculateMaximumSignedInputSize()` is passed the outpoint being sized, but that context was not used when estimating the signed input size.
Pass the outpoint through so externally selected inputs are not underestimated.

Co-authored-by: Antoine Poinsot <darosior@protonmail.com>
Document btck_transaction_check and btck_block_check validation state output parameters as overwritten in-place. This matches their reset-on-entry behavior and avoids implying callers should preserve prior state.
…rwritten in-place

0358c26 kernel: document overwritten validation state outputs (w0xlt)

Pull request description:

  This PR updates the public kernel API documentation for validation-state output parameters that are still caller-provided:

  - `btck_transaction_check`
  - `btck_block_check`

  Both wrappers reset the supplied validation state on entry before running validation, so callers should treat the state as overwritten in-place rather than preserving prior contents.

ACKs for top commit:
  yuvicc:
    re-ACK 0358c26
  sedited:
    ACK 0358c26

Tree-SHA512: f0097c38449c09c6c614a1fb6e5fe09bc84e5dae57c0cb57540419fd6c3f40c06ce8b41e12ab2eff27f4b18d053d32aba2c4a7551a037be93d618b1734922f37
0429c50 bench: Replace Coin Selection bench (Murch)
ec1eefd bench: Remove unnecessary wallet parameter (Murch)
e6c4ffb bench: Fix type mismatch (Murch)

Pull request description:

  Adds a Coin Selection benchmark that doesn’t just test a worst case of one of the algorithms but exercises coin selection to to select inputs for a variety of different targets from a large number of UTXOs.

ACKs for top commit:
  l0rinc:
    code review ACK 0429c50
  sedited:
    ACK 0429c50

Tree-SHA512: 53238d39c8f6d543d80af77e3bb23ab418f2ee266a5ae407fd739c158ca86db553457dcc372b7aa5017f392fb5ae784394cad9edd79b1c0f58ffc32c89e0c306
…ARM intrinsics

86718e4 scripted-diff: rename ABEF_SAVE/CDGH_SAVE to ABCD_SAVE/EFGH_SAVE in SHA-256 ARM intrinsics (jrakibi)

Pull request description:

  ARM SHA256 intrinsics take state in natural order: ABCD + EFGH (hash_abcd/hash_efgh). [Documented here](https://developer.arm.com/architectures/instruction-sets/intrinsics/#f:@navigationhierarchiesinstructiongroup=[Cryptography,SHA256])
  The code already uses that layout, only the `ABEF_SAVE`/`CDGH_SAVE` names were wrong.

  Rename to `ABCD_SAVE`/`EFGH_SAVE`. No logic change.
  Fix in original C code (Jeffrey): noloader/SHA-Intrinsics#14

ACKs for top commit:
  l0rinc:
    ACK 86718e4
  sedited:
    ACK 86718e4

Tree-SHA512: 81c430343f5ee7c9f8d775aa88affb1e3ac60b5df07eac6072d2ba7b53d28c9bb62ea72eee4bc410309f6d38a8abcbb6e27be43dd57d1112b4311e83b58540cf
Co-authored-by: Antoine Poinsot <darosior@protonmail.com>
… 2500 sigops

ae73b69 test: restore assertion that tx contains exactly 2500 sigops (ismaelsadeeq)

Pull request description:

  darosior wrote bitcoin#29060 (comment):

  _This is useful documentation, plus useful in making sure the comment above the check does not become stale or incorrect._

  Hence reverted.

ACKs for top commit:
  l0rinc:
    code review ACK ae73b69
  sedited:
    ACK ae73b69
  willcl-ark:
    ACK ae73b69

Tree-SHA512: 2c76e9b66e367613c1232b65b1c18f2d0c1068acdf712ca0937dae465e637b024df95d6479f26cc5d04e5767e711eb5b3f3a329207af75ee64c7bfc8bc9173f6
…itcoin#31005)

3381855 doc: external signer: update interface, --stdin flag, IPC-command signtx, contains updates from bitcoin#33947 (Danny van Heumen)

Pull request description:

  Updates to documentation for External Signer.

  - Added mention that `signtransaction` command is no longer primary mechanism.
  - Document inter-process communication via `--stdin` flag followed with stdin-content.
  - Document `signtx` command followed by Base64-encoded PSBT.

ACKs for top commit:
  Sjors:
    ACK 3381855
  naiyoma:
    ACK 3381855

Tree-SHA512: e9c666c7a9de08a148846c8d2d1fc2905ba7ce672b7baad35fd9d7a693bfd9beae99e29134aa24282fc14d2de86bbf653ad15e167658a075d4ec9f5bcdbaabdd
cd8d3bd wallet: use outpoint when estimating input size (Lőrinc)

Pull request description:

  ### Problem
  `CalculateMaximumSignedInputSize()` is passed the outpoint being sized, but a previous refactor stopped using that context when estimating the signed input size.
  This could make externally selected inputs look slightly smaller than they really are.

  ### Fix
  Pass the outpoint through again when estimating the signed input size.
  Add a regression test for the external-input case.

  > [!NOTE]
  > the branch name still reflects the previous state of this PR, where the unused parameter was removed instead of wired back in

ACKs for top commit:
  achow101:
    ACK cd8d3bd
  pablomartin4btc:
    ACK cd8d3bd

Tree-SHA512: 6089ae65ae12677c32be0556d704f8c179f1ff5a017690846ae495644890526f85d8c0d75d4ec4c3c9ac5b519251169009484623340b8bc3a87fa9a3be27fefd
l0rinc added 3 commits May 20, 2026 21:59
scantxoutset derives the target scriptPubKeys before walking the UTXO set. Track the derived scriptPubKey lengths in a small fixed filter and skip the exact lookup for represented lengths that cannot match any requested script.

Use a fixed bitset for lengths up to 127 so the filter is heap-free and still covers the common standard scriptPubKeys, including P2WPKH, P2SH, P2PKH, P2WSH/P2TR, P2PK, and compressed bare multisig. Larger scriptPubKeys fall through to the existing exact lookup, so arbitrary scripts remain handled correctly.

By itself this is neutral for the measured broad xpub scan because many mainnet UTXOs have one of the requested standard sizes. The next commit uses this cheap guard to make hash-set exact lookups profitable for larger target sets by avoiding hash probes for impossible script sizes.

Benchmark on the local mainnet chainstate (165,399,250 UTXOs), warmup=1, runs=3, Release build:

  bitcoin-cli -rpcclienttimeout=0 -named scantxoutset action=start scanobjects='[{"desc":"combo([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)","range":1000}]'

GCC 14.2.0:
  Before: 90.724 s +/- 1.113 s
  After:  90.661 s +/- 0.980 s
  Speedup: 1.00x

Clang 22.0.0:
  Before: 109.137 s +/- 0.102 s
  After:  109.052 s +/- 1.453 s
  Speedup: 1.00x
After filtering by scriptPubKey length, exact lookup is still needed for common sizes that can match the requested descriptors. For large target sets, build an unordered set using the existing SaltedSipHasher instead of probing the ordered set for each plausible coin scriptPubKey.

Keep the ordered set as the primary lookup structure for small scans. Unconditionally hashing every plausible coin scriptPubKey was not kept because it regressed a single raw P2WPKH scan with GCC (70.886 s -> 75.802 s). The hash set is now built only for larger target sets, which covers ranged descriptor scans while leaving small address/raw-script scans on the cheaper ordered lookup path.

Benchmark on the local mainnet chainstate (165,399,250 UTXOs), warmup=1, runs=3, Release build, measured on top of the previous commit:

  bitcoin-cli -rpcclienttimeout=0 -named scantxoutset action=start scanobjects='[{"desc":"combo([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)","range":1000}]'

GCC 14.2.0:
  Before: 88.705 s +/- 0.091 s
  After:  85.684 s +/- 1.147 s
  Speedup: 1.04x

Clang 22.0.0:
  Before: 108.015 s +/- 0.860 s
  After:  102.231 s +/- 1.267 s
  Speedup: 1.06x

Additional GCC sanity check for a single raw P2WPKH script:
  Before: 71.218 s +/- 0.071 s
  After:  72.255 s +/- 1.803 s
  Speedup: 0.99x
gettxoutsetinfo with hash_type=none still needs the UTXO totals, but it does not need the per-transaction output map used to feed hash construction.

Teach the shared UTXO stats loop to apply per-coin stats directly when no hash object is requested. The hashed paths keep the existing grouping and hash finalization, while the none path avoids the map insert and clear work. The previous nullptr no-op hash overloads are removed because the hash calls are now guarded with if constexpr and leaving those overloads behind triggers unused-function warnings.

Benchmark on the local mainnet chainstate (165,399,250 UTXOs), warmup=1, runs=3, Release build:

  bitcoin-cli -rpcclienttimeout=0 -named gettxoutsetinfo hash_type=none use_index=false

GCC 14.2.0:
  Before: 89.443 s +/- 0.046 s
  After:  78.875 s +/- 0.818 s
  Speedup: 1.13x

Clang 22.0.0:
  Before: 113.896 s +/- 1.544 s
  After:   91.706 s +/- 2.715 s
  Speedup: 1.24x
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.

8 participants