4

Bitcoin Core's Coin Selection optimizes for minimal change outputs. How does Bitcoin Core prevent Change outputs of sizes below dust threshold from occurring?

Murch
  • 75,206
  • 34
  • 186
  • 622
  • This question is wrong, as Bitcoin Core actually creates a minimum change of 0.01 BTC, if it can't produce a direct match. – Murch Oct 19 '16 at 22:55

2 Answers2

2

See these lines:

// We do not move dust-change to fees, because the sender would end up paying more than requested.
// This would be against the purpose of the all-inclusive feature.
// So instead we raise the change and deduct from the recipient.
if (nSubtractFeeFromAmount > 0 && newTxOut.IsDust(::minRelayTxFee))
{
    CAmount nDust = newTxOut.GetDustThreshold(::minRelayTxFee) - newTxOut.nValue;
    newTxOut.nValue += nDust; // raise change until no more dust
    for (unsigned int i = 0; i < vecSend.size(); i++) // subtract from first recipient
    {
        if (vecSend[i].fSubtractFeeFromAmount)
        {
            txNew.vout[i].nValue -= nDust;
            if (txNew.vout[i].IsDust(::minRelayTxFee))
            {
                strFailReason = _("The transaction amount is too small to send after the fee has been deducted");
                return false;
            }
            break;
        }
    }
}

So Bitcoin core will give slightly less to the recipient rather than spend more than the payer originally requested, in the case of a dust-change output.

morsecoder
  • 14,168
  • 2
  • 42
  • 94
  • 1
    Then there's the question of whether or not this is a good policy... I don't believe it is. I think that as infrequently as dust change happens, just let miners have it and get a slightly faster confirmation time. – morsecoder Sep 01 '15 at 11:59
  • It might not be good network policy, but it doesn't seem like users have an incentive to destroy dust UTXO's sent to them. – Nick ODell Sep 02 '15 at 04:00
0

Bitcoin Core actually creates a minimum change of 0.01 BTC (if it has sufficient funds), if it can't produce a direct match.

In the rare case that it doesn't have sufficient funds to produce a non-dust change output, it will do the weird stuff Stephen mentions.

Murch
  • 75,206
  • 34
  • 186
  • 622