2

When importing descriptors with a range less than 1000, it seems to be ignored. Is this deliberate? I could‘t find anything about this in the docs.

To reproduce, first, create an empty wallet:

bitcoin-cli -regtest -named createwallet wallet_name=test disable_private_keys=true blank=true descriptors=true

Import a descriptor with range 10:

bitcoin-cli -regtest -named importdescriptors requests='[{ "desc": "'"wpkh([9a6a2580/84'/1'/179']tpubDCMRAYcH71Gib1rASZpnMPpJbj7S1Nzmao1nPv5Jrb8pwSUimsH5TmK842UhnGPJbiNThzxhK4BpRUCsjSckpNYkH9kjKGWLd94yhZFN94J/0/*)#rljv8npg"'", "timestamp":"now", "active": true, "range":10}]'

Check the range with listdescriptors:

{
  "wallet_name": "test",
  "descriptors": [
    {
      "desc": "wpkh([9a6a2580/84'/1'/179']tpubDCMRAYcH71Gib1rASZpnMPpJbj7S1Nzmao1nPv5Jrb8pwSUimsH5TmK842UhnGPJbiNThzxhK4BpRUCsjSckpNYkH9kjKGWLd94yhZFN94J/0/*)#rljv8npg",
      "timestamp": 1666876980,
      "active": true,
      "internal": false,
      "range": [
        0,
        999
      ],
      "next": 0
    }
  ]
}

In contrast, if I import a descriptor with a range larger than 1000, it seems to be respected:

bitcoin-cli -regtest -named importdescriptors requests='[{ "desc": "'"wpkh([9a6a2580/84'/1'/180']tpubDCMRAYcH71GibuLuWcDkwmmY1gXkXhf162QuEHxkMpZPSi7xck2eGQ6MRGKxNTeY8P1FiFTPCLA5x7qZpFx84fnnrNQFpSnUCwd1nPG8Mk9/0/*)#u49n3vuy"'", "timestamp":"now", "active": true, "range":2000}]'

Check the range again with listdescriptors:

(…)
{
      "desc": "wpkh([9a6a2580/84'/1'/180']tpubDCMRAYcH71GibuLuWcDkwmmY1gXkXhf162QuEHxkMpZPSi7xck2eGQ6MRGKxNTeY8P1FiFTPCLA5x7qZpFx84fnnrNQFpSnUCwd1nPG8Mk9/0/*)#u49n3vuy",
      "timestamp": 1666876980,
      "active": true,
      "internal": false,
      "range": [
        0,
        2000
      ],
      "next": 0
    }

1 Answer 1

3

Every time we call the DescriptorScriptPubKeyMan::TopUp method (which happens quite a lot internally, including whenever we add a new descriptor) it automatically adjusts the range-end to be at least as big as (next index + keypool size).

If you launch bitcoind with specifying a keypool smaller than the range you want to use (e.g. bitcoind -regtest -keypool=5), you will observe the behaviour you expected.

(Thank you for providing the steps to reproduce.)

2
  • Thanks! 1. Do you think the importdescriptors documentation should be improved? Your answer was not obvious to me. I wouldn't mind creating a PR clarifying this. 2. Is the key pool size related to address lookahead? I.e. with a range of [0, 999], will Bitcoin Core detect incoming transactions on the 1000 first addresses of that output descriptor? If so, does importing a lot of brand new descriptors warrant a smaller range to save on memory/processing, in cases where we’re in full control of the addresses shared from the various descriptors?
    – Andreas
    Commented Nov 2, 2022 at 19:01
  • You're definitely welcome to open a PR or issue! I think clarifying the connection between keypool is appropriate. It's probably not super crucial because a larger range should never lead to unexpected/dangerous behaviour, but yeah I suppose (but am not sure) that when importing large amounts of descriptors this can lead to performance impact. Even if it would have just saved you a bunch of time figuring this out, it's probably worth adding to the docs imo!
    – stickies-v
    Commented Nov 3, 2022 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.