wallet: Remove GetLegacyBalance #15587

pull MarcoFalke wants to merge 2 commits into bitcoin:master from MarcoFalke:1903-walletRemoveLegacyBal changing 3 files +45 −91
  1. MarcoFalke commented at 2:59 AM on March 13, 2019: member

    GetLegacyBalance returns arbitrarily different values than GetBalance, sometimes even negative balances

    It is only used to throw a warning in some cases, so instead of fixing it, it should be safe to remove it (since the "balance check" is done by the wallet internally).

    The first commit is a scripted-diff that does not change the objdump of bitcoind for me and seems like a nice cleanup to me.

  2. scripted-diff: wallet: Rename pcoin to wtx
    -BEGIN VERIFY SCRIPT-
    sed -i --regexp-extended -e 's/const CWalletTx ?\* ?pcoin = &/const CWalletTx\& wtx = /g' src/wallet/wallet.cpp
    sed -i -e 's/\<pcoin->/wtx./g' src/wallet/wallet.cpp
    sed -i -e 's/\<pcoin\>/\&wtx/g' src/wallet/wallet.cpp
    -END VERIFY SCRIPT-
    fa3da91df9
  3. wallet: Remove GetLegacyBalance 5555aa43c7
  4. MarcoFalke force-pushed on Mar 13, 2019
  5. fanquake added the label Wallet on Mar 13, 2019
  6. DrahtBot commented at 6:27 AM on March 13, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15010 ([wallet] Fix getbalance with minconf by jnewbery)
    • #13756 (wallet: "avoid_reuse" wallet flag for improved privacy by kallewoof)

    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.

  7. luke-jr commented at 10:07 AM on March 13, 2019: member

    GetLegacyBalance is the only one that returns the correct values... The newer stuff is still broken.

  8. MarcoFalke commented at 12:59 PM on March 13, 2019: member

    A negative balance can clearly not be correct

  9. practicalswift commented at 3:39 PM on March 13, 2019: contributor

    @MarcoFalke This PR looks a bit unfinished: the calculated totalAmount is never used after this change?

    Can you describe the code path that will be taken that makes the GetLegacyBalance call technically redundant?

  10. luke-jr commented at 4:09 PM on March 13, 2019: member

    Negative balances can indeed be correct. Receives are only counted once they reach a certain confirmation level. But sends (including ones that use unconfirmed inputs) are always counted. So if you receive 50 BTC, and send 40 BTC, until the 50 BTC confirms, you have a balance of -40 BTC.

  11. MarcoFalke commented at 5:11 PM on March 13, 2019: member

    Can you describe the code path that will be taken that makes the GetLegacyBalance call technically redundant?

    It is practically redundant in that it may fail in cases where we'd later create the transaction because we have sufficient balance and it may not fail in cases where we are unable to create a transaction due to insufficient balance.

    So the check is at best confusing. Definitely not enough reason to keep that code around in sendmany. Especially considering that none of the other RPCs make this check. Compare for example sendtoaddress.

  12. practicalswift commented at 10:14 PM on March 13, 2019: contributor

    @MarcoFalke

    The PR seems unfinished:

    The minconf API argument passed by the user is being ignored after your change:

    {"minconf", RPCArg::Type::NUM, /* default */ "1", 
     "Only use the balance confirmed at least this many times."},
    

    Drop that argument?

    Also totalAmount is calculated but not used.

    TBH these kind of things should really be detected automatically using compiler warnings or a linter before hitting human review. Human review time is scarce.

  13. MarcoFalke closed this on Mar 13, 2019

  14. MarcoFalke deleted the branch on Mar 13, 2019
  15. MarcoFalke commented at 10:35 PM on March 13, 2019: member

    Going to reopen later, maybe

  16. practicalswift commented at 11:05 PM on March 13, 2019: contributor

    @MarcoFalke What was the egg (🥚) + hash you posted initially about? :-)

  17. jnewbery commented at 7:00 PM on March 18, 2019: member

    Concept ACK

  18. DrahtBot locked this on Dec 16, 2021

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-17 06:15 UTC

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