14 篇文章 1 订阅

# 以太坊的区块奖励机制

## 以太坊的区块奖励

blockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block   5ether


ByzantiumBlockReward   *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium


## 叔伯块（uncle）及叔伯块奖励分发机制

maxUncles            = 2                 // Maximum number of uncles allowed in a single block


/consensus/ethash/consensus.go
func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
//...
// Gather the set of past uncles and ancestors
number, parent := block.NumberU64()-1, block.ParentHash()
//从当前区块回溯7层（或7代）,搜集祖先（主链上的块）和叔伯块
for i := 0; i < 7; i++ {
ancestor := chain.GetBlock(parent, number)
if ancestor == nil {
break
}
for _, uncle := range ancestor.Uncles() {
}
parent, number = ancestor.ParentHash(), number-1
}
// Verify each of the uncles that it's recent, but not an ancestor  验证叔伯块不是祖先（即不能是主链的块）
for _, uncle := range block.Uncles() {
// Make sure every uncle is rewarded only once  每一个叔伯块只能被奖励一次，否则就“多重奖励”了
hash := uncle.Hash()
if uncles.Has(hash) {
return errDuplicateUncle
}

// Make sure the uncle has a valid ancestry 该叔伯块为祖先区块，即为主链上的块
if ancestors[hash] != nil {
return errUncleIsAncestor
}
//叔伯块的祖先不在7层祖先之中 或者 叔伯块和当前区块在同一区块高度
if ancestors[uncle.ParentHash] == nil || uncle.ParentHash == block.ParentHash() {
return errDanglingUncle
}
//验证叔伯块头部的有效性
if err := ethash.verifyHeader(chain, uncle, ancestors[uncle.ParentHash], true, true); err != nil {
return err
}
//...
}


## 计算累计收益的函数

func AccumulateRewards(state *state.StateDB, header *types.Header, uncles []*types.Header) {
reward := new(big.Int).Set(blockReward)     //侄子区块拿到的恒定区块奖励
r := new(big.Int)
for _, uncle := range uncles {
r.Mul(r, blockReward)
r.Div(r, big8)

r.Div(blockReward, big32)
}
}


ps：拜占庭硬分叉后一个叔伯块奖励为1/32*3。Block #5931460中Block Reward中的0.09375便是1/32*3的结果。

• 1
点赞
• 1
收藏
• 打赏
• 0
评论
12-18
06-06 6029
09-27 1641
07-20 4561
06-03 925
03-24 4099
10-15 2164
08-08 7316
04-21 3395
08-16 3180
07-31 1万+
02-26 6938
05-01 2039
06-18 2416
05-09 487
02-05 1634
08-07 1761

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

Non_咕咚

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。