Repository navigation
fix(rpc): read chunked responses from the bitcoind RPC server - #393
eynhaender wants to merge 1 commit into
Conversation
emma31-dev
left a comment
There was a problem hiding this comment.
Approach ACK.
Thank you for working on this. Merge master into this branch and rebase to one commit that i can ACK.
| - 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 |
There was a problem hiding this comment.
The changelog entry can be simplified to this:
| - 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 |
|
|
||
| let rpc_error = | ||
| |e: jsonrpc::Error| Error::BitcoinCoreRpcError(bitcoincore_rpc::Error::JsonRpc(e)); | ||
| let (user, pass) = auth.get_user_pass().map_err(Error::BitcoinCoreRpcError)?; |
There was a problem hiding this comment.
NIT: .map_err can be safely removed
| 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`).
830780a to
0837bc1
Compare
|
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
left a comment
There was a problem hiding this comment.
ACK 0837bc1
Everything looks good and online commands still work as expected.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #393 +/- ##
==========================================
+ Coverage 59.87% 59.94% +0.07%
==========================================
Files 25 25
Lines 4558 4576 +18
==========================================
+ Hits 2729 2743 +14
- Misses 1829 1833 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tvpeter
left a comment
There was a problem hiding this comment.
Thank you @eynhaender for the issue and this PR. It fixes the chunked response problem, but the transport swap introduces two problems that affect every RPC user, including Bitcoin Core users who never had the chunked response problem:
minreqopens a new TCP connection per request, which runs out of local ports on longer scans.simple_httpkeeps one socket open and reuses it. On regtest, wallet full_scan on this branch fails around 15,000 blocks with Can't assign requested address (os error 49) (16k sockets in TIME_WAIT), while master finishes in ~7s with one connection.bitreqhas the same issue for blocking callers.- A URL with no scheme and no port now goes to port 80 instead of 8332.
simple_httpdefaults to 8332 in that case. This PR prepends http://, sominrequses port 80.--url 127.0.0.1then missesbitcoindand sends the RPC credentials to whatever is listening on 80.
A better approach might be to implement jsonrpc's Transport trait over an HTTP client that both reuses connections and reads chunked responses (e.g. a ureq agent), then wrap it with Client::from_jsonrpc as this PR already does. I am open to alternatives that you might have.
Thank you.
Description
Fixes #392.
--client-type rpcbuilt its client withbitcoincore_rpc::Client::new, which always uses jsonrpc'ssimple_httptransport and fails on any response sent withTransfer-Encoding: chunked.This PR builds the client with
Client::from_jsonrpcover jsonrpc'sminreq_httptransport, which reads both chunked andContent-Lengthresponses. bitcoincore-rpc 0.19 already enablesminreq_http, soCargo.tomlandCargo.lockare unchanged.Notes to the reviewers
minreqrequires a URL scheme, whilesimple_httpassumedhttp.http://is therefore prepended when--urlhas none, so127.0.0.1:18443from the README keeps working.Basic auth (
--basic-auth, and the cookie file viaAuth::get_user_pass) is passed to theminreq_httpbuilder. Transport errors map to the existingError::BitcoinCoreRpcError(bitcoincore_rpc::Error::JsonRpc(..)).Tested manually on regtest with
wallet full_scanand the same wpkh wallet against Bitcoin Core 32.1 and libbitcoin-server masterd09a5c2a(bitcoind endpoint, which sends every response withTransfer-Encoding: chunked):http://)In every run that succeeded, the txid set and the balance were identical.
There is no automated regression test:
bdk_testenv's bitcoind only sendsContent-Lengthresponses. A test would need a mock HTTP server that sends chunked responses; I can add one if wanted.Checklists
All Submissions:
just pre-pushbefore pushingBugfixes: