Use genesis difficulty for private networks

This commit is contained in:
Chris Purta 2018-07-06 10:40:43 -07:00
parent 1990c9e621
commit 4f926086ee

View file

@ -297,6 +297,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
next := new(big.Int).Add(parent.Number, big1)
switch {
case isPrivateNetwork(config):
return parent.Difficulty
case config.IsByzantium(next):
return calcDifficultyByzantium(time, parent)
case config.IsHomestead(next):
@ -306,6 +308,15 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade
}
}
// isPrivateNetwork is a helper function to determine if the current
// chain is a private network or not based on the configurations
// ChainID.
func isPrivateNetwork(config *params.ChainConfig) bool {
return config.ChainID != params.MainnetChainConfig.ChainID ||
config.ChainID != params.TestChainConfig.ChainID ||
config.ChainID != params.RinkebyChainConfig.ChainID
}
// Some weird constants to avoid constant memory allocs for them.
var (
expDiffPeriod = big.NewInt(100000)