Skip to content

Using import_multi with a descriptor and a large range returns a socket error, but only on version 0.14 #211

Open
@chris-belcher

Description

@chris-belcher

This code works for version 0.13 or below, once I upgrade to 0.14 this error started happening.

Here is code demonstrating the bug

const RPC_CREDENTIALS: Option<(&str, &str)> = Some(("regtestrpcuser", "regtestrpcpass"));

const RPC_HOSTPORT: &str = "localhost:18443";
const RPC_WALLET: &str = "teleport";

const ADDRESS_IMPORT_COUNT: usize = 5000;

use bitcoincore_rpc::json::{
    ImportMultiOptions, ImportMultiRequest, ImportMultiRescanSince,
};
use bitcoincore_rpc::{Client, RpcApi, Auth};


fn main() -> Result<(), bitcoincore_rpc::Error> {

    let descs = [
        "wpkh(tpubDCph6XxkYmXpittC1dKgfNU2wTuq3JbpDNqJRwB1zpEZHJZBgdk1nxtn4p4TiF6ydvJH4BFbPwHMf8gGZ85DSLDfqKGRLtLeyuWs9hBeHvo/0/*)#fymqnm93",
        "wpkh(tpubDCph6XxkYmXpittC1dKgfNU2wTuq3JbpDNqJRwB1zpEZHJZBgdk1nxtn4p4TiF6ydvJH4BFbPwHMf8gGZ85DSLDfqKGRLtLeyuWs9hBeHvo/1/*)#cs7pww4f"
    ];

    let auth = match RPC_CREDENTIALS {
        Some((user, pass)) => Auth::UserPass(user.to_string(), pass.to_string()),
        None => panic!(""),
    };
    let rpc = Client::new(
        &format!("http://{}/wallet/{}", RPC_HOSTPORT, RPC_WALLET),
        auth,
    )?;
    rpc.get_blockchain_info()?;

    let address_label = "somelabel";

    let import_requests = descs 
        .iter()
        .map(|desc| ImportMultiRequest {
            timestamp: ImportMultiRescanSince::Now,
            descriptor: Some(desc),
            range: Some((0, ADDRESS_IMPORT_COUNT - 1)),
            watchonly: Some(true),
            label: Some(&address_label),
            ..Default::default()
        })
        .collect::<Vec<ImportMultiRequest>>();

    let result = rpc.import_multi(
        &import_requests,
        Some(&ImportMultiOptions {
            rescan: Some(false),
        }),
    )?;
    for r in result {
        if !r.success {
            return Err(bitcoincore_rpc::Error::UnexpectedStructure);
        }
    }

    println!("Hello, world!");

    Ok(())
}

This results in an error: Error: JsonRpc(Transport(SocketError(Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" })))

The cargo.toml file:

[package]
name = "rpc-bitcoincore-0-14-importmulti"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitcoincore-rpc = "0.14"

Changing to bitcoincore-rpc = "0.13" or below stops the error from happening.

Reducing the value of ADDRESS_IMPORT_COUNT down to something like 500 or 50 instead of 5000 also makes the error disappear, indicating that the cause is the long runtime of importmulti, possibly version 0.14 reduced a timeout somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions