Add a "tx output spender" index

Adds an outpoint -> txid index, which can be used to find which transactions spent a given output.
We use a composite key with 2 parts (suggested by @romanz): hash(spent outpoint) and tx position, with an empty value.
To find the spending tx for a given outpoint, we do a prefix search (prefix being the hash of the provided outpoint), and for all keys that match this prefix
we load the tx at the position specified in the key and return it, along with the block hash, if does spend the provided outpoint.
To handle reorgs we just erase the keys computed from the removed block.

This index is extremely useful for Lightning and more generally for layer-2 protocols that rely on chains of unpublished transactions.
If enabled, this index will be used by `gettxspendingprevout` when it does not find a spending transaction in the mempool.
This commit is contained in:
sstone authored and sstone committed 2026-02-19 11:41:53 +01:00
1 parent 2706758dc3
commit 3d82ec5bdd
18 files changed
+611 -105

No files matched your search

+1 -1
View File
@@ -373,7 +373,7 @@ BASE_SCRIPTS = [
'feature_presegwit_node_upgrade.py',
'feature_settings.py',
'rpc_getdescriptorinfo.py',
'rpc_mempool_info.py',
'rpc_gettxspendingprevout.py',
'rpc_help.py',
'feature_framework_testshell.py',
'tool_rpcauth.py',