subtractFeeFromOutputs option in fundrawtransaction RPC call is not working as expected on v22.0 #23026

issue yurayakimenko openend this issue on September 18, 2021
  1. yurayakimenko commented at 3:45 pm on September 18, 2021: none

    Expected behavior When I’m trying to send full balance from node to some another address (transaction have many inputs and only one output) on node versions 19.0 and 20.0 - it’s working fine. I’m just set amount for transactions equal to node’s confirmed balance and set "subtractFeeFromOutputs": [0] for fundrawtransaction RPC call.

    So the expected result - node is leaving empty (without balance) after this transaction and fees are subtracted from first input (without any need in manual subtraction and calculation).

    Actual behavior On version 22.0 for the same RPC request (as I wrote above) I got an error -4: Insufficient funds.

    To reproduce Try to send all node’s balance in one transaction to some external BTC address with "subtractFeeFromOutputs": [0] option.

    System information Bitcoin Core 22.0 Linux 3.10.0-1160.15.2.el7.x86_64 x86_64 CentOS Linux 7.9.2009

  2. yurayakimenko added the label Bug on Sep 18, 2021
  3. fanquake added the label Wallet on Sep 20, 2021
  4. meshcollider commented at 11:40 am on September 27, 2021: contributor

    I am unable to reproduce this, could you please post the exact series of commands you made (minus any personal info)?

    Can you confirm that the transaction you are trying to fund does indeed have just one output and that it is greater than the fee you need to pay?

  5. DevMinJong commented at 2:19 pm on November 15, 2021: none
    @yurayakimenko Did you solve it? It’s the same issue.
  6. MarcoFalke commented at 2:25 pm on November 15, 2021: member
    There is nothing we can do without additional information. If you can’t provide the exact series of commands as requested above, an excerpt of the feecalc in the debug log might help (obv. stripping private info).
  7. MarcoFalke added the label Waiting for author on Nov 15, 2021
  8. DevMinJong commented at 2:58 pm on November 15, 2021: none

    @yurayakimenko @MarcoFalke The update has been completed from version 0.17.1 to 22.0, and the fundrawtransaction function is throwing an error in version 22.0.

    v0.17.1 cli

    ./bitcoin-cli getbalance 1.07338220

    ./bitcoin-cli decoderawtransaction 020000000001ecd96506000000001976a91408339cb23bbb53bf38f68bc087febb238108f96c88ac00000000

     0{
     1  "txid": "59817e88b6a431a70093f39b0c12ed0788f94dc05d9ab5cb2f56c00a736ff4c2",
     2  "hash": "59817e88b6a431a70093f39b0c12ed0788f94dc05d9ab5cb2f56c00a736ff4c2",
     3  "version": 2,
     4  "size": 44,
     5  "vsize": 44,
     6  "weight": 176,
     7  "locktime": 0,
     8  "vin": [
     9  ],
    10  "vout": [
    11    {
    12      "value": 1.07338220,
    13      "n": 0,
    14      "scriptPubKey": {
    15        "asm": "OP_DUP OP_HASH160 08339cb23bbb53bf38f68bc087febb238108f96c OP_EQUALVERIFY OP_CHECKSIG",
    16        "hex": "76a91408339cb23bbb53bf38f68bc087febb238108f96c88ac",
    17        "address": "1kNEc94p77fsqCvATZroPPR38KT9KTsXj",
    18        "type": "pubkeyhash",
    19        "addresses": [
    20          "1kNEc94p77fsqCvATZroPPR38KT9KTsXj"
    21        ],
    22        "reqSigs": 1
    23      }
    24    }
    25  ]
    26}
    

    ./bitcoin-cli fundrawtransaction “020000000001ecd96506000000001976a91408339cb23bbb53bf38f68bc087febb238108f96c88ac00000000” “{"subtractFeeFromOutputs":[0]}”

    success response

    v22.0 cli

    ./bitcoin-cli getbalance 1.07338220

    ./bitcoin-cli decoderawtransaction 020000000001ecd96506000000001976a91408339cb23bbb53bf38f68bc087febb238108f96c88ac00000000

     0{
     1  "txid": "59817e88b6a431a70093f39b0c12ed0788f94dc05d9ab5cb2f56c00a736ff4c2",
     2  "hash": "59817e88b6a431a70093f39b0c12ed0788f94dc05d9ab5cb2f56c00a736ff4c2",
     3  "version": 2,
     4  "size": 44,
     5  "vsize": 44,
     6  "weight": 176,
     7  "locktime": 0,
     8  "vin": [
     9  ],
    10  "vout": [
    11    {
    12      "value": 1.07338220,
    13      "n": 0,
    14      "scriptPubKey": {
    15        "asm": "OP_DUP OP_HASH160 08339cb23bbb53bf38f68bc087febb238108f96c OP_EQUALVERIFY OP_CHECKSIG",
    16        "hex": "76a91408339cb23bbb53bf38f68bc087febb238108f96c88ac",
    17        "address": "1kNEc94p77fsqCvATZroPPR38KT9KTsXj",
    18        "type": "pubkeyhash",
    19        "addresses": [
    20          "1kNEc94p77fsqCvATZroPPR38KT9KTsXj"
    21        ],
    22        "reqSigs": 1
    23      }
    24    }
    25  ]
    26}
    

    ./bitcoin-cli fundrawtransaction “020000000001ecd96506000000001976a91408339cb23bbb53bf38f68bc087febb238108f96c88ac00000000” “{"subtractFeeFromOutputs":[0]}” Insufficient funds

  9. MarcoFalke commented at 3:22 pm on November 15, 2021: member
    How many coins are in the wallet and what feerate is being targeted? It might be that the two version target different feerates.
  10. DevMinJong commented at 2:44 am on November 17, 2021: none

    @MarcoFalke @yurayakimenko Wallet’s balance was sufficient to pay a fee, and we used “subractFeeFromOutputs” as a “fundrawtransaction” option to transfer all of the money from the account. However, if the feeRate is set high, the amount to pay the fee is sufficient, but an “Insufficient Funds” error occurs.

    v0.17.1

    ./bitcoin-cli getbalance 0.02747781

    ./bitcoin-cli createrawtransaction [] “[{"1BoN7fHjtdufAL4ZjVnbW38SsAMbQwPK4R":0.02747781}]” 02000000000185ed2900000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000

    [high feeRate case] ./bitcoin-cli fundrawtransaction “02000000000185ed2900000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000” “{"subtractFeeFromOutputs":[0], "feeRate":0.01016711}”

    0{
    1  "hex": "020000001183fb588c5ceae790f627fd76278fefbe7ecb414ae3c83678746b5a7c32b9b5b70000000000fdffffff1dc5e5d10a325c739924ee0f990171eb1660ca24f6038dec6c69799721590ba90000000000fdffffffda529a6edd29c32b1f746ac39d1b28776543a6aed5c330007b0756743ee2f8420000000000fdfffffff3dd6ea5b7fc0540a179162cbd1b9c25e82d7d5c0ad6a7e086dcba4f4f9798760100000000fdffffff57afa33e56d3cdcc752cfae9e0b44b8e9608400d07e5ddd122669426b29ea9c80100000000fdffffffccee315e4800d7ac0696c8f8845d9985573882f1483d95572c3465226fd872d40000000000fdffffff4ed7188988b48dcd81723fed788cd72811173c88557dc0e807867b2c116cbf640000000000fdffffff342d28a62a5f005adcb1bbc8eae7640377c78b643e5cb2642235e58498047b200000000000fdffffff4ffdff99026432d641b7be05979661088f74ea5304649102c090cebb552e1e1e0000000000fdffffffc39083c8b187b4feec0c93a64d7e0b3377dbb4d436d5b869f42a8c863af685b50000000000fdffffff4ae03f15b3f1ccfe1d1672e94098bb56add36bbd7d6cfba187c7ec61af42aa830000000000fdfffffff9c4284c741c018136e588b921a3dc365c9a3d93f2b788f523dced9a3f3b53ff0100000000fdffffff90c43d6d07ce04c8676376cbabdd9293cc251320d3dfa065ffe22524f14207150100000000fdffffffae5ba3902ba27be221261ec4a19e88cebec6e7d37c7264170a0b4304b3f94fd50000000000fdffffffc579ad3661c6999eeff283f97d3b2bd119d449c18e46fa28fb4d344493d3ce280100000000fdffffff3db96066d514891dececeadf3cc9f75cec457aa78cc5dbd2f7f6c8254674df950000000000fdffffff69a8eeeefbc5912636d3c715c73581525db4de907556e1c132c1d4436030cf700100000000fdffffff01147c0300000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000",
    2  "fee": 0.02519409,
    3  "changepos": -1
    4}
    

    ./bicoin-cli decderawtransaction “020000001183fb588c5ceae790f627fd76278fefbe7ecb414ae3c83678746b5a7c32b9b5b70000000000fdffffff1dc5e5d10a325c739924ee0f990171eb1660ca24f6038dec6c69799721590ba90000000000fdffffffda529a6edd29c32b1f746ac39d1b28776543a6aed5c330007b0756743ee2f8420000000000fdfffffff3dd6ea5b7fc0540a179162cbd1b9c25e82d7d5c0ad6a7e086dcba4f4f9798760100000000fdffffff57afa33e56d3cdcc752cfae9e0b44b8e9608400d07e5ddd122669426b29ea9c80100000000fdffffffccee315e4800d7ac0696c8f8845d9985573882f1483d95572c3465226fd872d40000000000fdffffff4ed7188988b48dcd81723fed788cd72811173c88557dc0e807867b2c116cbf640000000000fdffffff342d28a62a5f005adcb1bbc8eae7640377c78b643e5cb2642235e58498047b200000000000fdffffff4ffdff99026432d641b7be05979661088f74ea5304649102c090cebb552e1e1e0000000000fdffffffc39083c8b187b4feec0c93a64d7e0b3377dbb4d436d5b869f42a8c863af685b50000000000fdffffff4ae03f15b3f1ccfe1d1672e94098bb56add36bbd7d6cfba187c7ec61af42aa830000000000fdfffffff9c4284c741c018136e588b921a3dc365c9a3d93f2b788f523dced9a3f3b53ff0100000000fdffffff90c43d6d07ce04c8676376cbabdd9293cc251320d3dfa065ffe22524f14207150100000000fdffffffae5ba3902ba27be221261ec4a19e88cebec6e7d37c7264170a0b4304b3f94fd50000000000fdffffffc579ad3661c6999eeff283f97d3b2bd119d449c18e46fa28fb4d344493d3ce280100000000fdffffff3db96066d514891dececeadf3cc9f75cec457aa78cc5dbd2f7f6c8254674df950000000000fdffffff69a8eeeefbc5912636d3c715c73581525db4de907556e1c132c1d4436030cf700100000000fdffffff01147c0300000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000”

     0{
     1  "txid": "2e6d8121885968861261a9473f889af0abfccd32f784178eb20dc62ec6bad8e4",
     2  "hash": "2e6d8121885968861261a9473f889af0abfccd32f784178eb20dc62ec6bad8e4",
     3  "version": 2,
     4  "size": 741,
     5  "vsize": 741,
     6  "weight": 2964,
     7  "locktime": 0,
     8  "vin": [
     9    {
    10      "txid": "b7b5b9327c5a6b747836c8e34a41cb7ebeef8f2776fd27f690e7ea5c8c58fb83",
    11      "vout": 0,
    12      "scriptSig": {
    13        "asm": "",
    14        "hex": ""
    15      },
    16      "sequence": 4294967293
    17    },
    18    {
    19      "txid": "a90b59219779696cec8d03f624ca6016eb7101990fee2499735c320ad1e5c51d",
    20      "vout": 0,
    21      "scriptSig": {
    22        "asm": "",
    23        "hex": ""
    24      },
    25      "sequence": 4294967293
    26    }
    27
    28....
    29  ],
    30  "vout": [
    31    {
    32      "value": 0.00228372,
    33      "n": 0,
    34      "scriptPubKey": {
    35        "asm": "OP_DUP OP_HASH160 76760491fdf2f1dc5428c79058c49e93fc432b81 OP_EQUALVERIFY OP_CHECKSIG",
    36        "hex": "76a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac",
    37        "reqSigs": 1,
    38        "type": "pubkeyhash",
    39        "addresses": [
    40          "1BoN7fHjtdufAL4ZjVnbW38SsAMbQwPK4R"
    41        ]
    42      }
    43    }
    44  ]
    45}
    

    v22.0

    ./bitcoin-cli getbalance 0.02747781

    ./bitcoin-cli createrawtransaction [] “[{"1BoN7fHjtdufAL4ZjVnbW38SsAMbQwPK4R":0.02747781}]” 02000000000185ed2900000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000

    [Appropriate fee case] ./bitcoin-cli fundrawtransaction “02000000000185ed2900000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000” “{"subtractFeeFromOutputs":[0], "feeRate":0.00006711}”

    0{
    1  "hex": "020000001190c43d6d07ce04c8676376cbabdd9293cc251320d3dfa065ffe22524f14207150100000000fdffffff83fb588c5ceae790f627fd76278fefbe7ecb414ae3c83678746b5a7c32b9b5b70000000000fdffffff69a8eeeefbc5912636d3c715c73581525db4de907556e1c132c1d4436030cf700100000000fdffffff4ed7188988b48dcd81723fed788cd72811173c88557dc0e807867b2c116cbf640000000000fdffffff4ffdff99026432d641b7be05979661088f74ea5304649102c090cebb552e1e1e0000000000fdffffff3db96066d514891dececeadf3cc9f75cec457aa78cc5dbd2f7f6c8254674df950000000000fdffffff342d28a62a5f005adcb1bbc8eae7640377c78b643e5cb2642235e58498047b200000000000fdffffffda529a6edd29c32b1f746ac39d1b28776543a6aed5c330007b0756743ee2f8420000000000fdffffffae5ba3902ba27be221261ec4a19e88cebec6e7d37c7264170a0b4304b3f94fd50000000000fdffffff57afa33e56d3cdcc752cfae9e0b44b8e9608400d07e5ddd122669426b29ea9c80100000000fdffffff1dc5e5d10a325c739924ee0f990171eb1660ca24f6038dec6c69799721590ba90000000000fdfffffff3dd6ea5b7fc0540a179162cbd1b9c25e82d7d5c0ad6a7e086dcba4f4f9798760100000000fdffffffccee315e4800d7ac0696c8f8845d9985573882f1483d95572c3465226fd872d40000000000fdffffff4ae03f15b3f1ccfe1d1672e94098bb56add36bbd7d6cfba187c7ec61af42aa830000000000fdffffffc39083c8b187b4feec0c93a64d7e0b3377dbb4d436d5b869f42a8c863af685b50000000000fdfffffff9c4284c741c018136e588b921a3dc365c9a3d93f2b788f523dced9a3f3b53ff0100000000fdffffffc579ad3661c6999eeff283f97d3b2bd119d449c18e46fa28fb4d344493d3ce280100000000fdffffff0190ac2900000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000",
    2  "fee": 0.00016629,
    3  "changepos": -1
    4}
    

    [high fee case] ./bitcoin-cli fundrawtransaction “02000000000185ed2900000000001976a91476760491fdf2f1dc5428c79058c49e93fc432b8188ac00000000” " {"subtractFeeFromOutputs":[0], "feeRate":0.00006712}"

    0error code: -4
    1error message:
    2Insufficient funds
    

    ##. In the above case, v22.0 shows a normal response if the feeRate is 0.00006711 or less, and an error if it is 0.00006712 or higher. Can I know why?

  11. achow101 commented at 4:41 am on November 17, 2021: member

    This is likely due to filtering for negative effective value inputs (i.e. UTXOs that cost more to spend than value they provide). Some of the inputs appear to be fairly small, so at high(er) feerates, their effective values become less than or equal to zero. In 22.0, the first coin selection algorithm, BnB, requires that effective values are positive. If one or more of your UTXOs are filtered out because their effective values are too low, the remaining UTXOs do not have enough value to meet the target when BnB is run. The second algorithm, Knapsack, does not require positive effective values. However it assumes that a change output will be made and so it increases the target to account for the change output (this is probably a bug for the subtract fee from outputs case). With an increased target, your wallet does not have enough funds to reach it, and so Knapsack also fails. Hence there is an insufficient funds error.

    Coin selection has changed quite a bit since 0.17.1 so that’s why there is a difference.

  12. MarcoFalke added this to the milestone 22.1 on Nov 17, 2021
  13. MarcoFalke removed the label Waiting for author on Nov 17, 2021
  14. meshcollider commented at 2:59 am on November 22, 2021: contributor
    @yurayakimenko would you be able to test #23534 and see if it fixes your issue?
  15. MarcoFalke commented at 10:28 am on March 31, 2022: member
    Should this bug be closed, now that #23534 is also closed?
  16. Xekyo commented at 6:41 pm on May 9, 2022: member
    Yes, this issue should be addressed per the new sendall RPC introduced by #24118.
  17. laanwj closed this on May 9, 2022

  18. DrahtBot locked this on May 9, 2023

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-25 09:12 UTC

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