Added safeguard against running TestDifficulty with a fresh genesis block (#1251)

This commit is contained in:
Svarog 2020-12-21 11:30:43 +02:00 committed by GitHub
parent 053bb351b5
commit 9f8f0fd747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -47,7 +47,6 @@ func (v *blockValidator) checkParentsLimit(header *externalapi.DomainBlockHeader
}
func (v *blockValidator) checkBlockTimestampInIsolation(header *externalapi.DomainBlockHeader) error {
blockTimestamp := header.TimeInMilliseconds
now := mstime.Now().UnixMilliseconds()
maxCurrentTime := now + int64(v.timestampDeviationTolerance)*v.targetTimePerBlock.Milliseconds()

View File

@ -2,6 +2,9 @@ package difficultymanager_test
import (
"testing"
"time"
"github.com/kaspanet/kaspad/util/mstime"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
@ -18,6 +21,14 @@ func TestDifficulty(t *testing.T) {
if params.DisableDifficultyAdjustment {
return
}
// This test generates 3066 blocks above genesis with at least 1 second between each block, amounting to
// a bit less then an hour of timestamps.
// To prevent rejected blocks due to timestamps in the future, the following safeguard makes sure
// the genesis block is at least 1 hour in the past.
if params.GenesisBlock.Header.TimeInMilliseconds > mstime.ToMSTime(time.Now().Add(-time.Hour)).UnixMilliseconds() {
t.Fatalf("TestDifficulty requires the GenesisBlock to be at least 1 hour old to pass")
}
params.K = 1
params.DifficultyAdjustmentWindowSize = 264