diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-24 17:26:06 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-08-24 22:16:39 +0800 |
commit | b872961ec82ec88a7ac6ef331cfb3eb685ce2c00 (patch) | |
tree | 652d5bc27e4f95809637e6f76f6db3162b2e435e /consensus/ethash | |
parent | 3c48a25762dfab9382791c33a2f5832466077ac3 (diff) | |
download | go-tangerine-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar go-tangerine-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar.gz go-tangerine-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar.bz2 go-tangerine-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar.lz go-tangerine-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar.xz go-tangerine-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar.zst go-tangerine-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.zip |
consensus, core, tests: implement Metropolis EIP 649
Diffstat (limited to 'consensus/ethash')
-rw-r--r-- | consensus/ethash/consensus.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 01d97a470..b71420445 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -36,8 +36,9 @@ import ( // Ethash proof-of-work protocol constants. var ( - blockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block - maxUncles = 2 // Maximum number of uncles allowed in a single block + frontierBlockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block + metropolisBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Metropolis + maxUncles = 2 // Maximum number of uncles allowed in a single block ) // Various error messages to mark blocks invalid. These should be private to @@ -306,6 +307,7 @@ var ( big9 = big.NewInt(9) big10 = big.NewInt(10) bigMinus99 = big.NewInt(-99) + big2999999 = big.NewInt(2999999) ) // calcDifficultyMetropolis is the difficulty adjustment algorithm. It returns @@ -346,8 +348,15 @@ func calcDifficultyMetropolis(time uint64, parent *types.Header) *big.Int { if x.Cmp(params.MinimumDifficulty) < 0 { x.Set(params.MinimumDifficulty) } + // calculate a fake block numer for the ice-age delay: + // https://github.com/ethereum/EIPs/pull/669 + // fake_block_number = min(0, block.number - 3_000_000 + fakeBlockNumber := new(big.Int) + if parent.Number.Cmp(big2999999) >= 0 { + fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, big2999999) // Note, parent is 1 less than the actual block number + } // for the exponential factor - periodCount := new(big.Int).Add(parent.Number, big1) + periodCount := fakeBlockNumber periodCount.Div(periodCount, expDiffPeriod) // the exponential factor, commonly referred to as "the bomb" @@ -501,7 +510,7 @@ func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header) // setting the final state and assembling the block. func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { // Accumulate any block and uncle rewards and commit the final state root - AccumulateRewards(state, header, uncles) + AccumulateRewards(chain.Config(), state, header, uncles) header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number)) // Header seems complete, assemble into a block and return @@ -518,7 +527,13 @@ var ( // reward. The total reward consists of the static block reward and rewards for // included uncles. The coinbase of each uncle block is also rewarded. // TODO (karalabe): Move the chain maker into this package and make this private! -func AccumulateRewards(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 + blockReward := frontierBlockReward + if config.IsMetropolis(header.Number) { + blockReward = metropolisBlockReward + } + // Accumulate the rewards for the miner and any included uncles reward := new(big.Int).Set(blockReward) r := new(big.Int) for _, uncle := range uncles { |