Closed kylezs closed 1 year ago
If it works with curl, but not with rust, then the problem seems to be in the rust code?
It works with every other bitcoin node I've tried it against.
Ok, I may take a look if you provide exact steps to reproduce on localhost
.
After some debugging we noticed that the setup we have in which the bitcoin node is sitting behind a reverse proxy was the issue. We don't exactly know yet why but it looks like the reverse proxy is changing the request which results in it being invalid hence the HTTP 400
error.
Bypassing the reverse proxy and communicating directly with the bitcoin server worked.
However, it is still a mystery how sending the same request using curl
through the reverse proxy works.
For context this is the request we used to test:
curl --user username:password -H 'Content-Type: application/json;' -d '{"jsonrpc":"2.0", "id": "1", "method": "getbestblockhash", "params" : []}' https://my-btc-node.mydomain.abc
Closing for now then. Discussion can continue / it can be re-opened if it's established that there is a bug in Bitcoin Core.
Also, looking at that crate, I assume the README is outdated, as it claims to only support end-of-life versions of Core: https://github.com/rust-bitcoin/rust-bitcoincore-rpc/#supported-bitcoin-core-versions ?
@fanquake Doesn't look like an issue with Bitcoin Core so yeah closing it is fine 👍 Thanks!
Looking at the supported versions, I don't see v24.0.1
which is the one we are using. It is confusing that this issue only surfaces when you have a reverse proxy in between the requester and the Bitcoin node RPC server. Will investigate more and share the results here.
Rewrote the parts we need from that crate using reqwest
and now the issue no longer exists so it's certainly an issue with the library we were using and not the bitcoin-core :). Suspect it's due to some bad / insufficient request headers that don't allow for the use of proxies.
Running a snap bitcoin-core node I was able to make requests via curl successfully. However, when using the rust crate: https://docs.rs/bitcoincore-rpc/latest/bitcoincore_rpc/index.html to query the same requests it fails with 400 Bad Request.
I've tested the rust code against other nodes, both remote, hosted nodes, and local nodes on baremetal and in docker, and the one packaged for snap is the only one that has problems.
Code to reproduce: