mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-1589] Re-enable DisableDifficultyAdjustment (#1182)
* [NOD-1589] Re-enable DisableDifficultyAdjustment * [NOD-1589] Remove simnet from TestDifficulty * [NOD-1589] Update comment
This commit is contained in:
parent
c3902ed7a8
commit
4886425caf
@ -126,6 +126,7 @@ func (f *factory) NewConsensus(dagParams *dagconfig.Params, db infrastructuredat
|
||||
dagTraversalManager,
|
||||
dagParams.PowMax,
|
||||
dagParams.DifficultyAdjustmentWindowSize,
|
||||
dagParams.DisableDifficultyAdjustment,
|
||||
dagParams.TargetTimePerBlock,
|
||||
dagParams.GenesisHash)
|
||||
coinbaseManager := coinbasemanager.New(
|
||||
@ -148,8 +149,6 @@ func (f *factory) NewConsensus(dagParams *dagconfig.Params, db infrastructuredat
|
||||
dagParams.SkipProofOfWork,
|
||||
genesisHash,
|
||||
dagParams.EnableNonNativeSubnetworks,
|
||||
dagParams.DisableDifficultyAdjustment,
|
||||
dagParams.DifficultyAdjustmentWindowSize,
|
||||
dagParams.MaxBlockSize,
|
||||
dagParams.MergeSetSizeLimit,
|
||||
dagParams.MaxBlockParents,
|
||||
|
@ -11,16 +11,14 @@ import (
|
||||
// blockValidator exposes a set of validation classes, after which
|
||||
// it's possible to determine whether either a block is valid
|
||||
type blockValidator struct {
|
||||
powMax *big.Int
|
||||
skipPoW bool
|
||||
genesisHash *externalapi.DomainHash
|
||||
enableNonNativeSubnetworks bool
|
||||
disableDifficultyAdjustment bool
|
||||
powMaxBits uint32
|
||||
difficultyAdjustmentWindowSize uint64
|
||||
maxBlockSize uint64
|
||||
mergeSetSizeLimit uint64
|
||||
maxBlockParents model.KType
|
||||
powMax *big.Int
|
||||
skipPoW bool
|
||||
genesisHash *externalapi.DomainHash
|
||||
enableNonNativeSubnetworks bool
|
||||
powMaxBits uint32
|
||||
maxBlockSize uint64
|
||||
mergeSetSizeLimit uint64
|
||||
maxBlockParents model.KType
|
||||
|
||||
databaseContext model.DBReader
|
||||
difficultyManager model.DifficultyManager
|
||||
@ -44,8 +42,6 @@ func New(powMax *big.Int,
|
||||
skipPoW bool,
|
||||
genesisHash *externalapi.DomainHash,
|
||||
enableNonNativeSubnetworks bool,
|
||||
disableDifficultyAdjustment bool,
|
||||
difficultyAdjustmentWindowSize uint64,
|
||||
maxBlockSize uint64,
|
||||
mergeSetSizeLimit uint64,
|
||||
maxBlockParents model.KType,
|
||||
@ -68,16 +64,14 @@ func New(powMax *big.Int,
|
||||
blockStatusStore model.BlockStatusStore) model.BlockValidator {
|
||||
|
||||
return &blockValidator{
|
||||
powMax: powMax,
|
||||
skipPoW: skipPoW,
|
||||
genesisHash: genesisHash,
|
||||
enableNonNativeSubnetworks: enableNonNativeSubnetworks,
|
||||
disableDifficultyAdjustment: disableDifficultyAdjustment,
|
||||
powMaxBits: util.BigToCompact(powMax),
|
||||
difficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
||||
maxBlockSize: maxBlockSize,
|
||||
mergeSetSizeLimit: mergeSetSizeLimit,
|
||||
maxBlockParents: maxBlockParents,
|
||||
powMax: powMax,
|
||||
skipPoW: skipPoW,
|
||||
genesisHash: genesisHash,
|
||||
enableNonNativeSubnetworks: enableNonNativeSubnetworks,
|
||||
powMaxBits: util.BigToCompact(powMax),
|
||||
maxBlockSize: maxBlockSize,
|
||||
mergeSetSizeLimit: mergeSetSizeLimit,
|
||||
maxBlockParents: maxBlockParents,
|
||||
|
||||
databaseContext: databaseContext,
|
||||
difficultyManager: difficultyManager,
|
||||
|
@ -22,12 +22,12 @@ type difficultyManager struct {
|
||||
genesisHash *externalapi.DomainHash
|
||||
powMax *big.Int
|
||||
difficultyAdjustmentWindowSize uint64
|
||||
disableDifficultyAdjustment bool
|
||||
targetTimePerBlock time.Duration
|
||||
}
|
||||
|
||||
// New instantiates a new DifficultyManager
|
||||
func New(
|
||||
databaseContext model.DBReader,
|
||||
func New(databaseContext model.DBReader,
|
||||
ghostdagManager model.GHOSTDAGManager,
|
||||
ghostdagStore model.GHOSTDAGDataStore,
|
||||
headerStore model.BlockHeaderStore,
|
||||
@ -35,9 +35,9 @@ func New(
|
||||
dagTraversalManager model.DAGTraversalManager,
|
||||
powMax *big.Int,
|
||||
difficultyAdjustmentWindowSize uint64,
|
||||
disableDifficultyAdjustment bool,
|
||||
targetTimePerBlock time.Duration,
|
||||
genesisHash *externalapi.DomainHash,
|
||||
) model.DifficultyManager {
|
||||
genesisHash *externalapi.DomainHash) model.DifficultyManager {
|
||||
return &difficultyManager{
|
||||
databaseContext: databaseContext,
|
||||
ghostdagManager: ghostdagManager,
|
||||
@ -47,6 +47,7 @@ func New(
|
||||
dagTraversalManager: dagTraversalManager,
|
||||
powMax: powMax,
|
||||
difficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
|
||||
disableDifficultyAdjustment: disableDifficultyAdjustment,
|
||||
targetTimePerBlock: targetTimePerBlock,
|
||||
genesisHash: genesisHash,
|
||||
}
|
||||
@ -63,13 +64,12 @@ func (dm *difficultyManager) genesisBits() (uint32, error) {
|
||||
|
||||
// RequiredDifficulty returns the difficulty required for some block
|
||||
func (dm *difficultyManager) RequiredDifficulty(blockHash *externalapi.DomainHash) (uint32, error) {
|
||||
|
||||
parents, err := dm.dagTopologyManager.Parents(blockHash)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// Genesis block
|
||||
if len(parents) == 0 {
|
||||
// Genesis block or network that doesn't have difficulty adjustment (such as simnet)
|
||||
if len(parents) == 0 || dm.disableDifficultyAdjustment {
|
||||
return dm.genesisBits()
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,9 @@ import (
|
||||
|
||||
func TestDifficulty(t *testing.T) {
|
||||
testutils.ForAllNets(t, true, func(t *testing.T, params *dagconfig.Params) {
|
||||
if params.DisableDifficultyAdjustment {
|
||||
return
|
||||
}
|
||||
params.K = 1
|
||||
params.DifficultyAdjustmentWindowSize = 264
|
||||
|
||||
@ -118,7 +121,7 @@ func TestDifficulty(t *testing.T) {
|
||||
switch params.Name {
|
||||
case "kaspa-testnet", "kaspa-devnet":
|
||||
expectedBits = uint32(0x1e7f83df)
|
||||
case "kaspa-mainnet", "kaspa-simnet":
|
||||
case "kaspa-mainnet":
|
||||
expectedBits = uint32(0x207f83df)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user