- Blockchain By Example
- Bellaj Badr Richard Horrocks Xun (Brian) Wu
- 169字
- 2021-06-10 18:53:44
Halving
For Bitcoin, the mining reward is cut in half every 210,000 blocks, which will occur approximately every four years. In Bitcoin, the reward, initially set to 50 BTC, fell to 25 BTC in late 2012, to 12.5 BTC in 2016 and so forth, until the reward tends to 0 at the 64th halving.
To change the halving rule, in chainparams.cpp, you have to edit the following parameter:
consensus.nSubsidyHalvingInterval = 210000;
Let's reschedule the halving interval in main and test at 100,000 blocks, equivalent to 174 days.
In src/validation.cpp, the halving mechanism formula is defined in the GetBlockSubsidy function, which determines the reward amount at a specific height in the blockchain:
In this instance, we have the following:
- nHeight is the number of blocks that have been found.
- consensusParams.nSubsidyHalvingInterval specifies the halving's interval block.
- nSubsidy finally gives the number of satoshi that the coinbase may create.
After another number of blocks equivalent to nSubsidyHalvingInterval, the reward halves again. Thus, the number of bitcoins in circulation asymptotically approaches nSubsidy*nSubsidyHalvingInterval*2.