Skip to content

Commit d672af7

Browse files
committed
Support NoPowCheck for debug
1 parent 1fc1f0d commit d672af7

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

core/blockchain/blockchain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (b *BlockChain) Init() error {
175175
log.Info(fmt.Sprintf("hash=%s,order=%s,height=%d", v.GetHash(), meerdag.GetOrderLogStr(v.GetOrder()), v.GetHeight()))
176176
}
177177

178-
b.difficultyManager = difficultymanager.NewDiffManager(b.Consensus().BlockChain(), b.params)
178+
b.difficultyManager = difficultymanager.NewDiffManager(b.Consensus(), b.params)
179179
return nil
180180
}
181181

core/types/pow/difficultymanager/difficultymanager.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"github.com/Qitmeer/qng/params"
77
)
88

9-
func NewDiffManager(b model.BlockChain, cfg *params.Params) model.DifficultyManager {
9+
func NewDiffManager(con model.Consensus, cfg *params.Params) model.DifficultyManager {
1010
switch cfg.PowConfig.DifficultyMode {
1111
case pow.DIFFICULTY_MODE_KASPAD:
1212
return &kaspadDiff{
13-
b: b,
13+
con: con,
14+
b: con.BlockChain(),
1415
powMax: cfg.PowConfig.MeerXKeccakV1PowLimit,
1516
difficultyAdjustmentWindowSize: int(cfg.WorkDiffWindowSize),
1617
disableDifficultyAdjustment: false,
@@ -20,7 +21,8 @@ func NewDiffManager(b model.BlockChain, cfg *params.Params) model.DifficultyMana
2021
}
2122
}
2223
return &meerDiff{
23-
b: b,
24+
con: con,
25+
b: con.BlockChain(),
2426
cfg: cfg,
2527
}
2628
}

core/types/pow/difficultymanager/kaspad.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type kaspadDiff struct {
6767
genesisBits uint32
6868
b model.BlockChain
6969
cfg *params.Params
70+
con model.Consensus
7071
}
7172

7273
// CalcEasiestDifficulty calculates the easiest possible difficulty that a block
@@ -114,7 +115,7 @@ func (m *kaspadDiff) RequiredDifficulty(block model.Block, newBlockTime time.Tim
114115

115116
// RequiredDifficultyByWindows returns the difficulty required for some block
116117
func (dm *kaspadDiff) RequiredDifficultyByWindows(targetsWindow blockWindow) (uint32, error) {
117-
if len(targetsWindow) < 1 {
118+
if len(targetsWindow) < 1 || dm.con.Config().NoPowCheck {
118119
return dm.genesisBits, nil
119120
}
120121
return dm.requiredDifficultyFromTargetsWindow(targetsWindow)

core/types/pow/difficultymanager/meer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const maxShift = uint(256)
2929
type meerDiff struct {
3030
b model.BlockChain
3131
cfg *params.Params
32+
con model.Consensus
3233
}
3334

3435
// CalcEasiestDifficulty calculates the easiest possible difficulty that a block
@@ -102,7 +103,7 @@ func (m *meerDiff) RequiredDifficulty(block model.Block, newBlockTime time.Time,
102103
baseTarget := powInstance.GetSafeDiff(0)
103104
originCurrentBlock := block
104105
// Genesis block.
105-
if block == nil {
106+
if block == nil || m.con.Config().NoPowCheck {
106107
return pow.BigToCompact(baseTarget), nil
107108
}
108109

0 commit comments

Comments
 (0)