Bitcoin Forum
September 27, 2018, 10:22:15 PM *
News: ♦♦ New info! Bitcoin Core users absolutely must upgrade to previously-announced 0.16.3 [Torrent]. All Bitcoin users should temporarily trust confirmations slightly less. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: How are block rewards calculated in the Bitcoin code?  (Read 905 times)
cloudboy
Hero Member
*****
Offline Offline

Activity: 689
Merit: 500


View Profile
April 28, 2014, 07:08:18 AM
 #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.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
DannyHamilton
Legendary
*
Offline Offline

Activity: 2198
Merit: 1373



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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!