## Where, in the code, in the Satoshi client is 21 million cap implemented?

7

1

Which fragment of the Satoshi client is verifying if announced block has a valid reward?

I mean, we now live in the 25 BTC reward period. I guess client after receiving a newly minted block, does verifications, like checking if inputs and outputs are balancing for example, and, I guess, if the reward is 25 BTC, right?

So where is this fragment of the code?

I know where is the code which limits BTC supply to 21 million:

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


...and I am looking for somebody to point me to the right place, where the verification is done.

Just a note that the relevant code resides here now: https://github.com/bitcoin/bitcoin/blob/0d20c42a014ff95aab1447a92605c3a194cfeecc/src/validation.cpp#L1080-L1091 (it's also link that should work forever ).

– meeDamian – 2019-09-10T17:07:42.327

6

There are 3 places where GetBlockValue is called. One is on incoming blocks, one is on blocks we're mining, and one is an error message. This is the one for incoming blocks:

if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
return state.DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)));


Source

This looks at the first transaction (the coinbase transaction) and checks the value. If it is larger than the subsidy plus the fees, then the block is rejected and the node that sent the block is blacklisted.

Beat me by a second in posting this. – David Ogren – 2013-04-18T21:33:49.453

@DavidOgren We've all been there at one point or another. :| – Nick ODell – 2013-04-18T21:37:09.480

Yours was more detailed in the explanation than mine anyway. – David Ogren – 2013-04-18T22:03:04.440