eth以太坊挖矿奖励计算公式

普通区块奖励

固定奖励 + 交易手续费 + 引用叔块奖励

  • 固定奖励: 根据blocknum的分区,给与不同的奖励
  • 交易手续费: 每个区块上的每笔交易中 gasUse*gasPrice的累加
  • 引用叔块奖励:叔块个数 * (固定奖励* 1/32)

交易手续费:

  • gasUse 来源 transactionReceipt
  • gasPrice 来源 transactiongasUse * gasPrice

叔块奖励计算

叔块奖励:单个叔块奖励的累加

单个叔块的奖励:(叔块高度 + 8 - 包含叔块的区块的高度) * 固定奖励 / 8

源码分析

位于 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
if config.IsByzantium(header.Number) {
blockReward = ByzantiumBlockReward
}
if config.IsConstantinople(header.Number) {
blockReward = ConstantinopleBlockReward
}
// Accumulate the rewards for the miner and any included uncles
reward := new(big.Int).Set(blockReward)
r := new(big.Int)
for _, uncle := range uncles {
// 叔块给挖出矿工的奖励是主块奖励的 n/8,其中n=1-7
r.Add(uncle.Number, big8)
r.Sub(r, header.Number)
r.Mul(r, blockReward)
r.Div(r, big8)
state.AddBalance(uncle.Coinbase, r)

// 叔块给打包矿工的奖励是主块奖励的 n/32
r.Div(blockReward, big32)
reward.Add(reward, r)
}
state.AddBalance(header.Coinbase, reward)
}

EIP-1559 引入了基础费(Basefee),升级后的以太坊手续费就分成两个部分:基础费和矿工小费。基础费用是交易所需的最少花费,由系统直接销毁,小费就是矿工所得的矿工费。以太坊区块中销毁的 ETH 就是这个区块 ...