Add option to avoid spending unconfirmed change #3651

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2014_02_spend_zeroconf_change_option changing 3 files +5 −1
  1. laanwj commented at 3:21 PM on February 11, 2014: member

    Adds the option -spendzeroconfchange=0 to make the wallet avoid spending zero conf change outputs.

    Rough workaround to the problems with '-4. Error: The transaction was rejected!' and other problems with chains of unconfirmed transactions and malleability.

    The drawback of this is that sending will run out of inputs sooner (resulting in unintuitive "insufficient balance" errors), so if you have a lot of sends you'll need to queue up sends and use sendmany.

  2. Add option to avoid spending unconfirmed change 1bbca249b2
  3. BitcoinPullTester commented at 3:47 PM on February 11, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/1bbca249b202c4802cc2c4d4de4a26e6392b4d92 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  4. petertodd commented at 4:31 PM on February 11, 2014: contributor

    Might make sense to make it -minconfstospend so you can ask for more than one confirmation for those who can wait. (reorgs)

  5. gavinandresen commented at 4:40 PM on February 11, 2014: contributor

    ACK code changes.

  6. laanwj commented at 4:59 PM on February 11, 2014: member

    Note that getbalance will still be counting unconfirmed change after this patch. GetBalance doesn't use AvailableCoins.

    Another option that would affect the balance computation as well as coin selection may be to put the condition in CWalletTx::IsConfirmed instead (here https://github.com/bitcoin/bitcoin/blob/master/src/wallet.h#L707).

    This would change the functionality from "don't spend unconfirmed change" to "don't count unconfirmed change at all". Not sure if that's desirable, but it's a possibility...

  7. sipa commented at 5:06 PM on February 11, 2014: member

    Setting minconf=1 on send* RPCs should have the same effect.

  8. petertodd commented at 5:07 PM on February 11, 2014: contributor

    The impression I get is the getbalance issue is less important than ensuring unconfirmed tx's don't get spent; I'd get this patch done and do something more complex with getbalance later. @sipa Good point!

  9. petertodd commented at 5:07 PM on February 11, 2014: contributor

    This patch is useful for all users too after all.

  10. sipa commented at 5:09 PM on February 11, 2014: member

    An alternative to this is just checking whether unconfirmed coins are in the mempool, before considering them available. That will be more transparent, should always be right, and less restrictive.

  11. petertodd commented at 5:10 PM on February 11, 2014: contributor

    @sipa That doesn't fix the issue; they could be mutated in a mempool elsewhere.

  12. laanwj commented at 5:11 PM on February 11, 2014: member

    @sipa I thought minconf wouldn't have effect on your own unconfirmed change, but that would be great, in that case no patch is needed at all.

    Re: checking mempool as I asked through mail would that solve all the issues? What if another transaction variant gets mined than is in the (local) mempool?

  13. petertodd commented at 5:12 PM on February 11, 2014: contributor

    I mean, specifically the problem is when I tell bitcoind to make a payment, I want that payment to go through. If I spend confirmed inputs the transaction making the payment might get mutated, but it will get mined eventually and the payment will happen without any further intervention. Spending unconfirmed in a mempool doesn't have that guarantee, and similarly there's the edge case of a reorganization with, say, single confirmation coins.

  14. sipa commented at 5:13 PM on February 11, 2014: member

    @laanwj When searching for coins to spend, we always consider just the confirmed ones first (and the >=6 confirmed ones before that), so preventing payments in case not enough balance exists in confirmed coins should be enough to prevent unconfirmed change from being used. @petertodd @laanwj You're right, ignore my suggestion.

  15. laanwj commented at 5:24 PM on February 11, 2014: member

    @sipa But minconf already defaults to 1 on sendfrom/sendmany. And it still spends unconfirmed change.

  16. sipa commented at 6:34 PM on February 11, 2014: member

    @laanwj In that case something is going on that I'm missing.

  17. gmaxwell commented at 7:09 PM on February 11, 2014: contributor

    @laanwj All minconf does on those rpcs is changes what it checks for deciding the account has enough balance, it has no influence on coin-selection.

  18. gmaxwell commented at 7:18 PM on February 11, 2014: contributor

    ACK this change, it improves a minor privacy leak too (when you spend unconfirmed change it was very very likely change, and not a third party payment). It's too disruptive to turn on by default, alas.

  19. petertodd commented at 7:47 PM on February 11, 2014: contributor

    @gmaxwell Right now the alternative is more disruptive; turn it on by default. Other wallets already work that way with user acceptance, and users can easily turn it off again once malleability becomes less of a issue.

  20. jgarzik commented at 9:07 PM on February 11, 2014: contributor

    Bleh, nobody will ever use this, defaulted off.

    ACK, merge it, then let's create a new PR immediately, to discuss changing the default! :)

  21. laanwj referenced this in commit 19e5b9d2df on Feb 11, 2014
  22. laanwj merged this on Feb 11, 2014
  23. laanwj closed this on Feb 11, 2014

  24. laanwj commented at 9:19 PM on February 11, 2014: member

    See #3654

  25. dooglus commented at 1:27 AM on February 12, 2014: contributor

    @sipa > In that case something is going on that I'm missing.

    I guess what's happening is that we have enough confirmed coins to make up the amount being sent, but not enough to include the required fee. So we end up using unconfirmed change.

  26. sipa commented at 1:39 AM on February 12, 2014: member

    That would be one hell of a coincidence, and there many people reporting failed transactions being created.

  27. dooglus commented at 1:55 AM on February 12, 2014: contributor

    Maybe most of those failed transactions are created using sendtoaddress, which doesn't have a minconf argument.

  28. sipa commented at 2:05 AM on February 12, 2014: member

    Oh, then I misread @laanwj's comment. Yeah, that would explain it...

  29. riecoin referenced this in commit f0c711c457 on Feb 20, 2014
  30. laanwj deleted the branch on Apr 9, 2014
  31. 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-13 15:16 UTC

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