commit
41ac8dd803
@ -40,8 +40,22 @@ import (
|
|||||||
var (
|
var (
|
||||||
FrontierBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
|
FrontierBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
|
||||||
ByzantiumBlockReward = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
|
ByzantiumBlockReward = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
|
||||||
|
ConstantinopleBlockReward = big.NewInt(2e+18) // Block reward in wei for successfully mining a block upward from Constantinople
|
||||||
maxUncles = 2 // Maximum number of uncles allowed in a single block
|
maxUncles = 2 // Maximum number of uncles allowed in a single block
|
||||||
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
|
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
|
||||||
|
|
||||||
|
// calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople.
|
||||||
|
// It returns the difficulty that a new block should have when created at time given the
|
||||||
|
// parent block's time and difficulty. The calculation uses the Byzantium rules, but with
|
||||||
|
// bomb offset 5M.
|
||||||
|
// Specification EIP-1234: https://eips.ethereum.org/EIPS/eip-1234
|
||||||
|
calcDifficultyConstantinople = makeDifficultyCalculator(big.NewInt(5000000))
|
||||||
|
|
||||||
|
// calcDifficultyByzantium is the difficulty adjustment algorithm. It returns
|
||||||
|
// the difficulty that a new block should have when created at time given the
|
||||||
|
// parent block's time and difficulty. The calculation uses the Byzantium rules.
|
||||||
|
// Specification EIP-649: https://eips.ethereum.org/EIPS/eip-649
|
||||||
|
calcDifficultyByzantium = makeDifficultyCalculator(big.NewInt(3000000))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Various error messages to mark blocks invalid. These should be private to
|
// Various error messages to mark blocks invalid. These should be private to
|
||||||
@ -299,6 +313,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p
|
|||||||
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
|
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
|
||||||
next := new(big.Int).Add(parent.Number, big1)
|
next := new(big.Int).Add(parent.Number, big1)
|
||||||
switch {
|
switch {
|
||||||
|
case config.IsConstantinople(next):
|
||||||
|
return calcDifficultyConstantinople(time, parent)
|
||||||
case config.IsByzantium(next):
|
case config.IsByzantium(next):
|
||||||
return calcDifficultyByzantium(time, parent)
|
return calcDifficultyByzantium(time, parent)
|
||||||
case config.IsHomestead(next):
|
case config.IsHomestead(next):
|
||||||
@ -316,13 +332,16 @@ var (
|
|||||||
big9 = big.NewInt(9)
|
big9 = big.NewInt(9)
|
||||||
big10 = big.NewInt(10)
|
big10 = big.NewInt(10)
|
||||||
bigMinus99 = big.NewInt(-99)
|
bigMinus99 = big.NewInt(-99)
|
||||||
big2999999 = big.NewInt(2999999)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// calcDifficultyByzantium is the difficulty adjustment algorithm. It returns
|
// makeDifficultyCalculator creates a difficultyCalculator with the given bomb-delay.
|
||||||
// the difficulty that a new block should have when created at time given the
|
// the difficulty is calculated with Byzantium rules, which differs from Homestead in
|
||||||
// parent block's time and difficulty. The calculation uses the Byzantium rules.
|
// how uncles affect the calculation
|
||||||
func calcDifficultyByzantium(time uint64, parent *types.Header) *big.Int {
|
func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *types.Header) *big.Int {
|
||||||
|
// Note, the calculations below looks at the parent number, which is 1 below
|
||||||
|
// the block number. Thus we remove one from the delay given
|
||||||
|
bombDelayFromParent := new(big.Int).Sub(bombDelay, big1)
|
||||||
|
return func(time uint64, parent *types.Header) *big.Int {
|
||||||
// https://github.com/ethereum/EIPs/issues/100.
|
// https://github.com/ethereum/EIPs/issues/100.
|
||||||
// algorithm:
|
// algorithm:
|
||||||
// diff = (parent_diff +
|
// diff = (parent_diff +
|
||||||
@ -357,12 +376,11 @@ func calcDifficultyByzantium(time uint64, parent *types.Header) *big.Int {
|
|||||||
if x.Cmp(params.MinimumDifficulty) < 0 {
|
if x.Cmp(params.MinimumDifficulty) < 0 {
|
||||||
x.Set(params.MinimumDifficulty)
|
x.Set(params.MinimumDifficulty)
|
||||||
}
|
}
|
||||||
// calculate a fake block number for the ice-age delay:
|
// calculate a fake block number for the ice-age delay
|
||||||
// https://github.com/ethereum/EIPs/pull/669
|
// Specification: https://eips.ethereum.org/EIPS/eip-1234
|
||||||
// fake_block_number = max(0, block.number - 3_000_000)
|
|
||||||
fakeBlockNumber := new(big.Int)
|
fakeBlockNumber := new(big.Int)
|
||||||
if parent.Number.Cmp(big2999999) >= 0 {
|
if parent.Number.Cmp(bombDelayFromParent) >= 0 {
|
||||||
fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, big2999999) // Note, parent is 1 less than the actual block number
|
fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, bombDelayFromParent)
|
||||||
}
|
}
|
||||||
// for the exponential factor
|
// for the exponential factor
|
||||||
periodCount := fakeBlockNumber
|
periodCount := fakeBlockNumber
|
||||||
@ -376,6 +394,7 @@ func calcDifficultyByzantium(time uint64, parent *types.Header) *big.Int {
|
|||||||
x.Add(x, y)
|
x.Add(x, y)
|
||||||
}
|
}
|
||||||
return x
|
return x
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// calcDifficultyHomestead is the difficulty adjustment algorithm. It returns
|
// calcDifficultyHomestead is the difficulty adjustment algorithm. It returns
|
||||||
@ -592,6 +611,9 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
|
|||||||
if config.IsByzantium(header.Number) {
|
if config.IsByzantium(header.Number) {
|
||||||
blockReward = ByzantiumBlockReward
|
blockReward = ByzantiumBlockReward
|
||||||
}
|
}
|
||||||
|
if config.IsConstantinople(header.Number) {
|
||||||
|
blockReward = ConstantinopleBlockReward
|
||||||
|
}
|
||||||
// Accumulate the rewards for the miner and any included uncles
|
// Accumulate the rewards for the miner and any included uncles
|
||||||
reward := new(big.Int).Set(blockReward)
|
reward := new(big.Int).Set(blockReward)
|
||||||
r := new(big.Int)
|
r := new(big.Int)
|
||||||
|
Loading…
Reference in New Issue
Block a user