Skip to content

fix(rpc): read chunked responses from the bitcoind RPC server - #393

Open
eynhaender wants to merge 1 commit into
bitcoindevkit:masterfrom
eynhaender:fix/rpc-chunked-responses
Open

eynhaender wants to merge 1 commit into
bitcoindevkit:masterfrom
eynhaender:fix/rpc-chunked-responses

Conversation

@eynhaender

@eynhaender eynhaender commented Nov 23, 2026 •

Copy link
Copy Markdown

Description

Fixes #392.

--client-type rpc built its client with bitcoincore_rpc::Client::new, which always uses jsonrpc's simple_http transport and fails on any response sent with Transfer-Encoding: chunked.

This PR builds the client with Client::from_jsonrpc over jsonrpc's minreq_http transport, which reads both chunked and Content-Length responses. bitcoincore-rpc 0.19 already enables minreq_http, so Cargo.toml and Cargo.lock are unchanged.

Notes to the reviewers

  • minreq requires a URL scheme, while simple_http assumed http. http:// is therefore prepended when --url has none, so 127.0.0.1:18443 from the README keeps working.

  • Basic auth (--basic-auth, and the cookie file via Auth::get_user_pass) is passed to the minreq_http builder. Transport errors map to the existing Error::BitcoinCoreRpcError(bitcoincore_rpc::Error::JsonRpc(..)).

  • Tested manually on regtest with wallet full_scan and the same wpkh wallet against Bitcoin Core 32.1 and libbitcoin-server master d09a5c2a (bitcoind endpoint, which sends every response with Transfer-Encoding: chunked):

    binary server result
    master Bitcoin Core 32.1 11 txs
    master libbitcoin-server d09a5c2a fails: "The server replied with a chunked response which is not supported"
    this PR Bitcoin Core 32.1 11 txs
    this PR libbitcoin-server d09a5c2a (with and without http://) 11 txs

    In every run that succeeded, the txid set and the balance were identical.

  • There is no automated regression test: bdk_testenv's bitcoind only sends Content-Length responses. A test would need a mock HTTP server that sends chunked responses; I can add one if wanted.

Checklists

All Submissions:

Bugfixes:

  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

`bitcoincore_rpc::Client::new` always uses jsonrpc's `simple_http`
transport, which rejects responses sent with `Transfer-Encoding: chunked`
("The server replied with a chunked response which is not supported").
Servers that stream JSON-RPC responses chunked, such as libbitcoin-server,
cannot be used with `--client-type rpc`.

Build the RPC client over jsonrpc's `minreq_http` transport instead, which
reads chunked and content-length responses. bitcoincore-rpc 0.19 already
enables the `minreq_http` feature of jsonrpc, so no dependency changes.

minreq requires a URL scheme while simple_http defaulted to http, so
`http://` is prepended when the URL has none (e.g. `127.0.0.1:18443`).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

RPC backend fails against servers that send chunked responses

1 participant