index: Add ScriptTypeIndex to track script type statistics per block #34126

pull zkokelj wants to merge 7 commits into bitcoin:master from zkokelj:ziga/script_type_index changing 7 files +508 −0
  1. zkokelj commented at 2:09 pm on December 20, 2025: none

    This PR adds a new optional index (ScriptTypeIndex) that traks statistics about script types for each block. The index maintains both the count and total value (in satoshis) of outputs for each script type per block.

    Tracking script type statistics enables analysis of Bitcoin’s UTXO set composition over time, (for example we can see addoption trends for: P2PKH, P2SH, SegWit, Taproot) and value distribution across script types.

    Implementation

    • New ScriptTypeIndex class extending BaseIndex
    • Tracks all standard script types: NONSTANDARD, P2PK, P2PKH, P2SH, MULTISIG, NULL_DATA, P2WPKH, P2WSH, P2TR
    • For each script type, tracks both output count and total sats locked
    • Disabled by default, enabled with -scripttypeindex flag

    RPC Interface

    Adds new RPC method getscripttypestats <blockhash> that returns nested objects with count and value for each script type:

    0{
    1  "nonstandard": {"count": 0, "value": 0},
    2  "p2pk": {"count": 1, "value": 5000000000},
    3  "p2pkh": {"count": 5, "value": 25000000000},
    4  ...
    5}
    

    Testing

    Unit tests included in src/test/scripttypeindex_tests.cpp:

    • Basic initial sync test
    • Test with multiple script types (P2PKH, P2SH, MULTISIG, NULL_DATA, P2WPKH, P2WSH, P2TR)

    Example output:

  2. Add ScriptTypeIndex and add it to CMakeLists f5fc26c484
  3. implement ComputeStats 0c8c1c20e9
  4. add CustomAppend + fix serialization 8fbd24be1a
  5. CustomRemove + LookupStats 34379e2428
  6. add scripttypeindex flag to enable index creation 5787fcf48d
  7. add unit tests for scripttype 51276074e5
  8. add RPC function 2a28b78f61
  9. DrahtBot added the label UTXO Db and Indexes on Dec 20, 2025
  10. DrahtBot commented at 2:09 pm on December 20, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34126.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    LLM Linter (✨ experimental)

    Possible places where equality-specific test macros should replace generic comparisons:

    • src/test/scripttypeindex_tests.cpp snippet: BOOST_CHECK(block_index != new_block_index); -> recommendation: use the inequality-specific Boost.Test macro BOOST_CHECK_NE(block_index, new_block_index) (or BOOST_REQUIRE_NE if this should be a fatal requirement) for clearer diagnostics.

    2025-12-20

  11. zkokelj closed this on Dec 20, 2025


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-29 00:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me