lhartikk / naivecoin

A tutorial for building a cryptocurrency
https://lhartikk.github.io/
Apache License 2.0
531 stars 266 forks source link

fix issue during mining #7

Open zoeleesss opened 6 years ago

zoeleesss commented 6 years ago

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;