Skip to content

fix: route the block-height and block-hash HTTP endpoints - #59

Closed
setavenger wants to merge 1 commit into
masterfrom
fix/route-block-height-and-block-hash
Closed

setavenger wants to merge 1 commit into
masterfrom
fix/route-block-height-and-block-hash

Conversation

@setavenger

@setavenger setavenger commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

GetBestBlockHeight and GetBlockHashByHeight have existed on the HTTP handler (internal/server/handler.go:45, :59) since the v2 refactor, but RunServer never registered them, so both returned 404 over HTTP. The same two calls are reachable over gRPC (internal/server/v2/service.go:59, :75), so only HTTP-only clients were affected.

Both routes are documented in the README that #30 merged — GET /block-height and GET /block-hash/:blockheight. The registrations were lost when the server moved into internal/. This restores them at those paths, so clients written against the documented API work again, and re-adds them to the endpoint list in the current README, which had dropped them too.

/block-hash/:blockheight is the piece a light client needs to handle a reorg without holding the chain: remember the hash of the last n scanned blocks, and before scanning walk backwards while the server disagrees, rolling back each block. That is the request in #29.

Scope

No handler code changed — this is two router.GET lines and two README bullets. In particular I did not reclassify the endpoints: I listed both under the existing Deprecated (JSON convenience) heading, since each mirrors a gRPC call. If you would rather /block-height sit next to /info as supported discovery, say so and I will move it.

Verification

  • go build ./... — clean.
  • go vet ./internal/server/... — clean.
  • go test ./... — internal/indexer ok, internal/types ok; every other package reports no test files. internal/server has no test suite, so nothing in the repo covers routing.
  • Because of that, I registered the full post-fix route set on a standalone gin v1.10.0 engine (the version in go.mod) and exercised it with httptest: registration does not panic, GET /block-height → 200, GET /block-hash/840000 → 200 with blockheight bound to 840000, existing routes unaffected, unknown paths still 404. That verifies the path patterns coexist without wildcard conflict; it does not exercise the real handlers.
  • Not verified: no live run against a Bitcoin Core node or a populated database. The handlers themselves are unchanged, and both read data the already-routed endpoints depend on — GetBlockHashByHeight backs /utxos, /tweaks, /spent-outputs, /compute-index and /full-block; GetChainTip backs /info — so no new data dependency is introduced. Hash byte order (ReverseBytesCopy) matches the gRPC implementation.

Refs #29


Note

Low Risk
Routing and documentation only; handler logic is unchanged and mirrors existing gRPC behavior.

Overview
Restores two documented HTTP routes that were implemented on the handler but never registered in RunServer, so GET /block-height and GET /block-hash/:blockheight had been returning 404 for HTTP-only clients while the same data remained available over gRPC.

internal/server/run.go now wires GetBestBlockHeight and GetBlockHashByHeight at those paths. The root README endpoint list again includes both under the existing Deprecated JSON convenience section, including the reorg-detection use case for block hash by height.

Reviewed by Cursor Bugbot for commit 620fcd8. Configure here.

GetBestBlockHeight and GetBlockHashByHeight have existed on the HTTP
handler since the v2 refactor but were never registered in RunServer, so
both returned 404. The same two calls are exposed over gRPC, so only
HTTP-only clients were affected.

The routes are documented in the README that #30 merged
(GET /block-height, GET /block-hash/:blockheight); the registrations were
lost when the server moved to internal/. This restores them at those
paths and re-adds them to the endpoint list in the current README.

/block-hash/:blockheight is what a client needs to detect a reorg without
holding the chain: store the hash of the last n scanned blocks and walk
back while the server disagrees. That is the request in #29.

No handler code changes. Both handlers read data the already-routed
endpoints depend on (GetBlockHashByHeight backs /utxos, /tweaks,
/spent-outputs, /compute-index and /full-block; GetChainTip backs /info),
so no new data dependency is introduced, and the hash byte order matches
the gRPC implementation.

Refs #29
@setavenger setavenger closed this Sep 19, 2026
@setavenger
setavenger deleted the fix/route-block-height-and-block-hash branch September 19, 2026 08:50
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