Merge bitcoin/bitcoin#24539: Add a "tx output spender" index

0b96b9c600 Minimize mempool lock, sync txo spender index only when and if needed (sstone)
3d82ec5bdd Add a "tx output spender" index (sstone)

Pull request description:

  This PR adds a new "tx output spender" index, which allows users to query which tx spent a given outpoint with the `gettxspendingprevout` RPC call that was added by https://github.com/bitcoin/bitcoin/pull/24408.

  Such an index would be extremely useful for Lightning, and probably for most layer-2 protocols that rely on chains of unpublished transactions.

  UPDATE: this PR is ready for review and issues have been addressed:
  - using a watch-only wallet instead would not work if there is a significant number of outpoints to watch (see https://github.com/bitcoin/bitcoin/pull/24539#issuecomment-1276595646)
  - this PR does not require `-txindex` anymore

  We use a composite key with 2 parts (suggested by romanz): hash(spent outpoint) and tx position, with an empty value. Average composite key size is 15 bytes.

  The spending tx can optionally be returned by `gettxspendingprevout` (even it `-txindex is not set`).

ACKs for top commit:
  hodlinator:
    re-ACK 0b96b9c600
  sedited:
    Re-ACK 0b96b9c600
  fjahr:
    ACK 0b96b9c600
  w0xlt:
    reACK 0b96b9c600

Tree-SHA512: 95c2c313ef4086e7d5bf1cf1a3c7b91cfe2bb1a0dcb4c9d3aa8a6e5bfde66aaca48d85a1f1251a780523c3e4356ec8a97fe6f5c7145bc6ccb6f820b26716ae01
This commit is contained in:
merge-script
2026-02-20 09:27:17 +01:00
18 changed files with 648 additions and 121 deletions

View File

@@ -55,6 +55,7 @@ Subdirectory | File(s) | Description
`blocks/` | `xor.dat` | Rolling XOR pattern for block and undo data files
`chainstate/` | LevelDB database | Blockchain state (a compact representation of all currently unspent transaction outputs (UTXOs) and metadata about the transactions they are from)
`indexes/txindex/` | LevelDB database | Transaction index; *optional*, used if `-txindex=1`
`indexes/txospenderindex/` | LevelDB database | Transaction spender index; *optional*, used if `-txospenderindex=1`
`indexes/blockfilter/basic/db/` | LevelDB database | Blockfilter index LevelDB database for the basic filtertype; *optional*, used if `-blockfilterindex=basic`
`indexes/blockfilter/basic/` | `fltrNNNNN.dat`<sup>[\[2\]](#note2)</sup> | Blockfilter index filters for the basic filtertype; *optional*, used if `-blockfilterindex=basic`
`indexes/coinstatsindex/db/` | LevelDB database | Coinstats index; *optional*, used if `-coinstatsindex=1`

View File

@@ -0,0 +1,14 @@
New settings
------------
- `-txospenderindex` enables the creation of a transaction output spender
index that, if present, will be scanned by `gettxspendingprevout` if a
spending transaction was not found in the mempool.
(#24539)
Updated RPCs
------------
- `gettxspendingprevout` has 2 new optional arguments: `mempool_only` and `return_spending_tx`.
If `mempool_only` is true it will limit scans to the mempool even if `txospenderindex` is available.
If `return_spending_tx` is true, the full spending tx will be returned.
In addition if `txospenderindex` is available and a confirmed spending transaction is found,
its block hash will be returned. (#24539)