Take the 2-minute tour ×
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

According to the Wiki:

If the blocksize is more than 250 kB, transactions get increasingly more expensive as the blocksize approaches the limit of 500 kB. Sending a transaction when the blocksize is 400 kB will cost 5 times the normal amount; sending when it's 499 kB will cost 500x, etc.

What is the exact formula that determines the transaction fee?

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

See GetMinFee() in main.h for the code which determines the minimum transaction fee.

The part you're describing is implemented as follows:

// Raise the price as the block approaches full
if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2)
{
    if (nNewBlockSize >= MAX_BLOCK_SIZE_GEN)
        return MAX_MONEY;
    nMinFee *= MAX_BLOCK_SIZE_GEN / (MAX_BLOCK_SIZE_GEN - nNewBlockSize);
}

where:

  • nBlockSize depends on who we are:
    • if we're a user making a new transaction, nBlockSize is 1
    • if we're a node deciding whether to relay an incoming transaction, nBlockSize is 1000
    • if we're a miner deciding which transactions to include in a new block, nBlockSize is the size of the block we're building before adding the new transaction
  • nNewBlockSize is the size of the block including the new transaction
  • MAX_BLOCK_SIZE_GEN is 500kB
  • MAX_MONEY is 21 million BTC (all the money in the world)

so it's saying:

  • if we're either deciding whether to relay or mine the transaction, and adding the transaction would make the block over 50% full:
    • never allow a transaction that makes the block 100% full
    • otherwise scale the fee up by a factor of 500kB / (500kB - nNewBlockSize)

Note: by rearranging the symbols, we get exactly what Meni wrote in his answer:

Fee = Normal fee / ((500kB - size) / 500kB) = Normal fee / (1 - size / 500kB)

share|improve this answer
    
That rule is pretty strange, and doesn't look stable to me, since it's against the miners interests. –  CodesInChaos Apr 9 '12 at 20:24
2  
It's not against the miner's interests. If the miner fills up the block with low-fee transactions, he loses the opportunity to get high-fee transaction in there. Remember, not all transactions are the same size, so you can't just go in fee order. (The optimum algorithm would be to sort the transactions into two pools, one for fee transactions in fee-per-byte order, the other for free transactions in priority order. Fill a block from the first pool in order if possible until no more paid transactions fit, then take as many from the second pool as fit.) –  David Schwartz Apr 12 '12 at 5:23
    
@DavidSchwartz I argue that miners will converge to a fee-per-byte auction instead of this algorithm because that's in their interest. You agree with the fee-per-byte part, but disagree with the current algorithm being against miners interest. So your comment seems inconsistent to me. –  CodesInChaos Apr 16 '12 at 15:18
    
@CodeInChaos: The effort required to act in their interest would actually make it not in their interest overall. The difference between an ideal algorithm and the current one, today, is about 0.02% or so. It's like driving across town to pay a penny a gallon less for gas. –  David Schwartz Apr 16 '12 at 18:20
    
Even if the algorithm wouldn't require a fee, if the the coin used for input is new a fee still could be required: bitcointalk.org/index.php?topic=84434.msg931988#msg931988 –  Stephen Gornick May 31 '12 at 3:56
add comment

I don't know the formula from any authoritative source, but based on the examples in the text, it is

Fee = Normal fee / (1 - Block size / 500KB)

Or equivalently (and I suspect the actual code uses this form)

Fee = Normal fee * (500 KB) / (500KB - Block size)
share|improve this answer
    
Did you add the "Or equivalently" part after posting your initial answer? There's no "edited by..." under your question, but I could swear your answer was originally half its current size. –  Chris Moore Apr 9 '12 at 18:57
    
@ChrisMoore: The author of a post can edit it during some time (5 minutes I think) without the change showing up as an edit. –  D.H. Apr 9 '12 at 19:33
    
@ChrisMoore: You are of course correct, as is D.H. . –  Meni Rosenfeld Apr 10 '12 at 7:18
    
Where is the "Normal fee" defined for this calculation? –  Highly Irregular May 16 '12 at 3:59
add comment

The other answers describe the rules currently implemented in the client, but I expect those rules to be replaced once block size limits become relevant. Since those rules aren't enforced when clients verify the blockchain, they are only guidelines, and will be violated if they're against the interest of miners.

Miners will simply choose the subset of candidate transactions that respects the limits (blocksize and signature count) and maximizes the fee.

Disregarding a few minor complications (knapsack and dependent transactions) this means that miners sort the transactions by fee/transactionSize if the maximal size is the limiting factor, and fee/signatureCount if the signature count is the limiting factor.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.