<p>Every time we call the <code>DescriptorScriptPubKeyMan::TopUp</code> method (which happens quite a lot internally, including whenever we add a new descriptor) <a href="https://github.com/bitcoin/bitcoin/blob/1bad29fe02096b269858b192a4a91c785a44e505/src/wallet/scriptpubkeyman.cpp#L2130" rel="nofollow noreferrer">it automatically adjusts</a> the range-end to be at least as big as (next index + keypool size).</p>
<p>If you launch bitcoind with specifying a <code>keypool</code> smaller than the range you want to use (e.g. <code>bitcoind -regtest -keypool=5</code>), you will observe the behaviour you expected.</p>
<p><em>(Thank you for providing the steps to reproduce.)</em></p>

CC BY-SA 4.0
2022-11-02T19:01:40.390Z
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
CC BY-SA 4.0
2022-11-03T16:26:09.903Z
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
CC BY-SA 4.0
2022-10-28T15:20:36.003Z
2022-10-28T15:20:36.003Z
stickies-v
<p>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 <a href="https://developer.bitcoin.org/reference/rpc/importdescriptors.html" rel="nofollow noreferrer">docs</a>.</p>
<p>To reproduce, first, create an empty wallet:</p>
<p><code>bitcoin-cli -regtest -named createwallet wallet_name=test disable_private_keys=true blank=true descriptors=true</code></p>
<p>Import a descriptor with range 10:</p>
<p><code>bitcoin-cli -regtest -named importdescriptors requests='[{ &quot;desc&quot;:  &quot;'&quot;wpkh([9a6a2580/84'/1'/179']tpubDCMRAYcH71Gib1rASZpnMPpJbj7S1Nzmao1nPv5Jrb8pwSUimsH5TmK842UhnGPJbiNThzxhK4BpRUCsjSckpNYkH9kjKGWLd94yhZFN94J/0/*)#rljv8npg&quot;'&quot;, &quot;timestamp&quot;:&quot;now&quot;, &quot;active&quot;: true, &quot;range&quot;:10}]'</code></p>
<p>Check the range with <code>listdescriptors</code>:</p>
<pre><code>{
  &quot;wallet_name&quot;: &quot;test&quot;,
  &quot;descriptors&quot;: [
    {
      &quot;desc&quot;: &quot;wpkh([9a6a2580/84'/1'/179']tpubDCMRAYcH71Gib1rASZpnMPpJbj7S1Nzmao1nPv5Jrb8pwSUimsH5TmK842UhnGPJbiNThzxhK4BpRUCsjSckpNYkH9kjKGWLd94yhZFN94J/0/*)#rljv8npg&quot;,
      &quot;timestamp&quot;: 1666876980,
      &quot;active&quot;: true,
      &quot;internal&quot;: false,
      &quot;range&quot;: [
        0,
        999
      ],
      &quot;next&quot;: 0
    }
  ]
}
</code></pre>
<p>In contrast, if I import a descriptor with a range larger than 1000, it seems to be respected:</p>
<p><code>bitcoin-cli -regtest -named importdescriptors requests='[{ &quot;desc&quot;:  &quot;'&quot;wpkh([9a6a2580/84'/1'/180']tpubDCMRAYcH71GibuLuWcDkwmmY1gXkXhf162QuEHxkMpZPSi7xck2eGQ6MRGKxNTeY8P1FiFTPCLA5x7qZpFx84fnnrNQFpSnUCwd1nPG8Mk9/0/*)#u49n3vuy&quot;'&quot;, &quot;timestamp&quot;:&quot;now&quot;, &quot;active&quot;: true, &quot;range&quot;:2000}]' </code></p>
<p>Check the range again with <code>listdescriptors</code>:</p>
<pre><code>(…)
{
      &quot;desc&quot;: &quot;wpkh([9a6a2580/84'/1'/180']tpubDCMRAYcH71GibuLuWcDkwmmY1gXkXhf162QuEHxkMpZPSi7xck2eGQ6MRGKxNTeY8P1FiFTPCLA5x7qZpFx84fnnrNQFpSnUCwd1nPG8Mk9/0/*)#u49n3vuy&quot;,
      &quot;timestamp&quot;: 1666876980,
      &quot;active&quot;: true,
      &quot;internal&quot;: false,
      &quot;range&quot;: [
        0,
        2000
      ],
      &quot;next&quot;: 0
    }
</code></pre>

<output-script-descriptors>
Minimum range when importing descriptors?
Andreas
# Minimum range when importing descriptors?

(Asked by: username_0 on 2022-10-28)

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](https://developer.bitcoin.org/reference/rpc/importdescriptors.html).

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
    }

```

**Tags:** output-script-descriptors


---

## 1 answers

### Answer by username_1 on 2022-10-28. Score: 3 | Accepted answer

Every time we call the `DescriptorScriptPubKeyMan::TopUp` method (which happens quite a lot internally, including whenever we add a new descriptor) [it automatically adjusts](https://github.com/bitcoin/bitcoin/blob/1bad29fe02096b269858b192a4a91c785a44e505/src/wallet/scriptpubkeyman.cpp#L2130) 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.)*

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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!  

---

