fix: consolidate CometBFT RPC response parsing (Alpha P2)#60
Merged
Conversation
…pe bug
CometBFT HTTP RPC endpoints return responses wrapped in a JSON-RPC
envelope: {"jsonrpc":"2.0","id":-1,"result":{...}}. Four independent
parsing sites in the codebase disagreed about whether this wrapper
existed, causing silent failures in production:
- tasks/statesync.go: missing wrapper → "empty block hash" error
- rpc/status.go: missing wrapper → LatestHeight() always returned 0
- tasks/result_export.go: missing wrapper → exporter retried forever
- shadow/layer0.go + layer1.go: correctly included wrapper
This commit introduces a single rpc.Client that strips the envelope
once via Get(), with GetRaw() for archival paths. All four sites now
use the shared client and canonical response types from rpc/types.go.
Additional fixes from Tide review:
- Handle JSON-RPC error responses (surface CometBFT error messages)
- Configurable timeout via SetTimeout(); StatusClient uses 500ms
(matching original) while other paths keep 10s default
- All test mocks now use full JSON-RPC envelopes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bdchatham
added a commit
that referenced
this pull request
Apr 3, 2026
PR #60 assumed all CometBFT RPC endpoints return JSON-RPC envelopes ({"jsonrpc":"2.0","result":{...}}), but seid's CometBFT fork returns flat JSON ({"node_info":{...}}). This caused Client.Get() to return "empty result" for all seid queries, breaking peer discovery and await-condition height polling. Fix Client.Get() to handle both formats: if the response has a "result" key, unwrap it (standard CometBFT); otherwise return the body as-is (seid flat format). Also add logging in peer discovery when instances are found but unreachable, preventing silent failures. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
bdchatham
added a commit
that referenced
this pull request
Apr 3, 2026
## Summary **Regression fix for PR #60.** Seid's CometBFT fork returns flat JSON (`{"node_info":{...}}`) not the standard JSON-RPC envelope (`{"jsonrpc":"2.0","result":{...}}`). PR #60 assumed all responses are wrapped, causing `Client.Get()` to return "empty result" for all seid queries. This broke: - **Peer discovery** — `defaultQueryNodeID` couldn't parse node IDs → "no reachable peers" - **await-condition** — `StatusClient.LatestHeight()` couldn't parse block height → polls never resolved ### Fix `Client.Get()` now handles both formats: if the response has a `"result"` key, unwrap it (standard CometBFT); otherwise return the body as-is (seid flat format). Also adds logging in peer discovery when EC2 instances are found but unreachable, preventing silent failures. ## Test plan - [x] `TestClient_Get_UnwrapsEnvelope` — standard CometBFT format still works - [x] `TestClient_Get_FlatJSON_SeidFormat` — new test for seid flat format - [x] All rpc, shadow, server, engine tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
configure-state-sync: querying block hash at height 200440000: empty block hash at height 200440000— caused by missing JSON-RPCresultwrapper in response parsingrpc/status.go(LatestHeight always 0),result_export.go(exporter retried forever),tasks/peers.go(node ID always empty) — all had the same missing envelope bugrpc.Clientthat strips the JSON-RPC envelope onceChanges
sidecar/rpc/client.go— thin CometBFT RPC client:Get()unwraps the{"jsonrpc":"2.0","result":{...}}envelope,GetRaw()returns full body for archival. Handles JSON-RPC error responses with actionable messages. Configurable timeout viaSetTimeout().sidecar/rpc/types.go— canonical unwrapped response types:StatusResult,BlockResult,BlockResultsResult,TxResultsidecar/rpc/status.go— refactored to useClient.Get()internally; 500ms timeout preserved for polling pathssidecar/tasks/statesync.go+peers.go— migrated torpc.Client+ shared typessidecar/tasks/result_export.go— migratedqueryLatestHeight+queryBlockResultssidecar/shadow/layer0.go+layer1.go+report.go— migrated torpc.Clientsidecar/tasks/tendermint.go,sidecar/shadow/rpc.goNet: -319 lines removed, +458 added (3 new files, 2 deleted, 12 modified)
Test plan
go test ./sidecar/rpc/— 15 tests pass (including new envelope, error, timeout tests)go test ./sidecar/tasks/— all existing tests pass with wrapped mocksgo test ./sidecar/shadow/— all existing tests pass with wrapped mocksgo vet ./sidecar/...cleango build ./sidecar/...cleanFollow-up items (tracked, not blocking)
rpc.ClientintoComparatorandResultExporterstructs for connection poolingqueryLatestHeightinresult_export.gowithrpc.StatusClient.LatestHeight()🤖 Generated with Claude Code