diff --git a/consensus/blake3pow/consensus.go b/consensus/blake3pow/consensus.go index 2dd72f879e..2893ffad5c 100644 --- a/consensus/blake3pow/consensus.go +++ b/consensus/blake3pow/consensus.go @@ -301,6 +301,7 @@ func (blake3pow *Blake3pow) CalcDifficulty(chain consensus.ChainHeaderReader, ti // given the parent block's time and difficulty. // NOTE: This is essentially the Ethereum DAA, without a 'difficulty bomb' func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int { + nodeCtx := common.NodeLocation.Context() // https://github.com/ethereum/EIPs/issues/100. // algorithm: // diff = (parent_diff + @@ -314,9 +315,9 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade x := new(big.Int) y := new(big.Int) - // (2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // 9 + // (2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // duration_limit x.Sub(bigTime, bigParentTime) - x.Div(x, big9) + x.Div(x, params.DurationLimit[nodeCtx]) if parent.UncleHash() == types.EmptyUncleHash { x.Sub(big1, x) } else { @@ -332,8 +333,8 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade x.Add(parent.Difficulty(), x) // minimum difficulty can ever be (before exponential factor) - if x.Cmp(params.MinimumDifficulty) < 0 { - x.Set(params.MinimumDifficulty) + if x.Cmp(params.MinimumDifficulty[nodeCtx]) < 0 { + x.Set(params.MinimumDifficulty[nodeCtx]) } return x diff --git a/params/protocol_params.go b/params/protocol_params.go index 8d9af485b2..38a12cd626 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -162,8 +162,11 @@ const ( var Bls12381MultiExpDiscountTable = [128]uint64{1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180, 179, 179, 178, 177, 176, 176, 175, 174} var ( - DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations. - MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be. - GenesisDifficulty = []*big.Int{big.NewInt(131072), big.NewInt(131072), big.NewInt(131072)} // Difficulty of the Genesis block. - DurationLimit = []*big.Int{big.NewInt(13), big.NewInt(13), big.NewInt(13)} // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. + DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations. + ZoneMinDifficulty = big.NewInt(131072) // The minimum difficulty in a zone. Prime & regions should be multiples of this value + RegionMinDifficulty = new(big.Int).Mul(big.NewInt(10), ZoneMinDifficulty) + PrimeMinDifficulty = new(big.Int).Mul(big.NewInt(10), RegionMinDifficulty) + MinimumDifficulty = []*big.Int{PrimeMinDifficulty, RegionMinDifficulty, ZoneMinDifficulty} // The minimum that the difficulty may ever be. + GenesisDifficulty = []*big.Int{PrimeMinDifficulty, RegionMinDifficulty, ZoneMinDifficulty} // Difficulty of the Genesis block. + DurationLimit = []*big.Int{big.NewInt(1000), big.NewInt(100), big.NewInt(10)} // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. )