Dev, how many blocks need to diff retarget?Speak in the abstract
, Difficulty is adjusted(retarget) based on the time interval of the last two blocks. But it does not rapidly change.To be more specific
, This can be calculated from the previous block’s difficulty level and the timestamp
(Unix’s time() at this block’s inception). difficulty adjustment algorithm : block_diff = parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99) + int(2**((block.number // 100000) - 2))
where // is the integer division operator, eg. 6 // 2 = 3 , 7 // 2 = 3 , 8 // 2 = 4 .simply explain
, If the time between the last two blocks was smaller than 13 seconds, the difficulty goes up. If the time between the last two blocks was larger than 13 seconds, the difficulty goes down. A block mined 1 second after the previous one has the same effect on the difficulty as one mined after 12 seconds.
But it does not radically change. Even mining with the same performance, Lucky mining will create a short timestamp interval. In the opposite case it will have long interval.