wallet: getrawchangeaddress and getnewaddress failures should not affect keypools for descriptor wallets #29510

pull UdjinM6 wants to merge 2 commits into bitcoin:master from UdjinM6:fix_reserve_dest_on_failure changing 2 files +18 −2
  1. UdjinM6 commented at 11:06 pm on February 28, 2024: contributor

    I think the expected behaviour of getrawchangeaddress and getnewaddress RPCs is that their failure should not affect keypool in any way. At least that’s how legacy wallets work, you can confirm this behaviour by running wallet_keypool.py --legacy-wallet on master with e073f1dfda7a2a2cb2be9fe2a1d576f122596021 applied on top. However running wallet_keypool.py --descriptors on the same commit results in the following failure:

    0  File "/path/to/bitcoin/test/functional/test_framework/test_framework.py", line 131, in main
    1    self.run_test()
    2  File "/path/to/bitcoin/test/functional/wallet_keypool.py", line 114, in run_test
    3    assert_equal(kp_size_before, kp_size_after)
    4  File "/path/to/bitcoin/test/functional/test_framework/util.py", line 57, in assert_equal
    5    raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
    6AssertionError: not([18, 24] == [19, 24])
    

    This happens because we pass nIndex (which is a class member) into GetReservedDestination and since it’s passed by reference we get an updated value back, so nIndex won’t be equal -1 anymore, no matter if the function failed or succeeded. This means that ReturnDestination (called by dtor of ReserveDestination) will try to return something we did not actually reserve.

    The fix is to simply use a temporary variable instead of a class member and only update nIndex when op_address actually has value, basically do it the same way we do for other class members (address and fInternal) already.

  2. wallet: Avoid updating `ReserveDestination::nIndex` when `GetReservedDestination` fails 367bb7a80c
  3. test: make sure keypool sizes do not change on `getrawchangeaddress`/`getnewaddress` failures e073f1dfda
  4. DrahtBot commented at 11:07 pm on February 28, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK achow101, josibake

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  5. DrahtBot added the label Wallet on Feb 28, 2024
  6. achow101 added this to the milestone 27.0 on Feb 28, 2024
  7. achow101 commented at 0:00 am on February 29, 2024: member

    ACK e073f1dfda7a2a2cb2be9fe2a1d576f122596021

    Nice catch! A consequence of this bug is that the user can get the same change address twice, and that is pretty bad. I think we’re going to want this for 27.0, and probably backport to 26.1 and 25.2 too.

  8. achow101 removed this from the milestone 27.0 on Feb 29, 2024
  9. achow101 added this to the milestone 25.2 on Feb 29, 2024
  10. achow101 removed this from the milestone 25.2 on Feb 29, 2024
  11. achow101 added this to the milestone 27.0 on Feb 29, 2024
  12. achow101 added the label Needs backport (25.x) on Feb 29, 2024
  13. achow101 added the label Needs backport (26.x) on Feb 29, 2024
  14. DrahtBot added the label CI failed on Feb 29, 2024
  15. DrahtBot removed the label CI failed on Feb 29, 2024
  16. fanquake requested review from josibake on Feb 29, 2024
  17. josibake commented at 4:21 pm on February 29, 2024: member

    ACK https://github.com/bitcoin/bitcoin/pull/29510/commits/e073f1dfda7a2a2cb2be9fe2a1d576f122596021

    Code reviewed, and also did a bit of poking around to check if this happens any other place nIndex is used. Didn’t see anything obvious, and this solves the specific problem with getnewaddress/getrawchangeaddress. Thanks for adding the test!

  18. DrahtBot removed review request from josibake on Feb 29, 2024
  19. josibake approved
  20. achow101 merged this on Feb 29, 2024
  21. achow101 closed this on Feb 29, 2024

  22. knst referenced this in commit d6c97e6390 on Mar 1, 2024
  23. achow101 referenced this in commit 7c08ccf19b on Mar 1, 2024
  24. achow101 referenced this in commit f93be0103f on Mar 1, 2024
  25. fanquake removed the label Needs backport (25.x) on Mar 4, 2024
  26. fanquake commented at 11:40 am on March 4, 2024: member
    Backported for 25.x in #29531.
  27. luke-jr referenced this in commit 86ba87383e on Mar 4, 2024
  28. luke-jr referenced this in commit c1358f6aad on Mar 4, 2024
  29. glozow referenced this in commit 7c82b2758c on Mar 5, 2024
  30. glozow referenced this in commit 40c56a4d13 on Mar 5, 2024
  31. glozow commented at 10:59 am on March 5, 2024: member
    Backported for 26.x in #29509
  32. glozow removed the label Needs backport (26.x) on Mar 5, 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