Skip to content

fix(grpc): NOT_FOUND for unindexed heights; document real FullTxItem byte order - #64

Open
setavenger wants to merge 1 commit into
integrationfrom
fix/grpc-contract-full-block-and-not-found
Open

setavenger wants to merge 1 commit into
integrationfrom
fix/grpc-contract-full-block-and-not-found

Conversation

@setavenger

Copy link
Copy Markdown
Owner

Summary

Two gRPC contract mismatches found while building the testkit's fake oracle, which copies this server's behaviour.

1. FullTxItem.inputs byte order: docs fixed, wire unchanged

prev txid prev vout
Server emits (internal/database/dbpebble/store.go:280, internal/server/v2/service.go:333) display order (internal PreviousOutPoint.Hash reversed) big-endian
GRPC.md (before) "little-endian (reversed from raw)" little-endian
blindbit-lib Go, pins 1a34ab6 and b921ae3 (= current master) not read. scannerv2/verifyoutputs.go reads only Txid/Utxos not read
blindbit-desktop not read (no GetFullBlock caller) not read
blindbit-rs blindbit-lib/src/scanner/utils.rs construct_dummy_tx parsed as internal order (wrong) parsed as little-endian (wrong)
testkit fake oracle display order big-endian

No live consumer decodes inputs. The Rust parser is wrong on both fields, but the result has no effect: the decoded inputs only feed the dummy transaction's compute_txid() inside bdk_sp::receive::scan_txouts, and scan_transaction_full then replaces that txid with item.txid. scan_transaction_full also has no production caller. Changing the wire would be a silent breaking change for no benefit, so this PR corrects GRPC.md to match the server. The txid/hash conventions are relabelled from "little-endian" to "display order", because the old label is what misled the Rust parser. inputs is also documented as covering only inputs that spend P2TR outputs (internal/indexer/builder.go:496). A new test pins the encoding with a vout (0x00000102) whose two byte orders differ.

2. Unindexed height: now NOT_FOUND for unary RPCs

Before this PR, GetFullBlock, GetSpentOutputsShort and GetBlockHashByHeight answered an unindexed height with OK, an empty block hash and empty data. A client could not tell that apart from an indexed block with no payments. A height above 2^32 was also truncated and silently served a lower block. These RPCs now return codes.NotFound, as GRPC.md already said, and return Internal on database errors.

Consumer check: none of blindbit-lib (both pins), blindbit-desktop or blindbit-rs branches on a status code or on an empty-hash response.

  • GetFullBlock is only called with heights the oracle itself just streamed.
  • friglet's resolve_block_hash already turns an empty hash into an error.
  • GetSpentOutputsShort has no callers.

The streaming RPCs are deliberately unchanged. The Rust scanner calls stream.message().await.unwrap() (blindbit-lib/src/scanner/scanning.rs:95), so a mid-stream NOT_FOUND for a range that starts below the sync height would panic it. GRPC.md now documents what the streams actually do (an empty message for an unindexed height), and a test pins that behaviour.

Verification

Tests use in-memory pebble plus bufconn gRPC (internal/server/v2/service_test.go):

  • go build ./... && go vet ./... && go test ./...: all ok. The same with -tags libsecp256k1 and CGO_ENABLED=1: all ok.
  • Mutation checks: reverting service.go makes the NOT_FOUND test fail on all 9 RPC×height cases. Switching be32 to little-endian makes the wire-encoding test fail.

🤖 Generated with Claude Code

…byte order

Unary per-height RPCs (GetFullBlock, GetSpentOutputsShort,
GetBlockHashByHeight) answered an unindexed height with OK, an empty block
hash and empty data - indistinguishable from an indexed block with nothing
in it. They now return codes.NotFound, as GRPC.md already documented.
Heights above uint32 no longer alias onto a lower height. No consumer
branches on the old behaviour; the streaming RPCs are left unchanged
because live clients abort a range scan on a mid-stream error.

GRPC.md described FullTxItem.inputs outpoints as little-endian txid and
vout. The server emits display-order txids and a big-endian vout. No live
consumer decodes the field, so the docs are corrected rather than the
wire changed. A test pins the encoding.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant