Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Corrected the PoW adjustment parameters. #151
With the current parameters the Diff adjustment will be more dynamic. I have made the percentage of lowering the difficulty twice higher, because if some of the major pools stops this could lead to really slow block time, that way it will be reduced at a good speed.
If you go with N=30 instead of N=40, the correction factor will be about 1.02.
The following shows how it will vary on a daily basis, and how it will very likely vary when it goes live due to hash attacks. The peaks after the red bars (hash attacks) are the price your constant miners have to pay as big miners come on briefly to get cheap blocks.
If you want to write your own difficulty algorithm, currently the best one available is shown below. Jacob Eliosoff came up with this a few days ago, using his stock analysis knowledge. It needs protection against "negative" solvetimes. You could stick with Zcash's MTP but you'll be 5 blocks slow. A better method is to use Tom Harold's limit on timestamps when getting your solvetimes. I threw in a 10 because I do not want a solvetime near zero. The algo is in the chart. You do not even need to go through a loop. You just look at previous D and previous SolveTime.
You can see the hash attacks can't be as long as in N=30 before the algorithm responds and the post-attack delays are not as bad.
For comparison, here's the unmodified Zcash code.
@StarbuckBG It's using N=30 without the 1.02 correction? (next_D would be a little more accurate if it's 0.98 of the calculation.) Not doing this will mean 2% longer average solvetime, so expect avg to be 612 instead of 600 seconds. Also, if you see distinct oscillations in the difficulty, it is very probably caused by using MTP for nLastBlockTime (end of the averaging window).
Where can I get a CSV list of height, difficulty, and timestamp? I'm really interested in seeing any effects the 32/16 and MTP work out OK with N=30. Judging by bitcoin cash, the N=30 is a really good choice. They used N=144. oops.