rest: add interface for gettxspendingprevout rpc

bitcoin/bitcoin: PR #33904

2 minor findings · 4 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · Mixed mempool and index results lose request order

Mixed-source REST results can reverse request order, unlike the RPC, potentially confusing positional clients; no current in-tree positional consumer was found.

Location: src/rest.cpp:991 (head).

Details and suggested fix

With -txospenderindex enabled and synced, and mempool_only omitted or false, request [A, B] where A has no mempool spender and B does. The mempool pass appends B immediately, then the index pass appends A, returning [B, A]. The RPC instead fills results by request position. REST does not explicitly document an ordering guarantee, and clients matching each object's txid/vout are unaffected. Preserve each entry's request index, fill a pre-sized result vector in both passes, and emit it in order. Add a REST assertion with the unspent or index-resolved outpoint first; the existing multi-outpoint test places the mempool hit first and misses this case.


Link

[minor] · Empty mempool_only values bypass boolean validation

?mempool_only and ?mempool_only= silently select the index-dependent default instead of returning 400; no current client sending these values was found.

Location: src/rest.cpp:933 (head).

Details and suggested fix

GetQueryParameter returns an engaged empty string for both forms. Applying value_or("") makes them indistinguishable from omission, and the empty() guard exempts them from validation. On an index-enabled node they therefore permit index lookups, whereas an empty return_spending_tx in the same handler returns 400. Keep the std::optional, apply the default only for std::nullopt, and require exactly true or false whenever the parameter is present. Add functional checks for the bare and explicitly empty forms.


Optional improvements

Link

[suggestion] · REST and RPC maintain divergent copies of the same resolver

The REST handler duplicates the RPC's mempool-then-index resolver but already differs in request-order handling, leaving two implementations of the same behavior to maintain.

Location: src/rest.cpp:955 (head).

Details and suggested fix

Extract the resolution core into a helper in rpc/mempool.{h,cpp}, following the existing sharing of MempoolToJSON and MempoolInfoToJSON. It can accept outpoints, per-entry base objects, and the two options, then return util::Expected<UniValue, ...> with an error kind so each transport retains its parsing, limits and error mapping. Passing base objects preserves the RPC's current input-object echoing. Keep results indexed by request position, including duplicate outpoints, preserve mempool precedence and all-mempool success without an index, and release the mempool lock before index synchronization. This removes the duplicated lookup and response-construction logic rather than repairing its copies independently.


Link

[suggestion] · Disabled and still-building indexes return indistinguishable 503 errors

Without an index, explicit mempool_only=false and a mempool miss produce the same 503 as an index still building, preventing clients from distinguishing a configuration error from a retryable condition.

Location: src/rest.cpp:997 (head).

Details and suggested fix

The combined guard reports both a null g_txospenderindex and incomplete initial index synchronization as “unavailable.” Retrying can help the latter, but cannot resolve the former without a configuration change. Ordinary notification lag after synchronization is handled by draining the queue, not by returning this error. Split the guard: return 400 with an “index is not enabled” message for a missing index, as the block-filter endpoints do, and retain 503 with a “still syncing” message for the initial build. Add a REST test for the disabled-index case.


Link

[suggestion] · REST tests omit no-index and mixed-source cases

The REST tests leave no-index defaults and errors, confirmed-spender hex, and reversed mixed-source ordering unchecked.

Location: test/functional/interface_rest.py:57 (head).

Details and suggested fix

All requests target node 0 with -txospenderindex=1; node 1 has neither the index nor -rest. Enable REST on node 1 and direct additional requests there, retaining the indexed tests. For the confirmed spend, assert that an omitted mempool_only returns 200 with only the queried outpoint, while explicit false reports the unavailable index, currently 503. This distinguishes the configuration-dependent default and error path in the separate REST implementation. On node 0, repeat return_spending_tx=true after confirmation and compare spendingtx with the saved hex; the current hex assertion covers only the mempool path. Also reverse the existing multi-outpoint request so the unspent entry precedes the mempool-spent entry, making its positional assertions detect source-grouped output.


Link

[suggestion] · The feature commit defers its required include to a fixup

The feature commit leaves its direct util/expected.h dependency to a later fixup, preventing independent IWYU validation as intended; no IWYU failure was observed.

Location: src/rest.cpp:40 (head).

Details and suggested fix

Commit 16823639c4d4a970b84e2e3df193ccfc3fa8b117 introduces the handler's use of the util::Expected returned by FindSpender. Commit f7c6c6630dca587400731c17bb8aa80c5383209b only adds <util/expected.h>, with its message identifying the IWYU requirement. Fold that include-only fixup into the feature commit so the feature carries its own enforced include dependency when reviewed or checked independently. This preserves the final tree; index/txospenderindex.h already supplies the definition transitively, so this is a commit-validation concern rather than a head compilation defect.


Coverage details

Earlier concerns

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