[WIP] Fix calculation of balances and available coins. #7706

pull morcos wants to merge 2 commits into bitcoin:master from morcos:fixconflicts2 changing 2 files +13 −6
  1. morcos commented at 4:56 PM on March 17, 2016: member

    I want to add something to the RPC test to catch what caused the issue in #7690 but this should fix it.

    I also want to think about whether this is exactly what we want. It's a slightly different behavior in the calculation of unconfirmed balances with regard to transactions which aren't final. I think an argument could be made that it was meant to count in unconfirmed balances non-final transactions which aren't in your mempool. Does anyone know if that was the case? If so it'll be hard to figure out how to distinguish those which are just not yet confirmed, and those which are permanently conflicted.

    Edit: Unfortunately this still is a work in progress. Both getbalance and GetAccountBalance in rpcwallet.cpp do their own summation of balances and also need to be fixed. Can we please get rid of accounts?

  2. Fix calculation of balances and available coins.
    No longer consider coins which aren't in our mempool.
    021fc6a876
  3. Modify treatment of unconfirmed txs for accounting by account.
    Unconfirmed txs that are no longer in your mempool will no longer affect your balance in either direction for accounting by account.
    168f7bf870
  4. morcos commented at 10:06 PM on March 17, 2016: member

    Unfortunately this is not easy to fix properly. Inside wallet.cpp, the calculation of your balance has the nice property of adding up all of your coins and then only counting the ones that haven't been spent. Therefore it's not really possible to spend a coin you're not counting in your balance.

    However the calculations used in the getbalance rpc call work differently, by adding up the received amounts and subtracting the sent amounts because they are using "accounts". So you'll end up with potentially negative balances and other bad things if we try to mimic the behavior for unconfirmed txs that we want in the wallet code. This is relevant because the only way to get an unconfirmed balance using rpc is to call getbalance "" 0 or getbalance "*" 0. I'll admit to not really understanding exactly what either of those do, but they both suffer from that same broken behavior.

    The "solution" I propose in the second commit is to revert to the 0.11 treatment of transactions which are not confirmed and not in your mempool when calculating balances by account. This will differ from the calculation that is done for the GUI and as an overall calculation.

    The biggest impact of this problem is that sendfrom and sendmany use the GetAccountBalance method of determining balance, so they will use the "wrong" value.

  5. morcos commented at 10:09 PM on March 17, 2016: member

    Perhaps it would be a good idea to special case the "" account in all of these rpc calls to not use the account method of calculations and use GetBalance and GetUnconfirmedBalance from wallet.cpp. That way everything should work "properly" if you are not trying to use accounts. Although GetBalance doesn't currently have support for minimum confirmation depths.

  6. promag commented at 11:48 PM on March 17, 2016: member

    Once upon a time I thought to my self why the call to GetAccountBalance when CreateTransaction fails if there's insufficient UTXO's..

  7. jonasschnelli added the label Wallet on Mar 18, 2016
  8. jonasschnelli added the label Priority Medium on Mar 18, 2016
  9. morcos commented at 1:58 PM on March 18, 2016: member

    Closed for #7715

  10. morcos closed this on Mar 18, 2016

  11. DrahtBot locked this on Sep 8, 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-21 15:15 UTC

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