rust-bitcoin / rust-bitcoincore-rpc

Rust RPC client library for the Bitcoin Core JSON-RPC API.
313 stars 230 forks source link

`scan_tx_out_set_blocking()` is panicking as if another scan is already in progress #361

Open luisschwab opened 2 weeks ago

luisschwab commented 2 weeks ago

rust-bitcoincore-rpc: v0.19.0 Bitcoin Core: v0.21.0 and v24.0.1

scan_tx_out_set_blocking() is panicking as if another scan was already in progress.

This snippet:

extern crate bitcoincore_rpc;
extern crate bitcoincore_rpc_json;

use bitcoincore_rpc::{Auth, Client, RpcApi};
use bitcoincore_rpc_json::ScanTxOutRequest;

fn main() {
    let rpc = Client::new("127.0.0.1",
            Auth::UserPass("satoshi".to_string(),
                           "satoshi".to_string())).unwrap();

    let scan_txout_request = ScanTxOutRequest::Single("pkh(02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5)".to_string());

    let utxos = rpc.scan_tx_out_set_blocking(&[scan_txout_request]).unwrap();

    println!("{:?}", utxos);
}

returns this error:

called `Result::unwrap()` on an `Err` value: JsonRpc(Rpc(RpcError { code: -8, message: "Scan already in progress, use action \"abort\" or \"status\"", data: None }))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I run $ bitcoin-cli scantxoutset abort before to make sure there is no scan in progress. After the panic, bitcoind continues the scan (confirmed via $ bitcoin-cli scantxoutset status).

luisschwab commented 2 weeks ago

cc @notmandatory

luisschwab commented 1 week ago

It's actually making two identical requests, ~15 seconds apart:

This error is caused by the rust-jsonrpc upstream dependency, which implements a 15 second timeout for requests (see here).

This is not the expected behavior: it should simply wait and block until the scan is done. A simple fix is not obvious to me, besides increasing the DEFAULT_TIMEOUT on rust-jsonrpc/src/http/simple_http.rs to an absurd amount, which would invalidate it's functionality for every other RPC that doesn't take as long to complete.