Skip to content

blockchain.block.header returns wrong response format when cp_height = 0 #744

@eynhaender

Description

@eynhaender

blockchain.block.header returns wrong response format when cp_height = 0

Summary

blockchain.block.header wraps its result in a JSON object instead of returning a plain hex string when cp_height is zero. This breaks Electrum wallet clients (confirmed with Sparrow) that expect the response format specified in the Electrum protocol.

Observed behavior

{"jsonrpc":"2.0","id":37,"result":{"hex":"0000092090a327..."}}

Expected behavior

{"jsonrpc":"2.0","id":37,"result":"0000092090a327..."}

Protocol spec

Per the Electrum protocol spec:

  • cp_height = 0 → result is a plain hex string
  • cp_height > 0 → result is a dict with header, branch, and root keys

Root cause

blockchain_block_headers() in src/protocols/electrum/protocol_electrum_headers.cpp is the shared implementation for both blockchain.block.header and blockchain.block.headers. It unconditionally builds a value_t{ object_t{} } for all code paths, including the single-header no-proof case that must return a plain string.

A second related bug exists in the same function: the pre-v1.6 branch sets result["hex"] for the proof dict (cp_height > 0, singular), but the spec key for that dict is "header", not "hex""hex" is only correct for the plural blockchain.block.headers concatenated response.

Impact

Sparrow retries the same request 5+ times per wallet load before dropping the connection. The wallet never finishes loading.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions