Skip to content

Instantly share code, notes, and snippets.

@gavinandresen
Last active December 16, 2015 15:09
Show Gist options
  • Save gavinandresen/5453840 to your computer and use it in GitHub Desktop.
Save gavinandresen/5453840 to your computer and use it in GitHub Desktop.
Short-term fee fix

Transaction fee handling is quickly becoming an issue, due to several factors:

  1. Bitcoin prices rising.
  2. Transaction volume increasing, and competition for space in blocks beginning.
  3. People with too much cash on their hands deciding to bloat the blockchain with data.

I propose the following band-aid, quick fix for the 0.8.2 release:

Modify the definition of CTransaction::IsStandard() as follows:

BOOST_FOREACH(const CTxOut& txout, vout) {
    if (!::IsStandard(txout.scriptPubKey))
        return false;
    if (txout.nValue == 0)
        return false;
}

becomes:

BOOST_FOREACH(const CTxOut& txout, vout) {
    if (!::IsStandard(txout.scriptPubKey))
        return false;
    if ((txout.nValue*1000)/(3*txout.size()) < MIN_RELAY_TX_FEE)
        return false; // Dust outputs non-standard
}

The intuitive meaning of that 3* ... formula is "if a transaction output is less than 3 times the fee it will cost to spend it, it is dust."

MIN_RELAY_TX_FEE is minimum fee-per-kilobyte, and is 0.0001. A pay-to-bitcoin-address txout is 33 bytes, so 'normal' transactions that are less then 10 uBTC are considered dust.

Make sure the transaction creation code never creates dust outputs as change (if it would, the output should be deleted and just added to fee paid).

Teach the GUI and RPC interfaces to return reasonable errors/messages if users/web services try to create transactions with dust outputs.

Finally: Un-hardcode MIN_RELAY_TX_FEE / MIN_TX_FEE; allow them to be set with a new command-line switch at startup, so if bitcoin prices continue to rise quickly OR transaction volume increases quickly we can ask users/miners to change them manually.

This would be a first step towards having smart code that automatically figured out an appropriate value for MIN_RELAY_TX_FEE. I think all of the above changes are fairly safe and straightforward and could be implemented quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment