Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: capsqrl on September 30, 2012, 07:20:59 PM



Title: How are inputs for transactions selected?
Post by: capsqrl on September 30, 2012, 07:20:59 PM
I was wondering how bitcoin clients (and bitcoin-qt in particular) select inputs for transactions. Are they selected by age (oldest/newest first), to minimize the number of inputs, to minimize the change output, or some other criteria?

Just curious.


Title: Re: How are inputs for transactions selected?
Post by: Revalin on September 30, 2012, 07:45:15 PM
It favors small, old ones to minimize fees and to consolidate the dust in your wallet.

Edit: Wrong, see below.


Title: Re: How are inputs for transactions selected?
Post by: Stephen Gornick on September 30, 2012, 07:48:08 PM
I was wondering how bitcoin clients (and bitcoin-qt in particular) select inputs for transactions. Are they selected by age (oldest/newest first), to minimize the number of inputs, to minimize the change output, or some other criteria?

Just curious.

The algorithm for the client generally aims to come up with the combination of coins that results in the least amount of change.

There are some factors also taking into account.  If the coins haven't confirmed yet, they will not be automatically chosen.

But after a short while, the age of the coins is no longer a factor.

Use the oldest first might give away information and thus take from Bitcoin's privacy, so the "minimize change" is essentially the only goal when choosing which coins to spend.


Title: Re: How are inputs for transactions selected?
Post by: Stephen Gornick on September 30, 2012, 07:55:37 PM
It favors small, old ones to minimize fees and to consolidate the dust in your wallet.

The coin selection is "fee blind", meaning it is not choosing the coins that results in the lowest amount of fees.  It also does not try to consolidate dust.

Quote
The reference client uses a heuristic subset-sum knapsack solver to try to minimize transaction size. It is fee blind, though it is run multiple times excluding less confirmed coins which may sometimes help avoid fees if there are many larger inputs available and minimizing sizes helps with fees (but does not guarantee low fees). Minimizing the current transaction size also does nothing to reduce the amount of data a pruning bitcoin node needs to keep around, in fact it usually does the opposite.

 - http://en.bitcoin.it/wiki/User:Gmaxwell/coin_selection


Title: Re: How are inputs for transactions selected?
Post by: Revalin on September 30, 2012, 07:58:32 PM
Post updated for truthlessness.