Skip to content

Commit

Permalink
Update DAA for hierarchical control
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Jan 25, 2023
1 parent db0454c commit 9ac0b8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 5 additions & 4 deletions consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand All @@ -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 {
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)

0 comments on commit 9ac0b8c

Please sign in to comment.