Skip to content

fix: consolidate CometBFT RPC response parsing (Alpha P2)#60

Merged
bdchatham merged 1 commit intomainfrom
fix/consolidate-cometbft-rpc-types
Apr 3, 2026
Merged

fix: consolidate CometBFT RPC response parsing (Alpha P2)#60
bdchatham merged 1 commit intomainfrom
fix/consolidate-cometbft-rpc-types

Conversation

@bdchatham
Copy link
Copy Markdown
Contributor

Summary

  • Fixes prod error: configure-state-sync: querying block hash at height 200440000: empty block hash at height 200440000 — caused by missing JSON-RPC result wrapper in response parsing
  • Fixes 3 additional silent failures: rpc/status.go (LatestHeight always 0), result_export.go (exporter retried forever), tasks/peers.go (node ID always empty) — all had the same missing envelope bug
  • Consolidates 4 independent CometBFT RPC parsing implementations into a single rpc.Client that strips the JSON-RPC envelope once

Changes

  • 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 via SetTimeout().
  • sidecar/rpc/types.go — canonical unwrapped response types: StatusResult, BlockResult, BlockResultsResult, TxResult
  • sidecar/rpc/status.go — refactored to use Client.Get() internally; 500ms timeout preserved for polling paths
  • sidecar/tasks/statesync.go + peers.go — migrated to rpc.Client + shared types
  • sidecar/tasks/result_export.go — migrated queryLatestHeight + queryBlockResults
  • sidecar/shadow/layer0.go + layer1.go + report.go — migrated to rpc.Client
  • Deleted: sidecar/tasks/tendermint.go, sidecar/shadow/rpc.go
  • All test mocks updated to use full JSON-RPC envelopes — prevents regression

Net: -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 mocks
  • go test ./sidecar/shadow/ — all existing tests pass with wrapped mocks
  • go vet ./sidecar/... clean
  • go build ./sidecar/... clean

Follow-up items (tracked, not blocking)

  • Hoist rpc.Client into Comparator and ResultExporter structs for connection pooling
  • Replace standalone queryLatestHeight in result_export.go with rpc.StatusClient.LatestHeight()

🤖 Generated with Claude Code

…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 bdchatham merged commit f8881c9 into main Apr 3, 2026
2 checks passed
@bdchatham bdchatham deleted the fix/consolidate-cometbft-rpc-types branch April 3, 2026 15:43
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>
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>
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