Review report

core: PR #36629

1 major finding · 2 minor findings · 4 suggestions

Earlier concerns neither republished nor resolved: 2 minor findings · 2 suggestions. See the Run archive for their assessments.

Findings

Link

[major] · Stale script-index rows survive restart and address the wrong block

Rows beyond the committed locator can survive a restart onto a competing block and make otherwise-synced script-history queries fail persistently.

Location: src/index/txoscriptindex.cpp:81 (head).

Details and suggested fix

WriteEntries persists each block's prefix-and-height rows separately from the locator. BaseIndex::Commit can leave that locator behind the written rows, and initialization restores only the locator. An unclean shutdown can therefore forget rows for block A. Invalidating an uncommitted tip A and restarting before another block connects can do the same, since disconnects do not rewind the index immediately. When replacement block B connects at that height, it overwrites only its own prefixes. Find applies an A-only row's offsets to B, and a malformed transaction read fails before exact-script filtering can discard it. Depending on B's layout, the selected range then keeps failing across ordinary restarts even though the index reports synced; rebuilding the index restores it. Store the originating block hash with each row and skip mismatches before reading offsets, following the other height-keyed indexes. Add a restart regression that queries an A-only script after replacement. No production occurrence of either sequence was established.


Link

[minor] · Post-asof consolidations are re-read for every selected input

An asof query from before a consolidation deserializes the consolidating transaction once per selected input, but charges its body only once against the 50 MiB budget.

Location: src/rpc/blockchain.cpp:4097 (head).

Details and suggested fix

With both indexes enabled, an asof query puts every spendable selected output into unresolved_outputs. When its spender is confirmed after the selected block, this branch erases only the current outpoint and skips the helper that removes all inputs of an accepted spender. Each remaining selected input of that consolidation therefore triggers another FindSpender call, reopening and deserializing the transaction and scanning its inputs. For n selected inputs, parsing repeats n times and the input scans perform quadratic work, while count_transaction charges the body only once. This also happens with include_spending_transactions=false, because historical queries still resolve spentness. In the rejection branch, erase every matching spender input from unresolved_outputs without marking those outputs spent. Add a regression that consolidates many selected outputs after the asof block.


Link

[minor] · Explicit null options fail instead of taking their defaults

Null height and boolean options raise type errors, while range:null counts as an explicit range, unlike the handler's treatment of asof:null.

Location: src/rpc/blockchain.cpp:3875 (head).

Details and suggested fix

RPCTypeCheckObj accepts null option values, but exists() then sends null heights and booleans to getInt or get_bool. For example, {"start_height": null} fails instead of using zero. Likewise, range:null rejects an address or scripthash query as though a range had been supplied. This differs from asof, which treats null as omitted, and from the documented RPC convention that missing and null arguments take the same defaults. Use isNull() to detect unspecified options, including has_range, and test null values against omitted values.


Optional improvements

Link

[suggestion] · Verbose response memory is outside the 50 MiB read budget

At verbosity 1 and 2, complete transactions expand into uncharged nested JSON objects, so response memory can greatly exceed the serialized read budget.

Location: src/rpc/blockchain.cpp:3679 (head).

Details and suggested fix

MAX_HISTORY_BYTES accounts for serialized reads, not the response being built. Verbose serialization expands every input and output, including unrelated outputs, into nested UniValue objects and retains the transaction hex. A 9–10 byte output becomes multiple objects with string keys and values, and annotation temporarily copies each transaction's decoded vout array. Histories with many tiny outputs can therefore amplify memory well beyond the read budget. A third party can shape such history by paying the queried script, but would need to confirm on the order of tens of MiB of data, and the operator controls verbosity and range; peak memory and any exhaustion remain unmeasured. Account for estimated per-vin/vout expansion at verbose levels in addition to serialized reads, while retaining the documented full-transaction response.


Link

[suggestion] · Successful ranged and multipath descriptor queries lack coverage

The functional test does not exercise range forwarding or receive/change expansion, although ranged xpub history is a stated feature.

Location: test/functional/rpc_getscripthistory.py:435 (head).

Details and suggested fix

The successful descriptor checks use MiniWallet's fixed raw() descriptor, addr(), and fixed combo(pubkey). Every explicit range is a rejection case, so dropping scan_object.pushKV("range", ...) would not affect those assertions. Fund derived scripts inside and outside a small nonzero [begin,end] range on both branches of a <0;1>/* descriptor. Compare the aggregate history with the union of per-scripthash queries. Include one transaction paying two derived scripts and check its merged output indexes as well as its txid. This would cover forwarding, inclusive bounds, and retention of both branches.


Link

[suggestion] · Verbose tests do not check annotations on unrelated outputs

Annotating every verbose output, or using matching-list position instead of output index, would escape the current assertions.

Location: test/functional/rpc_getscripthistory.py:254 (head).

Details and suggested fix

The help limits spentness annotations to matching outputs, and the handler currently uses output.index correctly. test_transaction_order_and_shared_spenders already creates the distinguishing fixture: unrelated output 0 and matching outputs 1 and 2. However, it queries only verbosity 0, while assert_output_status checks only the requested output. Reuse this fixture at verbosity 1 and 2. Assert that the complete vout indexes are [0, 1, 2], outputs 1 and 2 have the expected spent and spending_txid, and output 0 has neither field.


Link

[suggestion] · Long script-history lookups ignore RPC shutdown

The per-hash lookup loop and Find never check RPC interruption, so shutdown waits for an in-flight large query to finish.

Location: src/rpc/blockchain.cpp:3987 (head).

Details and suggested fix

A ranged descriptor can cover a million derivation positions, followed by a Find seek for each distinct script hash, and heavy histories can consume the 50 MiB read budget through random block-file reads. Neither the per-hash loop nor Find checks RPC interruption. StopHTTPServer waits for its workers, so an in-flight query delays shutdown until its work finishes. Call node.rpc_interruption_point() between script hashes, as scanblocks does between chunks, and pass an interruption callback into Find for its iterator loop. This lets shutdown cancel the lookups without changing successful results.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.