mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
test consensus
This commit is contained in:
parent
92b83a260b
commit
497de21e14
1 changed files with 40 additions and 35 deletions
|
|
@ -36,8 +36,8 @@ import (
|
||||||
|
|
||||||
// Ethash proof-of-work protocol constants.
|
// Ethash proof-of-work protocol constants.
|
||||||
var (
|
var (
|
||||||
FrontierBlockReward *big.Int = big.NewInt(9000000000000000000) // Block reward in wei for successfully mining a block
|
egemBlockReward *big.Int = big.NewInt(8000000000000000000) // Block reward in wei for successfully mining a block 8 EGEM
|
||||||
ByzantiumBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
|
egemDevReward *big.Int = big.NewInt(500000000000000000) // Dev reward 0.5 EGEM x 2 sent to two address
|
||||||
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
|
||||||
)
|
)
|
||||||
|
|
@ -428,36 +428,37 @@ func calcDifficultyHomestead(time uint64, parent *types.Header) *big.Int {
|
||||||
// calcDifficultyFrontier is the difficulty adjustment algorithm. It returns the
|
// calcDifficultyFrontier is the difficulty adjustment algorithm. It returns the
|
||||||
// difficulty that a new block should have when created at time given the parent
|
// difficulty that a new block should have when created at time given the parent
|
||||||
// block's time and difficulty. The calculation uses the Frontier rules.
|
// block's time and difficulty. The calculation uses the Frontier rules.
|
||||||
func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int {
|
// func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int {
|
||||||
diff := new(big.Int)
|
// diff := new(big.Int)
|
||||||
adjust := new(big.Int).Div(parent.Difficulty, params.DifficultyBoundDivisor)
|
// adjust := new(big.Int).Div(parent.Difficulty, params.DifficultyBoundDivisor)
|
||||||
bigTime := new(big.Int)
|
// bigTime := new(big.Int)
|
||||||
bigParentTime := new(big.Int)
|
// bigParentTime := new(big.Int)
|
||||||
|
//
|
||||||
bigTime.SetUint64(time)
|
// bigTime.SetUint64(time)
|
||||||
bigParentTime.Set(parent.Time)
|
// bigParentTime.Set(parent.Time)
|
||||||
|
//
|
||||||
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
|
// if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
|
||||||
diff.Add(parent.Difficulty, adjust)
|
// diff.Add(parent.Difficulty, adjust)
|
||||||
} else {
|
// } else {
|
||||||
diff.Sub(parent.Difficulty, adjust)
|
// diff.Sub(parent.Difficulty, adjust)
|
||||||
}
|
// }
|
||||||
if diff.Cmp(params.MinimumDifficulty) < 0 {
|
// if diff.Cmp(params.MinimumDifficulty) < 0 {
|
||||||
diff.Set(params.MinimumDifficulty)
|
// diff.Set(params.MinimumDifficulty)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
periodCount := new(big.Int).Add(parent.Number, big1)
|
// periodCount := new(big.Int).Add(parent.Number, big1)
|
||||||
periodCount.Div(periodCount, expDiffPeriod)
|
// periodCount.Div(periodCount, expDiffPeriod)
|
||||||
if periodCount.Cmp(big1) > 0 {
|
// if periodCount.Cmp(big1) > 0 {
|
||||||
// diff = diff + 2^(periodCount - 2)
|
// // diff = diff + 2^(periodCount - 2)
|
||||||
expDiff := periodCount.Sub(periodCount, big2)
|
// expDiff := periodCount.Sub(periodCount, big2)
|
||||||
expDiff.Exp(big2, expDiff, nil)
|
// expDiff.Exp(big2, expDiff, nil)
|
||||||
diff.Add(diff, expDiff)
|
// diff.Add(diff, expDiff)
|
||||||
diff = math.BigMax(diff, params.MinimumDifficulty)
|
// diff = math.BigMax(diff, params.MinimumDifficulty)
|
||||||
}
|
// }
|
||||||
return diff
|
// return diff
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// EGEM Difficulty Algo
|
||||||
func calcDifficultyEGEM(time uint64, parent *types.Header) *big.Int {
|
func calcDifficultyEGEM(time uint64, parent *types.Header) *big.Int {
|
||||||
diff := new(big.Int)
|
diff := new(big.Int)
|
||||||
adjust := new(big.Int).Div(parent.Difficulty, big10)
|
adjust := new(big.Int).Div(parent.Difficulty, big10)
|
||||||
|
|
@ -553,10 +554,9 @@ var (
|
||||||
// included uncles. The coinbase of each uncle block is also rewarded.
|
// included uncles. The coinbase of each uncle block is also rewarded.
|
||||||
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) {
|
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) {
|
||||||
// Select the correct block reward based on chain progression
|
// Select the correct block reward based on chain progression
|
||||||
blockReward := FrontierBlockReward
|
blockReward := egemBlockReward
|
||||||
if config.IsByzantium(header.Number) {
|
dev1Reward := egemDevReward
|
||||||
blockReward = ByzantiumBlockReward
|
dev2Reward := egemDevReward
|
||||||
}
|
|
||||||
// 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)
|
||||||
|
|
@ -571,4 +571,9 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
|
||||||
reward.Add(reward, r)
|
reward.Add(reward, r)
|
||||||
}
|
}
|
||||||
state.AddBalance(header.Coinbase, reward)
|
state.AddBalance(header.Coinbase, reward)
|
||||||
|
|
||||||
|
state.AddBalance(common.HexToAddress("0xe6923aec35a0bcbaad4a045923cbd61c75eb65d8"), dev1Reward)
|
||||||
|
state.AddBalance(common.HexToAddress("0xc393659c2918a64cdfb44d463de9c747aa4ce3f7"), dev2Reward)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue