diff --git a/blockdag/difficulty.go b/blockdag/difficulty.go index 229be7e7a..5cf6ac3f8 100644 --- a/blockdag/difficulty.go +++ b/blockdag/difficulty.go @@ -15,7 +15,7 @@ import ( // block given its bluest parent. func (dag *BlockDAG) requiredDifficulty(bluestParent *blockNode, newBlockTime mstime.Time) uint32 { // Genesis block. - if bluestParent == nil || bluestParent.blueScore < dag.difficultyAdjustmentWindowSize+1 { + if dag.Params.DisableDifficultyAdjustment || bluestParent == nil || bluestParent.blueScore < dag.difficultyAdjustmentWindowSize+1 { return dag.powMaxBits } diff --git a/blockdag/difficulty_test.go b/blockdag/difficulty_test.go index de016f18c..9080c3cc8 100644 --- a/blockdag/difficulty_test.go +++ b/blockdag/difficulty_test.go @@ -80,7 +80,7 @@ func TestCalcWork(t *testing.T) { } func TestDifficulty(t *testing.T) { - params := dagconfig.SimnetParams + params := dagconfig.MainnetParams params.K = 1 params.DifficultyAdjustmentWindowSize = 264 dag, teardownFunc, err := DAGSetup("TestDifficulty", true, Config{ diff --git a/dagconfig/params.go b/dagconfig/params.go index 2af6e9aa5..a6a101d0e 100644 --- a/dagconfig/params.go +++ b/dagconfig/params.go @@ -178,6 +178,9 @@ type Params struct { // EnableNonNativeSubnetworks enables non-native/coinbase transactions EnableNonNativeSubnetworks bool + + // DisableDifficultyAdjustment determine whether to use difficulty + DisableDifficultyAdjustment bool } // NormalizeRPCServerAddress returns addr with the current network default @@ -235,6 +238,8 @@ var MainnetParams = Params{ // EnableNonNativeSubnetworks enables non-native/coinbase transactions EnableNonNativeSubnetworks: false, + + DisableDifficultyAdjustment: false, } // RegressionNetParams defines the network parameters for the regression test @@ -288,6 +293,8 @@ var RegressionNetParams = Params{ // EnableNonNativeSubnetworks enables non-native/coinbase transactions EnableNonNativeSubnetworks: false, + + DisableDifficultyAdjustment: false, } // TestnetParams defines the network parameters for the test Kaspa network. @@ -339,6 +346,8 @@ var TestnetParams = Params{ // EnableNonNativeSubnetworks enables non-native/coinbase transactions EnableNonNativeSubnetworks: false, + + DisableDifficultyAdjustment: false, } // SimnetParams defines the network parameters for the simulation test Kaspa @@ -394,6 +403,8 @@ var SimnetParams = Params{ // EnableNonNativeSubnetworks enables non-native/coinbase transactions EnableNonNativeSubnetworks: false, + + DisableDifficultyAdjustment: true, } // DevnetParams defines the network parameters for the development Kaspa network. @@ -445,6 +456,8 @@ var DevnetParams = Params{ // EnableNonNativeSubnetworks enables non-native/coinbase transactions EnableNonNativeSubnetworks: false, + + DisableDifficultyAdjustment: false, } var (