- snip -
Need to generate 1 block at the and of 15 days period and it will cause 4x difficulty drop.
- snip -
Not true.
Difficulty adjusts after 2016 blocks. NOT after 15 days.
If blocks happen at near NORMAL speed (average 1 block every nearly 10 minutes) then difficulty adjusts after approximately 14 days:
2016 blocks * 10 minutes = 20160 minutes = 336 hours = 14 days
If there is not enough hash power and therefore blocks take longer, then difficulty takes longer to adjust.
2016 blocks * average 40 minutes per block = 80640 minutes = 1344 hours = 56 days until difficulty adjusts 4X
See code here:
https://github.com/bitcoin/bitcoin/blob/1b046603b30ebfab6199a2f92015d507b248b590/src/pow.cpp#L19Specifies params.DifficultyAdjustmentInterval:
// Only change once per difficulty adjustment interval
if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
{
...
params.DifficultyAdjustmentInterval calculated here:
https://github.com/bitcoin/bitcoin/blob/1b046603b30ebfab6199a2f92015d507b248b590/src/consensus/params.h#L63int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
nPowTargetTimespan is set here:
https://github.com/bitcoin/bitcoin/blob/1b046603b30ebfab6199a2f92015d507b248b590/src/chainparams.cpp#L79consensus.nPowTargetTimespan = 14 * 24 * 60 * 60;
Note: 14*24*60*60 = 1209600
nPowTargetSpacing is set here:
https://github.com/bitcoin/bitcoin/blob/1b046603b30ebfab6199a2f92015d507b248b590/src/chainparams.cpp#L80consensus.nPowTargetSpacing = 10 * 60;
Note: 10 * 60 = 600
So, DifficultyAdjustmentInterval = 1209600 / 600 = 2016
So, adjustment happens when:
(pindexLast->nHeight+1) === 2016
In other words...
Only once every 2016 blocks.