Skip to content

ComputeUTXOStats#152

Draft
l0rinc wants to merge 3 commits into
masterfrom
detached513
Draft

ComputeUTXOStats#152
l0rinc wants to merge 3 commits into
masterfrom
detached513

Conversation

@l0rinc
Copy link
Copy Markdown
Owner

@l0rinc l0rinc commented Apr 28, 2026

No description provided.

l0rinc added 3 commits April 28, 2026 22:19
Computing gettxoutsetinfo with hash_type=none still walks the UTXO set to calculate totals, but it does not need to group outputs per transaction for hash construction.

Accumulate the same statistics directly in a nullptr hash specialization and remove the unused nullptr hash helper overloads. Strengthen the RPC functional test so the none result is compared to the hashed result minus only the hash field.

Benchmark on the local mainnet chainstate (165,155,899 UTXOs) with:

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

Before (032223f): 47.462 s +/- 0.103 s
After:               34.370 s +/- 0.073 s
Speedup:             1.38x
scantxoutset with ranged descriptors derives a bounded set of scriptPubKeys before walking the UTXO set. Keep those scripts in an unordered set using the existing SaltedSipHasher instead of probing a tree for every UTXO.

Also track the distinct derived script sizes and skip the lookup entirely when a coin's scriptPubKey length cannot match. This targets non-empty descriptor scans, including broad xpub balance scans, without changing descriptor expansion or result handling.

Benchmark on the local mainnet chainstate (165,155,899 UTXOs) with:

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

Before (20dd526b08): 50.266 s +/- 0.190 s
After:               46.402 s +/- 0.221 s
Speedup:             1.08x
The scantxoutset UTXO walk only needs each outpoint key for progress updates and for actual matches. The cursor has already cached the key internally, but the RPC loop was still copying it into a local COutPoint for every coin before checking whether it was needed.

Only fetch the key when updating progress or recording a match, and update progress on the same 8192-coin cadence used for interruption checks. This keeps scan status responsive while removing most key copies and progress atomic stores from the hot loop.

Benchmark, 165,155,899 UTXOs, warmup=1, runs=3:

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

Before: 42.177 s +/- 0.162 s

After:  40.287 s +/- 0.319 s

Speedup: 1.05x
@l0rinc l0rinc changed the title Detached513 ComputeUTXOStats Apr 30, 2026
l0rinc pushed a commit that referenced this pull request May 28, 2026
The best block locator was introduced in #152, previously created
wallets do not have these record.
l0rinc pushed a commit that referenced this pull request May 28, 2026
Pre-#152 wallets have no best block stored. Test we
can migrate them.
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.

1 participant