Skip to content

Commit

Permalink
Adjust difficulty managment between rusty and golang nodes during the…
Browse files Browse the repository at this point in the history
… first block window
  • Loading branch information
okilisan committed Sep 2, 2024
1 parent 44d8ed6 commit c7ac35d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/karlsenminer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {

// Show version at startup.
log.Infof("Version %s", version.Version())
log.Infof("Using KarlsenHashV2 impl: %s", pow.GetHashingAlgoVersion())
log.Infof("Miner compatibility KarlsenHashV1 & KarlsenHashV2 impl: %s", pow.GetHashingAlgoVersion())

// Enable http profiling server if requested.
if cfg.Profile != "" {
Expand Down
2 changes: 1 addition & 1 deletion domain/consensus/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type GHOSTDAGManagerConstructor func(

// DifficultyManagerConstructor is the function signature for a constructor of a type implementing model.DifficultyManager
type DifficultyManagerConstructor func(model.DBReader, model.GHOSTDAGManager, model.GHOSTDAGDataStore,
model.BlockHeaderStore, model.DAABlocksStore, model.DAGTopologyManager, model.DAGTraversalManager, *big.Int, int, bool, time.Duration,
model.BlockHeaderStore, model.DAABlocksStore, model.DAGTopologyManager, model.DAGTraversalManager, *big.Int, int, int, bool, time.Duration,
*externalapi.DomainHash, uint32) model.DifficultyManager

// PastMedianTimeManagerConstructor is the function signature for a constructor of a type implementing model.PastMedianTimeManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type difficultyManager struct {
genesisHash *externalapi.DomainHash
powMax *big.Int
difficultyAdjustmentWindowSize int
minDifficultyWindowLen int
disableDifficultyAdjustment bool
targetTimePerBlock time.Duration
genesisBits uint32
Expand All @@ -41,6 +42,7 @@ func New(databaseContext model.DBReader,
dagTraversalManager model.DAGTraversalManager,
powMax *big.Int,
difficultyAdjustmentWindowSize int,
minDifficultyWindowLen int,
disableDifficultyAdjustment bool,
targetTimePerBlock time.Duration,
genesisHash *externalapi.DomainHash,
Expand All @@ -55,6 +57,7 @@ func New(databaseContext model.DBReader,
dagTraversalManager: dagTraversalManager,
powMax: powMax,
difficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
minDifficultyWindowLen: minDifficultyWindowLen,
disableDifficultyAdjustment: disableDifficultyAdjustment,
targetTimePerBlock: targetTimePerBlock,
genesisHash: genesisHash,
Expand Down Expand Up @@ -117,7 +120,8 @@ func (dm *difficultyManager) requiredDifficultyFromTargetsWindow(targetsWindow b
// We could instead clamp the timestamp difference to `targetTimePerBlock`,
// but then everything will cancel out and we'll get the target from the last block, which will be the same as genesis.
// We add 64 as a safety margin
if len(targetsWindow) < 2 || len(targetsWindow) < dm.difficultyAdjustmentWindowSize {
//if len(targetsWindow) < 2 || len(targetsWindow) < dm.difficultyAdjustmentWindowSize {
if len(targetsWindow) < 2 || len(targetsWindow) < dm.minDifficultyWindowLen {
return dm.genesisBits, nil
}

Expand Down
8 changes: 8 additions & 0 deletions domain/dagconfig/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ type Params struct {
// to calculate the required difficulty of each block.
DifficultyAdjustmentWindowSize int

// MinDifficultyWindowLen is the minimum size of window that can be inspected
// under this value the genesis difficulty is sent.
MinDifficultyWindowLen int

// These fields are related to voting on consensus rule changes as
// defined by BIP0009.
//
Expand Down Expand Up @@ -234,6 +238,7 @@ var MainnetParams = Params{
TargetTimePerBlock: defaultTargetTimePerBlock,
FinalityDuration: defaultFinalityDuration,
DifficultyAdjustmentWindowSize: defaultDifficultyAdjustmentWindowSize,
MinDifficultyWindowLen: 10,
TimestampDeviationTolerance: defaultTimestampDeviationTolerance,

// Consensus rule change deployments.
Expand Down Expand Up @@ -303,6 +308,7 @@ var TestnetParams = Params{
TargetTimePerBlock: defaultTargetTimePerBlock,
FinalityDuration: defaultFinalityDuration,
DifficultyAdjustmentWindowSize: defaultDifficultyAdjustmentWindowSize,
MinDifficultyWindowLen: 10,
TimestampDeviationTolerance: defaultTimestampDeviationTolerance,

// Consensus rule change deployments.
Expand Down Expand Up @@ -372,6 +378,7 @@ var SimnetParams = Params{
TargetTimePerBlock: time.Millisecond,
FinalityDuration: time.Minute,
DifficultyAdjustmentWindowSize: defaultDifficultyAdjustmentWindowSize,
MinDifficultyWindowLen: 10,
TimestampDeviationTolerance: defaultTimestampDeviationTolerance,

// Consensus rule change deployments.
Expand Down Expand Up @@ -433,6 +440,7 @@ var DevnetParams = Params{
TargetTimePerBlock: defaultTargetTimePerBlock,
FinalityDuration: defaultFinalityDuration,
DifficultyAdjustmentWindowSize: defaultDifficultyAdjustmentWindowSize,
MinDifficultyWindowLen: 10,
TimestampDeviationTolerance: defaultTimestampDeviationTolerance,

// Consensus rule change deployments.
Expand Down

0 comments on commit c7ac35d

Please sign in to comment.