Repository navigation
fix(grpc): end streams with NOT_FOUND at unindexed heights - #65
Open
setavenger wants to merge 1 commit into
Open
setavenger wants to merge 1 commit into
setavenger wants to merge 1 commit into
Conversation
StreamBlockScanDataShort and StreamComputeIndex answered a height the oracle has not indexed (above the tip, below the sync start, a gap, or a height > MaxUint32 that aliased to an indexed one via uint32 truncation) with an OK message carrying an empty block hash and no data. Clients read that as an indexed block without payments and skip it, silently losing funds. Both streams now end with codes.NotFound naming the height at the first unindexed height, after sending every preceding indexed block. Database errors keep their existing behaviour. GRPC.md documents the contract and advises bounding `end` by the GetInfo height. Tests cover both streams over an in-memory pebble store with a gap, below the first block, above the tip and beyond the uint32 range. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Sep 24, 2026
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.
Warning
Deploy ordering: do not deploy this to users before the blindbit-rs client fix (setavenger/blindbit-rs#20) is released. Current Rust clients call
.unwrap()on every stream message. With this change they get aNOT_FOUNDstatus instead of an OK message, so they would panic. Merge whenever you like, but release the client first.Bug
StreamBlockScanDataShortandStreamComputeIndexdid not check whether a height was indexed. For a height the oracle has not indexed,dbpebble.GetBlockHashByHeightreturns(nil, nil):pebble.ErrNotFoundis swallowed and does not come back as an error. That covers heights above the tip, below the sync start height, and gaps. The streams then sent an OK message with an empty block hash, an empty compute index and no spent outputs.A height above
MaxUint32was also cast touint32, so it wrapped around to a low height. The stream then served that other block's hash under the requested height.The Rust scanner treats such a message as an indexed block with no payments. It moves past the height and never finds the payments in it, so funds are lost without any error. The blindbit-testkit mutation check
unindexed-ok-emptyshows this loss end to end.Fix
streamBlockHash, is used by both streams. It returnsstatus.Errorf(codes.NotFound, "height %d is not indexed", height)in two cases:math.MaxUint32MaxUint32check also stops a request withendnearMaxUint64from looping forever.internal/server/GRPC.md:NOT_FOUNDnaming the height, every message before it is valid, and clients should boundendby theGetInfoheight.Tests
The new file
internal/server/v2/stream_test.gouses an in-memory pebble store and a bufconn gRPC server. Blocks are indexed at H and H+2, which leaves a gap at H+1. Its helper names differ from those in #64'shelpers_test.go.Each case below runs against both streams:
NOT_FOUNDnaming H+1NOT_FOUNDnaming H-1, no messagesNOT_FOUND, no messagesNOT_FOUNDnaming H+3NOT_FOUND; before the fix this aliased to block HRed before the fix: with the unfixed
service.go, 10 of the 14 subtests failed. Every unindexed case got OK messages with empty hashes. For example,[H, H+2]returned 3 messages with{501 []}in the middle, and2^32+Hreturned block H's hash. After the fix, all 14 pass.Verification
go build ./... && go vet ./... && go test ./...okforinternal/indexer,internal/server/v2andinternal/typesCGO_ENABLED=1 go build -tags libsecp256k1 ./... && CGO_ENABLED=1 go vet -tags libsecp256k1 ./... && CGO_ENABLED=1 go test -tags libsecp256k1 ./...golangci-lintis not installed locally, so it was not run.Overlap with #64
#64 (unmerged) makes the unary per-height RPCs return
NOT_FOUND. It leaves the streams unchanged, and its GRPC.md says the streams do not useNOT_FOUND. This PR covers the streams.Both PRs edit
internal/server/GRPC.md, so whichever merges second needs a small GRPC.md rebase:NOT_FOUNDrow in the error table should end up saying that all per-height RPCs and both streams useNOT_FOUND.There is no code conflict: this PR's helper is
streamBlockHash, and #64's isindexedBlockHash.🤖 Generated with Claude Code