Bitcoin Forum
November 05, 2024, 07:59:08 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How are block rewards calculated in the Bitcoin code?  (Read 992 times)
cloudboy (OP)
Hero Member
*****
Offline Offline

Activity: 690
Merit: 501


View Profile
April 28, 2014, 07:08:18 AM
Last edit: April 28, 2014, 07:32:26 AM by cloudboy
 #1

I see the GetBlockValue() function:

Code:
int64_t GetBlockValue(int nHeight, int64_t nFees)
{
    int64_t nSubsidy = 50 * COIN;
    int halvings = nHeight / Params().SubsidyHalvingInterval();

    // Force block reward to zero when right shift is undefined.
    if (halvings >= 64)
        return nFees;

    // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
    nSubsidy >>= halvings;

    return nSubsidy + nFees;
}

I understand that the bitwise right shift once nHeight is large enough will halve the block reward. What I am confused about is
  • Why nSubsidy is 50 (initial reward) multiplied by 100 million? -- I realized that COIN is 100million satoshis.
  • halvings will be 0 until nHeight is more than  Params().SubsidyHalvingInterval(), but why won't nSubsidy halve with every subsequent nHeight, until nHeight is 2 x Params().SubsidyHalvingInterval() ? -- nSubsidy is always then reset to 50 BTC, and then the bitwise right shift is performed. Can't believe I missed that haha.

Sorry if these have been answered or seem trivial. Looking at this code for the first time can be a little overwhelming when you aren't familiar with it. Thank you.

--Update: Figured it out. Maybe it will be useful for someone else in the future. Mods please close.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3472
Merit: 4801



View Profile
April 28, 2014, 01:21:21 PM
 #2

Mods please close.

You can close your own threads.

Bottom left corner of the page you should see a link that says "lock topic".
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!