1.矿工区块奖励计算方法
打包者:blockReward + blockReward/32 * uncles.length
Uncle: ((uncle.Number + 8) - header.Number) * blockReward /8
go-ethereum/consensus/ethash/consensus.go
// AccumulateRewards credits the coinbase of the given block with the mining
// reward. The total reward consists of the static block reward and rewards for
// 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) {
// Select the correct block reward based on chain progression
blockReward := FrontierBlockReward //5ETH
if config.IsByzantium(header.Number) { //区块高度 > 4370000
blockReward = ByzantiumBlockReward //3ETH
}
// Accumulate the rewards for the miner and any included uncles
reward := new(big.Int).Set(blockReward)
r := new(big.Int)
for _, uncle := range uncles {
r.Add(uncle.Number, big8)
r.Sub(r, header.Number)
r.Mul(r, blockReward)
r.Div(r, big8)
state.AddBalance(uncle.Coinbase, r) //r = ((uncle.Number + 8) - header.Number) * blockReward /8
r.Div(blockReward, big32) //r = blockReward/32
reward.Add(reward, r) //每多一个uncle,打包者会在blockReward的基础上多一个blockReward/32
}
state.AddBalance(header.Coinbase, reward) //给挖矿者增加reward
}
2. 区块举例
2.1.https://etherscan.io/block/6365764
挖矿者奖励
Block Reward:3.158814429281857873 Ether (3 + 0.065064429281857873 + 0.09375)
| 值 | 计算方式 |
|----------|-------------|
| 3 | ByzantiumBlockReward |
| 0.09375 | blockReward/32 = 3/32 |
| 0.065064429281857873 | 交易费 |Uncle奖励
https://etherscan.io/uncle/0xb07c2f04deb0c3f8d7b345854a4bd98e5b7f45854c4e1dfade8f81ef3574b8d0
Uncles Reward: 2.25 Ether (1 Uncle at Position 0)
| 值 | 计算方式 |
|----------|-------------|
| 2.25 | ((uncle.Number + 8) - header.Number) * blockReward /8 = ((6365762 + 8) - 6365764) * 3 /8 |