mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
Added safeguard against running TestDifficulty with a fresh genesis block (#1251)
This commit is contained in:
parent
053bb351b5
commit
9f8f0fd747
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user