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

@emma31-dev emma31-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK.

Thank you for working on this. Merge master into this branch and rebase to one commit that i can ACK.

Comment thread CHANGELOG.md Outdated
- Fixed `key generate` silently producing a 24-word mnemonic for any `--entropy` value other than 12; values other than 12 and 24 are now rejected
- Gated `full_scan`'s `--scan-stop-gap` to the Electrum and Esplora backends that use it; RPC and CBF wallets now reject the flag instead of silently ignoring it, while a `STOP_GAP` environment variable keeps working for supported backends and no longer breaks unsupported ones
- Changed `payjoin history` to return JSON instead of a rendered table
- Fixed the `rpc` backend failing against servers that send chunked responses ("The server replied with a chunked response which is not supported"); the RPC client now uses jsonrpc's `minreq_http` transport

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog entry can be simplified to this:

Suggested change
- Fixed the `rpc` backend failing against servers that send chunked responses ("The server replied with a chunked response which is not supported"); the RPC client now uses jsonrpc's `minreq_http` transport
- Fixed the `rpc` backend failing against servers that send chunked responses

Comment thread src/client.rs Outdated

let rpc_error =
|e: jsonrpc::Error| Error::BitcoinCoreRpcError(bitcoincore_rpc::Error::JsonRpc(e));
let (user, pass) = auth.get_user_pass().map_err(Error::BitcoinCoreRpcError)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: .map_err can be safely removed

Suggested change
let (user, pass) = auth.get_user_pass().map_err(Error::BitcoinCoreRpcError)?;
let (user, pass) = auth.get_user_pass()?;

`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`).
@eynhaender
eynhaender force-pushed the fix/rpc-chunked-responses branch from 830780a to 0837bc1 Compare November 26, 2026 13:32
@eynhaender

Copy link
Copy Markdown
Author

Rebased on master as a single commit and applied both suggestions. CI is waiting for workflow approval. Thanks for your quick response, let's keep on building.

@emma31-dev emma31-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 0837bc1

Everything looks good and online commands still work as expected.

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

2 participants