The bug was caused when
timeTaken > timeExpected * 2 at first round.
Originally, It would be -1, which is absolutely wrong.
So in order to avoid this bug, test if prevAdjustmentBlock.difficulty > 0.
if yes, then return prevAdjustmentBlock.difficulty - 1;
if not , then return prevAdjustmentBlock.difficulty;
The bug was caused when
timeTaken > timeExpected * 2
at first round. Originally, It would be -1, which is absolutely wrong. So in order to avoid this bug, test ifprevAdjustmentBlock.difficulty > 0
. if yes, then return prevAdjustmentBlock.difficulty - 1; if not , then return prevAdjustmentBlock.difficulty;