获取区块奖励过程
来源:互联网 发布:mysql建索引优化 编辑:程序博客网 时间:2024/05/22 02:07
区块奖励入口代码:go-ethereum\core\chain_makers.go line:182
其中config:
config *params.ChainConfig //链配置
statedb = state.New(parent.Root(), state.NewDatabase(db))//状态DB建立
header为该块头,可以根据配置、父块组合出来 header := makeHeader(config, parent, statedb),实际使用时,只用到header.Number和header.coinBase
parent为*types.Block实例,父块
db即ethdb.Database实例
uncles:叔节点,实际使用时,只用到header.Number和header.coinBase
makeHeader函数:
func makeHeader(config *params.ChainConfig, parent *types.Block, state *state.StateDB) *types.Header {
var time *big.Int
if parent.Time() == nil {
time = big.NewInt(10)
} else {
time = new(big.Int).Add(parent.Time(), big.NewInt(10)) // block time is fixed at 10 seconds
}
return &types.Header{
Root: state.IntermediateRoot(config.IsEIP158(parent.Number())),
ParentHash: parent.Hash(),
Coinbase: parent.Coinbase(),
Difficulty: ethash.CalcDifficulty(config, time.Uint64(), &types.Header{
Number: parent.Number(),
Time: new(big.Int).Sub(time, big.NewInt(10)),
Difficulty: parent.Difficulty(),
UncleHash: parent.UncleHash(),
}),
GasLimit: CalcGasLimit(parent),
GasUsed: new(big.Int),
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: time,
}
}
计算奖励:
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
}
// 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.Div(blockReward, big32)
reward.Add(reward, r)
}
//reward为最终奖励额度
state.AddBalance(header.Coinbase, reward)
}
阅读全文
0 0
- 获取区块奖励过程
- 奖励
- 奖励
- 每日区块链:美国运通将区块链用于消费者奖励系统
- 过程改进建设中的常见奖励措施
- 项目实施过程中是要奖励功劳还是苦劳?
- 项目实施过程中是要奖励功劳还是苦劳?
- 乔布斯自传(笔记)——过程就是奖励
- phpcms v9 邀请用户注册自动获取积分奖励
- 51nod 1163 最高奖励 已AC 刷题过程记录
- 奖励自己
- 奖励有害
- 领取奖励
- 自我奖励
- 区块链介绍(一) 矿工挖矿过程
- 浅谈区块链开发数字货币过程中环境变量问题
- 前端好用工具推荐-获取页面区块坐标
- jquery里面获取div区块的宽度与高度
- a标签阻止默认行为的几种简单方法
- pycharm无法输出中文&cookielib is not define
- GalaxyOJ-853 (dp)
- java中的泛型
- 在阿里搭建FTP服务的坑
- 获取区块奖励过程
- MPChartAndroid轴线标签自定义的一些显示BUG
- 以太网端口聚合
- PHP 中正确统计中文字数
- 第五周——项目二—建立链栈算法库
- MYSQL的三大范式
- 9.23 看电影 2743
- java基础的入门
- Django 2.0 roadmap