Repository navigation
fix(rest): return 404 from /tx/:txid/outspend/:vout for unknown outputs - #269
Open
theluckystrike wants to merge 2 commits into
Open
theluckystrike wants to merge 2 commits into
theluckystrike wants to merge 2 commits into
Conversation
An unknown txid or an out-of-range vout returned 200 {"spent":false},
the same response as a real unspent output. Look the tx up when the
output has no spend and return 404, like GET /tx/:txid does.
Fixes Blockstream#266
Use the TxOut row (mempool, then chain) to confirm an unspent output exists, and only read the full tx from the local store on a miss. Never query bitcoind on this path, so a daemon error in light mode can't become a 404, and DB errors return 503. Add tests for mempool and OP_RETURN outputs, and for light mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #266
GET /tx/:txid/outspend/:voutreturned 200{"spent":false}for a txid that doesn't exist, and for a vout past the end of a real tx, so callers couldn't tell those apart from a real unspent output. It now returns 404Transaction not found/Output not found, likeGET /tx/:txid.This is an API behaviour change: nonexistent outputs now get a 404 instead of a 200. mempool/electrs still returns 200 here, so the two backends would differ. If you'd rather keep compatibility, I can put the 404 behind a flag.
On the unspent path the check is a point lookup of the TxOut row (mempool first, then chain). The full tx is only read from the local store on a miss. It never calls bitcoind, so in light mode a daemon error can't turn into a 404, and a DB error returns a 503.
Tests cover mempool and confirmed unspent outputs (200), an unknown txid and an out-of-range vout (404), an OP_RETURN output (200), and light mode with no getrawtransaction call.
cargo test --test rest(macOS arm64), before:after:
The new light-mode test fails on the previous version of this PR (1 extra getrawtransaction call).