1 major finding · 1 minor finding · 3 suggestions
Earlier concerns neither republished nor resolved: 3 minor findings · 2 suggestions. See the Run archive for their assessments.
Findings
[major] · Stale script-index rows survive a restart and are read against the wrong block
After an unclean shutdown (or invalidating an uncommitted tip and restarting), a different block at the same height can leave rows whose offsets are later read inside that block. Some history queries then fail until the index is rebuilt.
Location: src/index/txoscriptindex.cpp:81 (head).
Details and suggested fix
WriteEntries stores each block's rows immediately. Each row's key is the hash prefix plus the height, and its value is the transaction offsets inside that block. BaseIndex::Commit writes the locator separately and skips the write while the index tip is ahead of the last flushed chainstate block. After an unclean shutdown, or after invalidateblock of a never-committed tip followed by a restart, Init resumes from the older locator. The block whose rows were written is then never rewound, so CustomRemove never erases them.
If a different block later occupies that height, appending it only overwrites the prefixes that block contains. Find maps each leftover row to m_chain[key.height] and deserializes the new block at the old block's offsets. Exact script-hash filtering prevents false matches. But when an offset does not land on a transaction boundary, the whole query fails with "Unable to read txoscriptindex transaction in block …". Nothing ever removes the row, so the failure persists until the index is rebuilt. The affected scripts are those paid in the replaced block but not in its replacement.
The existing height-keyed indexes store the block hash with each height row and check it in LookUpOne. Storing a short block-hash tag with each row and skipping (and overwriting) mismatched rows would make stale rows harmless, at a few bytes per row. Add a restart test with uncommitted rows and a competing block at the same height. The trigger needs one of those restart sequences plus a different block at that height; no production occurrence was established.
[minor] · A spender after the asof block is re-read once for each matched output it spends
An asof query from before a consolidation of many matched outputs deserializes the consolidating transaction repeatedly but charges it only once against the 50 MiB budget.
Location: src/rpc/blockchain.cpp:4095 (head).
Details and suggested fix
With asof, every matched output goes into unresolved_outputs. When FindSpender returns a spender confirmed after the asof block, this branch erases only the current outpoint and skips resolve_spender, the code that removes every outpoint a spender consumes. Each remaining outpoint spent by the same transaction triggers another FindSpender call. That call opens the block file and deserializes the same transaction again, while count_transaction returns early for the already-counted (block_hash, txid). A later transaction spending n matched outputs is therefore read n times but charged once, so work grows with n times its size.
This is the documented way to page a fixed snapshot of an address whose outputs were later consolidated. As a static estimate, a standard-size consolidation of about 1,400 P2WPKH inputs (about 200 kB) would be deserialized about 1,400 times. In this branch, iterate the spender's vin and erase every matching entry from unresolved_outputs without marking it spent, mirroring resolve_spender.
Optional improvements
[suggestion] · Verbosity-2 block and undo reads are not charged to the lookup budget
A history whose matches span many blocks can stay within the 50 MiB budget while forcing one full block read and one undo read per distinct block.
Location: src/rpc/blockchain.cpp:4148 (head).
Details and suggested fix
At verbosity 2, tx_to_json calls ReadBlockUndo and ReadBlock for each new block hash among non-coinbase matches and spenders, then hashes every transaction in that block to map undo positions. The cache holds only one block. None of this is charged to remaining_bytes, which otherwise covers index keys, values and candidate transactions, and which the step-4 comment describes as the bound on excessive lookups. For an address with small payments spread over many blocks, the budget allows a very large number of matches, each of which can cost a full block plus undo read.
Should these reads be charged to the budget, or capped by a separate distinct-block limit, so verbosity 2 fails with the same narrowing hint? If the budget is meant to cover only index and transaction bytes, documenting that would make the intended DoS bound explicit.
[suggestion] · Spentness check holds cs_main for one UTXO lookup per matched output
The number of lookups done under cs_main is limited only indirectly by the 50 MiB byte budget, so a heavily reused script can hold the lock across a large batch of chainstate reads.
Location: src/rpc/blockchain.cpp:4007 (head).
Details and suggested fix
Without asof, step 6 takes cs_main once and calls CoinsTip().PeekCoin for every matched output. PeekCoin does not fill the cache and falls through to the chainstate database on a miss, which is the usual case for spent outputs. The only limit is the set of outputs whose transactions fit in the byte budget: roughly one lookup per transaction-sized chunk for a reused address, and more when one transaction pays the script many times. Block connection and other cs_main users wait while this runs.
The final check already rejects the response if the tip changed. Releasing and re-acquiring cs_main every fixed number of outputs (or per match) would bound the hold time while keeping that consistency guard. The actual hold time depends on dbcache and storage and is not measured here.
[suggestion] · No release note for the new index and RPC
Users upgrading would not learn about -txoscriptindex or getscripthistory from the release notes.
Location: src/init.cpp:552 (head).
Details and suggested fix
The PR adds the -txoscriptindex startup option and the getscripthistory RPC but no doc/release-notes-36629.md. The developer notes ask for a PR-specific release note for notable new features and configuration changes. A short note describing the option, its approximate disk cost, the RPC, and its reliance on -txospenderindex for spenders and asof would cover it.
Design and approach
Extend the motivation to state which target workflows the in-tree scanblocks + getdescriptoractivity path cannot serve, with measurements. Candidates include scripthash-only Electrum queries, per-query latency of full filter scans, and pruned nodes without undo data. Also respond to the #14053 objection that a Core index serving Electrum clients adds maintainer burden. The concept candidate rated the PR worth_pursuing but said the predecessor objections could not be retrieved. PR #14053 is retrievable. Its reviewers objected that personal wallet history does not need a full index. Its author closed it because existing features and the lightweight scanblocks approach (#20664) cover the practical use cases. The checkout confirms that scanblocks and getdescriptoractivity return receive and spend activity for descriptors. The PR description does not mention them and says the only workaround is third-party software. This is an actionable motivation gap, not a rejection of the approach. Several current Concept ACKs exist, but they are not evidence on this point. 1 2
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [minor]: Bound descriptor expansion and empty index probes
- [minor]: Treat null option values as omitted
- [suggestion]: Test successful ranged-descriptor history queries
- [minor]: Check block identity when merging script lookups (earlier report)
- [suggestion]: Bound ranged-descriptor expansion and miss probes (earlier report)