Post
Topic
Board Development & Technical Discussion
Re: Is the 21 million bitcoin limit unchangeable?
by
archaeopteryx
on 22/03/2013, 09:28:30 UTC
21000000 * COIN is the theoretical upperbound of bitcoin's entire money supply. Of course no one account or transaction can have more than that number, so it is used to check that a given money value is within the valid range.

To understand how this limit came about, you need to understand the function GetBlockValue() that give rise to the upperbound of 21M * COIN: MAX_MONEY = 2 * 210000 * 50 * COIN

Code:
int64 static GetBlockValue(int nHeight, int64 nFees)
{
    int64 nSubsidy = 50 * COIN;

    // Subsidy is cut in half every 210000 blocks, which will occur approximately every 4 years
    nSubsidy >>= (nHeight / 210000);

    return nSubsidy + nFees;
}

I think I understand the GetBlockValue function (I spent most of my allotted time in the newbie pool digging through the Bitcoin source code and asking some questions). The math works out to be 20,999,999.9769 total Bitcoins mined at block #6,930,000 if I calculated it correctly. What I don't quite understand is the purpose for this line:

Code:
inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

as a transaction will never even come close to that amount, and neither will any given Bitcoin address. Given the ~21 million COIN limit created by GetBlockValue, why is it necessary to check "nValue" to make sure it is within 0 - 21,000,000?