extend v4 difficulty algorithm (two variants) #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Correct "invalid" timestamps.
This PR is equal to #5 but
v4-interp2
has lower guards fir the first last block and allow a mx change in hashrate per block by +-20%Why should it be useful to correct the timestamps?
In the perfect blockchain world all system clocks are synced and it is not possible to set an arbitrary time stamp. In that case it will never be possible to have negative block time differences because you can not mine a block before the previous block is known. From that all timestamps are growing with the block index. v4-interp assumes that there are valid timestamps in the sequence of blocks those are used to calculate the difficulty. Valid timestamps are used as boundary condition to correct time stamps to be a sequence with increasing timestamps per block index.
description
This algorithms performs like the v4 implementation. The difference is that there is no 99% reduction to correct the difficulty and negative differences will not be set to zero.
"Invalid" time stamps will be masked and corrected later. Invalid means in the case of
v4-interp
that the difference between two block timestamps is negative. If so it is not clear if the new timestamp is manipulated to point to the past or if the previous is set to the future. Therefore the newer and previous timestamp are marked as invalid.Invalid timestamps are corrected in a second step. A valid previous and a valid time stamp from a future block will be used to interpolate linearly new time stamps for all invalid blocks between this two valid blocks.
The figure show a sequence of block timestamps where a newer block has a time stamp before the previous block. The read blocks are marked as invalid and the timings gets corrected. For the correction the timestamp of block 1 and 4 are used.