2

I've changed MAX_MONEY to decrease the number of coins issued in my altcoin, but it's not working.

Why?

  • 2
    Check where MAX_MONEY is used, and you'll see it does not affect subsidy. It only limits the values being allowed in transactions. – Pieter Wuille Mar 27 '15 at 19:01
4

Despite the name, the MAX_MONEY constant is not used in determining the total maximum number of coins. Rather, it is used only for a sanity check: any transaction output larger than MAX_MONEY is automatically rejected as invalid. They simply set this new constant equal to the eventual maximum number of Bitcoins, since that is a value that certainly should never be exceeded by any output. This was part of the fix to an early bug where only the sum of all outputs for a transaction was checked, leading to the possibility that the addition might overflow.

The block subsidy (aka reward) is computed in the GetBlockSubsidy function in validation.cpp.

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;
}

Here you can see the initial block reward of 50 coins is hard coded. The halving interval consensusParams.nSubsidyHalvingInterval is set in chainparams.cpp in the constructors for CMainParams, CTestNetParams and CRegTestParams respectively (the respective default values are 210000, 210000, 150). Note that MAX_MONEY does not appear.

So in order to change your coin's total money supply, you'll need to do a little math to decide what the initial block reward and halving interval should be, and modify them accordingly. If you want the reward adjusted by any other mechanism than "continue halving until the reward reaches zero", then you'll have to rewrite the GetBlockSubsidy function. (And you should also change MAX_MONEY to an appropriate value that should never be exceeded by any transaction output.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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