I’m seeing 50% of generated change addresses not being used. It’s as if two are reserved for every one that is used.
This is happening in version v24.0.1.
Here’s a sequence of commands that shows what I mean. Only the odd numbered change hdkeypaths are used:
0$ /bin/rm -fr ~/.bitcoin/regtest
1$ bitcoin-qt -regtest &
2$ bitcoin-cli -regtest createwallet 1 > /dev/null
3$ bitcoin-cli -regtest createwallet 2 > /dev/null
4$ bitcoin-cli -regtest -rpcwallet=1 -generate 1 > /dev/null
5$ bitcoin-cli -regtest -rpcwallet=2 -generate 100 > /dev/null
6$ to=$(bitcoin-cli -regtest -rpcwallet=2 getnewaddress)
7$ txs=$(for i in {1..5}; do bitcoin-cli -regtest -rpcwallet=1 sendtoaddress $to 1; done)
8$ addrs=$(for i in $txs; do bitcoin-cli -regtest getrawtransaction $i true | jq -Mc '.vout[]|{value:.value,addr:.scriptPubKey.address}'; done | grep -v ':1,' | jq -r .addr)
9$ for a in $addrs; do bitcoin-cli -regtest -rpcwallet=1 getaddressinfo $a | jq -r .hdkeypath; done
10m/84'/1'/0'/1/1
11m/84'/1'/0'/1/3
12m/84'/1'/0'/1/5
13m/84'/1'/0'/1/7
14m/84'/1'/0'/1/9
This happens whether or not I create descriptor wallets. For example, with a descriptor wallet I get these descriptors for the change addresses:
0wpkh([779aecf0/84'/1'/0'/1/1]029919052bd5b904afbf71d90afbec0a852d1f0181914b6d07bcab028a0d1ac3e4)#94rhf9lu
1wpkh([779aecf0/84'/1'/0'/1/3]0360ecbba4ebaac3ab4f62f14b12a136c2cc5e8264ac1be2af1b5e4413944a2c6a)#lwjzrh62
2wpkh([779aecf0/84'/1'/0'/1/5]03d3f72c2cc6085bdee5388ff3b96df7d27ac18d85b5cc8d8048e287b52777062e)#5q4fsvmd
3wpkh([779aecf0/84'/1'/0'/1/7]02b77a29387f645bb5ed27ef25144ae67a984e056e41b35fce33bb377d199845ab)#mc608kvz
4wpkh([779aecf0/84'/1'/0'/1/9]024988fafba17c2d6f5b2b27428e2fb65ca8a7882ac0fae1422e4fdf46c95dbc61)#mwxzye2v
and for a legacy wallet I get these:
0wpkh([bcc40f8d/0'/1'/1']03d3cc823cd01dcb23dce0ac53f8b38c3cb8b9ddbdfc789550c280d25cba432932)#3vxlglf6
1wpkh([bcc40f8d/0'/1'/3']03016e2243892459754e125954d205136247f67580e9379ca931f2ec374b924aef)#kxwx63p3
2wpkh([bcc40f8d/0'/1'/5']0236dd8b3a6ebd26a4e1e9dc1d84bf053438c339babacd202000f44917bd452336)#jaq2hgn4
3wpkh([bcc40f8d/0'/1'/7']03785884e52fad4588d2d0e1df48b8ba691dddfb3696667932a3b46cb0202132fa)#0d786n6s
4wpkh([bcc40f8d/0'/1'/9']03ba88cdc9a37aa676a1152c6d7d970aa32324b99d8c6f775c4543e016161ea4d9)#vdvr44ar