txindex: allow running in pruned mode #36002

pull andrewtoth wants to merge 4 commits into bitcoin:master from andrewtoth:txindex-prune changing 16 files +263 −70
  1. andrewtoth commented at 12:01 AM on August 18, 2026: contributor

    After #35531, each txindex entry now points to the block hash containing the tx instead of the file location of the block. The block hash is then used to find the file position of the block to read the tx from. This allows us to determine the hash of the containing block even if the block is later pruned, and also determine the location of the block on disk if it is later downloaded again via getblockfrompeer.

    This PR enables maintaining a txindex while pruned. If a txid lookup tries to read a tx from a pruned block, the hash of the missing block is surfaced to the caller.

    If desired, a user may call getblockfrompeer using the returned hash to download the block, then try again successfully. The downloaded block will be added to the front of the block queue, so won't be pruned again for at least 288 blocks. Of course a larger prune setting is desired if lots of historical blocks will be read, and there are privacy issues if the user is looking up their own transactions. Ideally the blocks can be fetched from a trusted node or from random peers with decoy blocks fetched occasionally.

  2. txindex: allow prune mode when there are no legacy entries 6def25bc6c
  3. DrahtBot commented at 12:01 AM on August 18, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK l0rinc

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34729 (Reduce log noise by ajtowns)
    • #34132 (coins,dbwrapper: remove error catcher, make point-read failures fatal by l0rinc)
    • #31260 (scripted-diff: Type-safe settings retrieval by ryanofsky)
    • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. txindex: return pruned block hashes from FindTx
    FindTx now returns a TxLookupResult so callers can distinguish a
    missing transaction from one that may only be in pruned blocks.
    0507ac4bfa
  5. rpc: report pruned blocks from GetTransaction
    getrawtransaction, gettxoutproof, and REST /tx now fail with an error
    naming the candidate block(s) when a txindex lookup only matches pruned
    blocks. getrawtransaction verbosity 2 omits fee and prevout when undo
    data is unavailable instead of throwing.
    
    A caller can call getblockfrompeer with the candidate block hashes and try again.
    5357c76d11
  6. test: cover txindex lookups of pruned blocks
    Extend the prune+txindex functional test to check that
    getrawtransaction, gettxoutproof, and REST /tx name the pruned block,
    and that utxoupdatepsbt skips those previous transactions until the
    block is fetched.
    6abdd0ce00
  7. andrewtoth force-pushed on Aug 18, 2026
  8. DrahtBot added the label CI failed on Aug 18, 2026
  9. DrahtBot commented at 12:14 AM on August 18, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/32082864144/job/95549090994</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU reported an include issue (“Failure generated from IWYU”) in src/index/txindex.cpp.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  10. l0rinc commented at 12:20 AM on August 18, 2026: contributor

    Big concept ACK \:D/

  11. DrahtBot removed the label CI failed on Aug 18, 2026

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: 2026-08-19 11:51 UTC

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