reward schedule – Where is the bitcoin source code is the 21 million hard cap stated?

[ad_1]

Where is the bitcoin source code is the 21 million hard cap stated?

Nowhere, because there isn’t actually a 21 million cap rule.

The relevant code is this:

CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
    // Force block reward to zero when right shift is undefined.
    if (halvings >= 64)
        return 0;

    CAmount nSubsidy = 50 * COIN;
    // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
    nSubsidy >>= halvings;
    return nSubsidy;
}

// consensusParams.nSubsidyHalvingInterval = 210000.

It computes the maximum subsidy a miner can claim at a given block height, and this function effectively controls Bitcoin’s inflation schedule. The often-stated “21 million” limit is just the approximate result of summing all coins this function permits to be brought into circulation, over all time.

The code, in short, implements the following:

  • The first 210000 blocks (roughly 4 years) allow up to 50 BTC subsidy each.
  • Then 210000 blocks with 25 BTC each
  • Then 210000 blocks with 12.5 BTC each
  • After 10 halvings, the subsidy becomes 0.04882812 BTC rather than 0.048828125 (which would need half-satoshi precision, and the code uses integer division which rounds down).
  • After 33 halvings, the subsidy becomes 0.

If one sums up all the subsidy values over all halvings, the result is 20999999.9769 BTC, not 21000000 BTC. Though, due to various minutiae, that’s also not the real limit; this answer goes into more detail.


Now, the code does also contain this constant:

/** No amount larger than this (in satoshi) is valid.
 *
 * Note that this constant is *not* the total money supply, which in Bitcoin
 * currently happens to be less than 21,000,000 BTC for various reasons, but
 * rather a sanity check. As this sanity check is used by consensus-critical
 * validation code, the exact value of the MAX_MONEY constant is consensus
 * critical; in unusual circumstances like a(nother) overflow bug that allowed
 * for the creation of coins out of thin air modification could lead to a fork.
 * */
static constexpr CAmount MAX_MONEY = 21000000 * COIN;

which, as the comment explains, does not actually control the total supply (as that’s rather the result of summing all the subsidy), but is used as a sanity check in many places.

[ad_2]

Source link

Leave a Comment