every other change address is unused #27051

issue dooglus openend this issue on February 6, 2023
  1. dooglus commented at 4:50 pm on February 6, 2023: contributor

    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
    
  2. dooglus added the label Bug on Feb 6, 2023
  3. achow101 commented at 5:03 pm on February 6, 2023: member
    For anyone who wants to tackle this, it’s most likely to be the optimistic avoidpartialspends behavior which does transaction creation twice, and in doing so, also retrieves two change addresses.
  4. pinheadmz commented at 5:09 pm on February 6, 2023: member

    For anyone who wants to tackle this

    Taking a look now ;-)

  5. dooglus commented at 6:08 pm on February 6, 2023: contributor
    If I specify -avoidpartialspends on the bitcoin-qt commandline I don’t see the wasted change addresses.
  6. pinheadmz commented at 8:41 pm on February 6, 2023: member
    Possible fix: #27053 @dooglus are you able to test/review ?
  7. dooglus commented at 11:16 pm on February 6, 2023: contributor
    @pinheadmz I’m not familiar enough with the code to review it, but I’ve tested it and it works for me with both legacy and descriptor wallets.
  8. bitcoin deleted a comment on Feb 7, 2023
  9. bitcoin deleted a comment on Feb 7, 2023
  10. fanquake closed this on Feb 20, 2023

  11. sidhujag referenced this in commit 42ff693135 on Feb 25, 2023
  12. bitcoin locked this on Feb 20, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me