Skip to content

Commit

Permalink
Setting the Min Difficutly based on the genesis block difficutly
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Sep 14, 2023
1 parent ff521f2 commit f75a117
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
15 changes: 15 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,24 +1247,31 @@ func setConsensusEngineConfig(ctx *cli.Context, cfg *ethconfig.Config) {
case ctx.GlobalBool(ColosseumFlag.Name):
cfg.Blake3Pow.DurationLimit = params.DurationLimit
cfg.Blake3Pow.GasCeil = params.ColosseumGasCeil
cfg.Blake3Pow.MinDifficulty = new(big.Int).Div(core.DefaultColosseumGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(GardenFlag.Name):
cfg.Blake3Pow.DurationLimit = params.GardenDurationLimit
cfg.Blake3Pow.GasCeil = params.GardenGasCeil
cfg.Blake3Pow.MinDifficulty = new(big.Int).Div(core.DefaultGardenGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(OrchardFlag.Name):
cfg.Blake3Pow.DurationLimit = params.OrchardDurationLimit
cfg.Blake3Pow.GasCeil = params.OrchardGasCeil
cfg.Blake3Pow.MinDifficulty = new(big.Int).Div(core.DefaultOrchardGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(LighthouseFlag.Name):
cfg.Blake3Pow.DurationLimit = params.LighthouseDurationLimit
cfg.Blake3Pow.GasCeil = params.LighthouseGasCeil
cfg.Blake3Pow.MinDifficulty = new(big.Int).Div(core.DefaultLighthouseGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(LocalFlag.Name):
cfg.Blake3Pow.DurationLimit = params.LocalDurationLimit
cfg.Blake3Pow.GasCeil = params.LocalGasCeil
cfg.Blake3Pow.MinDifficulty = new(big.Int).Div(core.DefaultLocalGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(DeveloperFlag.Name):
cfg.Blake3Pow.DurationLimit = params.DurationLimit
cfg.Blake3Pow.GasCeil = params.LocalGasCeil
cfg.Blake3Pow.MinDifficulty = new(big.Int).Div(core.DefaultLocalGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
default:
cfg.Blake3Pow.DurationLimit = params.DurationLimit
cfg.Blake3Pow.GasCeil = params.GasCeil
cfg.Blake3Pow.MinDifficulty = new(big.Int).Div(core.DefaultColosseumGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)

}
} else {
Expand All @@ -1273,24 +1280,32 @@ func setConsensusEngineConfig(ctx *cli.Context, cfg *ethconfig.Config) {
case ctx.GlobalBool(ColosseumFlag.Name):
cfg.Progpow.DurationLimit = params.DurationLimit
cfg.Progpow.GasCeil = params.ColosseumGasCeil
cfg.Progpow.MinDifficulty = new(big.Int).Div(core.DefaultColosseumGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(GardenFlag.Name):
cfg.Progpow.DurationLimit = params.GardenDurationLimit
cfg.Progpow.GasCeil = params.GardenGasCeil
cfg.Progpow.MinDifficulty = new(big.Int).Div(core.DefaultGardenGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(OrchardFlag.Name):
cfg.Progpow.DurationLimit = params.OrchardDurationLimit
cfg.Progpow.GasCeil = params.OrchardGasCeil
cfg.Progpow.GasCeil = params.ColosseumGasCeil
cfg.Progpow.MinDifficulty = new(big.Int).Div(core.DefaultOrchardGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(LighthouseFlag.Name):
cfg.Progpow.DurationLimit = params.LighthouseDurationLimit
cfg.Progpow.GasCeil = params.LighthouseGasCeil
cfg.Progpow.MinDifficulty = new(big.Int).Div(core.DefaultLighthouseGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(LocalFlag.Name):
cfg.Progpow.DurationLimit = params.LocalDurationLimit
cfg.Progpow.GasCeil = params.LocalGasCeil
cfg.Progpow.MinDifficulty = new(big.Int).Div(core.DefaultLocalGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
case ctx.GlobalBool(DeveloperFlag.Name):
cfg.Progpow.DurationLimit = params.DurationLimit
cfg.Progpow.GasCeil = params.LocalGasCeil
cfg.Progpow.MinDifficulty = new(big.Int).Div(core.DefaultLocalGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)
default:
cfg.Progpow.DurationLimit = params.DurationLimit
cfg.Progpow.GasCeil = params.GasCeil
cfg.Progpow.MinDifficulty = new(big.Int).Div(core.DefaultColosseumGenesisBlock(cfg.ConsensusEngine).Difficulty, common.Big2)

}
}
Expand Down
2 changes: 2 additions & 0 deletions consensus/blake3pow/blake3pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Config struct {

GasCeil uint64

MinDifficulty *big.Int

// When set, notifications sent by the remote sealer will
// be block header JSON objects instead of work package arrays.
NotifyFull bool
Expand Down
4 changes: 2 additions & 2 deletions consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ func (blake3pow *Blake3pow) CalcDifficulty(chain consensus.ChainHeaderReader, pa
x.Add(x, parent.Difficulty())

// minimum difficulty can ever be (before exponential factor)
if x.Cmp(params.MinimumDifficulty) < 0 {
x.Set(params.MinimumDifficulty)
if x.Cmp(blake3pow.config.MinDifficulty) < 0 {
x.Set(blake3pow.config.MinDifficulty)
}
return x
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/progpow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ func (progpow *Progpow) CalcDifficulty(chain consensus.ChainHeaderReader, parent
x.Add(x, parent.Difficulty())

// minimum difficulty can ever be (before exponential factor)
if x.Cmp(params.MinimumDifficulty) < 0 {
x.Set(params.MinimumDifficulty)
if x.Cmp(progpow.config.MinDifficulty) < 0 {
x.Set(progpow.config.MinDifficulty)
}
return x
}
Expand Down
1 change: 1 addition & 0 deletions consensus/progpow/progpow.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ type Config struct {
CachesLockMmap bool
DurationLimit *big.Int
GasCeil uint64
MinDifficulty *big.Int

// When set, notifications sent by the remote sealer will
// be block header JSON objects instead of work package arrays.
Expand Down
1 change: 1 addition & 0 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ func (sl *Slice) NewGenesisPendingHeader(domPendingHeader *types.Header) {
genesisTermini.SetSubTerminiAtIndex(genesisHash, i)
}
if sl.hc.Empty() {
domPendingHeader.SetTime(uint64(time.Now().Unix()))
sl.phCache.Add(sl.config.GenesisHash, types.NewPendingHeader(domPendingHeader, genesisTermini))
}
}
Expand Down
2 changes: 2 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func CreateProgpowConsensusEngine(stack *node.Node, chainConfig *params.ChainCon
NotifyFull: config.NotifyFull,
DurationLimit: config.DurationLimit,
GasCeil: config.GasCeil,
MinDifficulty: config.MinDifficulty,
}, notify, noverify)
engine.SetThreads(-1) // Disable CPU mining
return engine
Expand All @@ -203,6 +204,7 @@ func CreateBlake3ConsensusEngine(stack *node.Node, chainConfig *params.ChainConf
NotifyFull: config.NotifyFull,
DurationLimit: config.DurationLimit,
GasCeil: config.GasCeil,
MinDifficulty: config.MinDifficulty,
}, notify, noverify)
engine.SetThreads(-1) // Disable CPU mining
return engine
Expand Down

0 comments on commit f75a117

Please sign in to comment.