Skip to content

[rpc] Import descriptors instead of addresses #841

@rajarshimaitra

Description

@rajarshimaitra

Describe the enhancement
Currently, in the RPC module, we handle address import into Core in two different ways.

bdk/src/blockchain/rpc.rs

Lines 388 to 392 in eac739d

if is_descriptor {
import_descriptors(client, start_epoch, scripts_iter)?;
} else {
import_multi(client, start_epoch, scripts_iter)?;
}

This allows us to be compatible with both legacy and descriptor wallets. But we are not harnessing the descriptor capability of core and manually deriving addresses and doing a legacy-type wallet sync. Even for descriptor wallet cases, we store the spks as raw descriptors.

bdk/src/blockchain/rpc.rs

Lines 807 to 810 in eac739d

fn descriptor_from_script_pubkey(script: &Script) -> String {
let desc = format!("raw({})", script.to_hex());
format!("{}#{}", desc, calc_checksum(&desc).unwrap())
}

It would be nice to use core's descriptor framework directly. That will make the code more straightforward, as well as improve RPC sync time a lot for larger wallets.

Core's descriptor doc says even import_multi should be able to handle descriptors and adapt them to legacy wallets since v0.18.

So we should be able to do syncing with the core without importing individual addresses.

Use case

Drop the address middle man, performance to the moon..

Additional context

  • Using a descriptor instead of importing addresses adds additional complexity of marinating sync between derived addresses in our db and derived addresses in core. This might require some extra hack around the core's rpc api. But it should not be too difficult and IMO worth the effort.

Metadata

Metadata

Labels

new featureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions