0 sats \ 2 replies \ @Distivboy_87 19 May 2023 \ on: Daily discussion thread
Just trying out to write the program code for the next Bitcoin Halving (fourth halving in 2024) that is using C programming language.
Making the use of The GetBlockSubsidy() function;
CAmount GetBlockSubsidy(int nHeight, const Concensus::Params& consensusParams)
{
int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
// Force block reward to zero when right shiftis undefined.
if (halvings >= 64)
return 0;
cAmount nSubsidy = 50 * COIN;
//Subsidy is cut in half every after 210, 000 blocks which will occur approximately every four years
nSubsidy >>= halvings;
return nSubsidy
}
Hints:
- consensusParams.nSubsidyHalvingInterval means consensus rules everyone on the bitcoin network needs to honour.
- consensus.nSubsidyHalvingInterval = 210, 000; i.e every 210, 000 blocks a halving occurs
- nHeight is the current block height or the number of blocks that have already happen
- Soon, we shall reach block 840,000 i.e 210,000*4, At this point (Year 2024) the equation becomes Int halvings = 840,000/210,000; which will give halvings the value of 4 (the fourth time the network shall halved)
- if (halvings >= 64) return 0; i.e Force block reward to zero when right shift is undefined and once there have been 64 halvings, there should be no further nSubsidy released cAmount nSubsidy = 50 * COIN; nSubsidy >>= halvings; return nSubsidy; this means that: cAmount nSubsidy = 50 * 100000000; (each coin is divided into 100, 000, 000 units) nSubsidy >>=4; return nSubsidy i.e At the very start, 50 Bitcoin were rewarded for every block found on the network. Then after 210, 000 blocks (first halving) 25 Bitcoin was rewarded. 12.5 Bitcoin reward for the second halving. Third halving which is where we are today, the reward is 6.25 Bitcoin. Therefore, for the fourth halving which is in the year 2024 the reward shall be 3.125 Bitcoin.
Any constructive additions or subtractions are welcome!
Just trying out to write the program code for the next Bitcoin Halving (fourth halving in 2024) that is using C programming language.
I don't get what you are trying to do. But looking at your hints, I would guess you are trying to explain how the function works?
reply
Of course, that's a function of block subsidy and reward halving
reply