SubtractFeeFromAmount Inconsistency #16100

issue VoxR4710 opened this issue on May 27, 2019
  1. VoxR4710 commented at 10:51 AM on May 27, 2019: none

    Running bitcoind and bitcoin-cli with JSON RPC, 0.18.0 on testnet, having a nightmare trying to understand the inconsistency of this parameter's behaviour.

    It works fine every time, until the remaining balance left in wallet will be lower than an undetermined amount. At that point, it decides to use all of the remainder as extra fees for the supposedly fee inclusive transaction, thereby failing to perform the subtractfeefromamount functionality.

    Examples of my test results:

    Balance 10000, sent 1000 - Balance 9000

    Balance 3000, sent 1600 - Balance 1400

    Balance 1400, sent 1300 - Balance 0

    Balance 8700, sent 8400 - Balance 0

    Balance 10000, sent 9500 - Balance 0

    The format and values of all other parameters and code do not change between tests, only the amount for sending. I do not specify any parameters beyond subtractfee

    There definitely seems to be some mechanism to use all the remainder for fees when the remainder is under a certain amount, but this is terrible and unpredictable, why does it happen and how can it be prevented? Should be reproduceable!

    Thanks

  2. VoxR4710 commented at 12:45 PM on May 27, 2019: none

    To ensure it wasn't to do with json-rpc or my code: bitcoin-cli getbalance 0.00009000 bitcoin-cli sendtoaddress n3qpExEQbF8orkqY7cpmJu6iUhNVHHcnk3 0.00008500 "" "" true 75800f6032ecf46f49b229a81d5ee17c9f5f49ffe1f0863ca148c7e3e42956ec bitcoin-cli getbalance 0.00000000

    What gives ?

  3. MarcoFalke commented at 12:56 PM on May 27, 2019: member

    Is 75800f6032ecf46f49b229a81d5ee17c9f5f49ffe1f0863ca148c7e3e42956ec in the mempool?

  4. VoxR4710 commented at 1:30 PM on May 27, 2019: none

    After a brief googling, I'm still not sure how to tell. Can you tell me? You can add my discord if it's easier. VoxR#1801

    I Can tell you I've left it overnight after a bug transaction to make sure there was nothing about confirmations. That TXID is real by the way you can look up the transaction. I've been coding bitcoin app for a while but I'm still pretty new, sorry.

  5. MarcoFalke commented at 2:52 PM on May 27, 2019: member

    The mempool can only hold a chain of unconfirmed transactions that is of length 25, when you send more than than in a short period of time (i.e. before the txs get confirmed in a block), the mempool will reject them and the wallet is unable to determine the balance.

  6. mzumsande commented at 3:01 PM on May 27, 2019: member

    I'm new too, but this sounds as if in some of the tests the dust limit is reached, i.e. for p2pkh if the outstanding balance would be less than 546 satoshi, no change output is generated and the outstanding amount is instead added to the miner fee.

  7. MarcoFalke commented at 3:09 PM on May 27, 2019: member

    Balance 10000, sent 1000 - Balance 9000

    Is that in BTC or satoshis?

  8. mzumsande commented at 3:26 PM on May 27, 2019: member

    according to the rpc getbalance output in the second post it's satoshis.

  9. MarcoFalke commented at 3:35 PM on May 27, 2019: member

    Ok, closing under the assumption that the amounts are satoshis and that change smaller than the dust is added to the fee.

    This is working as designed.

  10. MarcoFalke closed this on May 27, 2019

  11. promag commented at 3:45 PM on May 27, 2019: member

    Also looks ok to me. Eventually there's no point in creating a change output.

  12. VoxR4710 commented at 5:55 PM on May 27, 2019: none

    Okay, I don't see the use of that and it's unhelpful to me but I'll find a way around it, I'm just glad to know what's going on at this stage!! I'll search for more info on this dust limit because it sounds exactly right. Thankyou and sorry for time waste (though I searched for days and never saw about dust limit )

  13. VoxR4710 commented at 7:45 PM on May 27, 2019: none

    That actually was only part of the problem! I still have some issue with SubtractFeeFromAmount. It makes no sense at all, though. Stay with me on this for a moment , please:

    Balance: 0.00008000 Received: 0.00118410 Balance: 0.00126410 Sent: 0.00118292 Balance: 0.00008000 Sent: 0.00001000 Balance: 0.00007000 Received: 0.00118410 Balance: 0.00125410 Then to make sure once again that it was nothing about PHP or jsonRPC, I use bitcoin-cli directly: bitcoin-cli sendtoaddress n3qpExEQbF8orkqY7cpmJu6iUhNVHHcnk3 0.00118292 "" "" true 50458050f042460ea7199a0d0327edbae153e4e0083cc5862ab64322b31819e9 Balance: 0.00007000 (!)

    How is it possible? Sometimes it works, sometimes it doesn't work? For a long time I thought I had written the parameters wrong for json-RPC, but unless the above command is also wrong, it's not me? All of the above was of course performed with subtractfeefromamount true. Please, if you can help in any way , I am literally a starving developer taking a shot on btc app :(

  14. MarcoFalke commented at 10:01 PM on May 27, 2019: member

    When Bitcoin Core tells you the Balance, it really means the sum of the values of all coins in your wallet. When Bitcoin Core creates a transaction, it really goes through all coins in your wallet and selects a subset of them to use as inputs for the transaction.

    Assume you have a balance of 0.00125410. This could be two coins (0.00007000 + 0.00118410). So sending an amount of 0.00118292 must select a subset that includes at least the coin with value 0.00118410. If it only includes that coin, there would be a change of less than the dust limit. Later on, instead of creating an expensive to spend change output, that dust is added to the tx fee.

  15. VoxR4710 commented at 4:04 AM on May 28, 2019: none

    O_O i have much to learn still, clearly Thank you so much for the response and sorry for making a mess in your board!

  16. 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-05-02 09:15 UTC

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