wallet: Replace `GetBalance()` logic with `AvailableCoins()` #26756

pull w0xlt wants to merge 3 commits into bitcoin:master from w0xlt:balance_coin_selection changing 10 files +522 −466
  1. w0xlt commented at 4:58 AM on December 27, 2022: contributor

    This PR proposes a solution for #26500 by changing the AvailableCoins() function to calculate values by status (TRUSTED, UNTRUSTED_PENDING and IMMATURE) and ownership (MINE, WATCH_ONLY), eliminating the GetBalance() logic.

    The downside is that the cache is no longer used. Not sure about the performance implication, but if the approach is OK, caching can also be used with this solution.

    This approach also fixes the bug mentioned at the end of the wallet_abandonconflict.py file.

  2. DrahtBot commented at 4:58 AM on December 27, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26951 (wallet: improve rescan performance 640% by pstratem)
    • #26573 (Wallet: don't underestimate the fees when spending a Taproot output by darosior)
    • #26567 (Wallet: estimate the size of signed inputs using descriptors by darosior)
    • #26152 (Bump unconfirmed ancestor transactions to target feerate by Xekyo)
    • #25979 ([WIP] wallet: standardize change output detection process by furszy)
    • #25620 (wallet: Introduce AddressBookManager by furszy)
    • #24897 ([Draft / POC] Silent Payments by w0xlt)
    • #24149 (Signing support for Miniscript Descriptors by darosior)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label Wallet on Dec 27, 2022
  4. w0xlt force-pushed on Dec 27, 2022
  5. w0xlt force-pushed on Dec 27, 2022
  6. DrahtBot added the label Needs rebase on Jan 3, 2023
  7. wallet: Separate the `AvailableCoins()` function into a new file
    This allows `AvailableCoins()` to be used in multiple files
    without creating a circular dependency
    0cc7da8ff6
  8. wallet: Replace `GetBalance()` logic with modified `AvailableCoins()`
    Add to the `AvailableCoins()` function the ability to separate
    values by status and ownership of each coin.
    e57dfaa9d2
  9. wallet: Remove unused `CachedTxGetAvailableCredit()` function 3a2bc11c26
  10. w0xlt force-pushed on Jan 5, 2023
  11. DrahtBot removed the label Needs rebase on Jan 5, 2023
  12. w0xlt commented at 12:21 PM on January 5, 2023: contributor

    Rebased.

  13. DrahtBot added the label Needs rebase on Feb 16, 2023
  14. DrahtBot commented at 11:07 AM on February 16, 2023: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

  15. achow101 requested review from achow101 on Apr 25, 2023
  16. achow101 requested review from josibake on Apr 25, 2023
  17. achow101 commented at 12:13 PM on May 1, 2023: member

    I think this will end up making GetBalance really slow. We should really be tracking our UTXOs and computing the balance (and available coins) from that instead of iterating the entire wallet to figure out the UTXOs. #27286 implements the first steps to doing that, and I think we should prefer moving in that direction.

  18. josibake commented at 1:10 PM on May 1, 2023: member

    I'd also prefer we stopped using AvailableCoins as a general wallet traversal tool in favor of something like #27286

    A lot of bugs/strangeness in the wallet seems to come from the fact that we always need to iterate over a bunch of transactions to learn the state of our wallet. If we did track wallet state in one place, we could have well-scoped individual functions for specific tasks.

  19. achow101 commented at 2:43 PM on May 3, 2023: member

    Closing due to lack of interest in this approach.

  20. achow101 closed this on May 3, 2023

  21. bitcoin locked this on May 2, 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: 2026-04-19 03:13 UTC

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