Skip to content

Add option to avoid spending unconfirmed change - #3651

Merged
laanwj merged 1 commit into
bitcoin:masterfrom
laanwj:2014_02_spend_zeroconf_change_option
Feb 11, 2014
Merged

laanwj merged 1 commit into
bitcoin:masterfrom
laanwj:2014_02_spend_zeroconf_change_option

Conversation

@laanwj

@laanwj laanwj commented Feb 11, 2014

Copy link
Copy Markdown
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.

@BitcoinPullTester

Copy link
Copy Markdown

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.

@petertodd

Copy link
Copy Markdown
Contributor

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

@gavinandresen

Copy link
Copy Markdown
Contributor

ACK code changes.

@laanwj

laanwj commented Feb 11, 2014

Copy link
Copy Markdown
Member Author

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...

@sipa

sipa commented Feb 11, 2014

Copy link
Copy Markdown
Member

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

@petertodd

Copy link
Copy Markdown
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!

@petertodd

Copy link
Copy Markdown
Contributor

This patch is useful for all users too after all.

@sipa

sipa commented Feb 11, 2014

Copy link
Copy Markdown
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.

@petertodd

Copy link
Copy Markdown
Contributor

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

@laanwj

laanwj commented Feb 11, 2014

Copy link
Copy Markdown
Member Author

@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?

@petertodd

Copy link
Copy Markdown
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.

@sipa

sipa commented Feb 11, 2014

Copy link
Copy Markdown
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.

@laanwj

laanwj commented Feb 11, 2014

Copy link
Copy Markdown
Member Author

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

@sipa

sipa commented Feb 11, 2014

Copy link
Copy Markdown
Member

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

@gmaxwell

Copy link
Copy Markdown
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.

@gmaxwell

Copy link
Copy Markdown
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.

@petertodd

Copy link
Copy Markdown
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.

@jgarzik

jgarzik commented Feb 11, 2014

Copy link
Copy Markdown
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! :)

laanwj added a commit that referenced this pull request Feb 11, 2014
1bbca24 Add option to avoid spending unconfirmed change (Wladimir J. van der Laan)
@laanwj
laanwj merged commit 1bbca24 into bitcoin:master Feb 11, 2014
@laanwj

laanwj commented Feb 11, 2014

Copy link
Copy Markdown
Member Author

See #3654

@dooglus

dooglus commented Feb 12, 2014

Copy link
Copy Markdown
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.

@sipa

sipa commented Feb 12, 2014

Copy link
Copy Markdown
Member

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

@dooglus

dooglus commented Feb 12, 2014

Copy link
Copy Markdown
Contributor

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

@sipa

sipa commented Feb 12, 2014

Copy link
Copy Markdown
Member

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

riecoin pushed a commit to riecoin/riecoin that referenced this pull request Feb 20, 2014
- added option -spendzeroconfchange to workaround tx malleability problem
    as in bitcoin#3651
- added seed nodes
- added checkpoints
- Chinese translations fixed
- difficulty field in getinfo, getmininginfo, getdifficulty now return
    the same as getwork: the size of the primes measured in bits. Note
    that this is not linear: 1500 is not 3x harder than 1000. It's like
    700 times harder.
- fixed DoS (crash) vulnerability in PoW calculation
@laanwj
laanwj deleted the 2014_02_spend_zeroconf_change_option branch April 9, 2014 14:10
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants