以太坊学习备忘录-挖矿

计算下一个区块的GasLimit

core/block_validator.go CalcGasLimit1559

上一个区块gasLimit - (上一个区块gasLimit / 1024 - 1)

但是不能低于设置的最低区块gasLimit

ETH的EIP-1559协议

挖矿关于区块燃料参数

eth/ethconfig/config.go 81

    Miner: miner.Config{
        GasFloor: 8000000,
        GasCeil:  8000000,
        GasPrice: big.NewInt(params.GWei),
        Recommit: 3 * time.Second,
    },
  • GasFloor: 区块燃料上限
  • GasCeil: 区块燃料下限

对应geth启动配置

  --miner.gastarget value             Target gas floor for mined blocks (default: 8000000)
  --miner.gaslimit value              Target gas ceiling for mined blocks (default: 8000000)

挖矿基本结构

挖矿数据结构以及方法

miner

挖矿工作线程

work

  • newWorkLoop 初始化挖矿
  • mainLoop 挖矿循环
  • resultLoop 成功出块之后做的一些处理
  • taskLoop 则是提交新的挖矿任务
func (miner *Miner) update() { }

同步完成,设置挖矿奖励账户开始挖矿

共识代码

有两份共识代码

  • consensus/clique 是POA共识,在dev模式下面会启用
  • consensus/ethash 是POW共识

重启数据丢失的问题

原因:退出geth时采用了不合适的方式使得数据没有保存

相关关键日志如下:

WARN [07-01|15:19:48.106|core/blockchain.go:293]                 Head state missing, repairing            number=20 hash=169d6f..511207 snaproot=ea4b1b..a1a795
TRACE[07-01|15:19:48.106|core/blockchain.go:524]                 Block state missing, rewinding further   number=20 hash=169d6f..511207
TRACE[07-01|15:19:48.106|core/blockchain.go:524]                 Block state missing, rewinding further   number=19 hash=051e88..82ba4c
TRACE[07-01|15:19:48.106|core/blockchain.go:524]                 Block state missing, rewinding further   number=18 hash=993ae7..9cbf54

解决:以合适的方式关闭geth控制台:ctrl+c(console模式使用 ctrl+d)或者输入exit命令。如果在挖矿,建议先停掉挖矿再退出。

geth-rewinds-chain-on-every-startup

难度调整

https://github.com/ethereum/EIPs/issues/100
algorithm:
diff = (parent_diff + (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99))) + 2^(periodCount - 2)

每13秒增加一个区块。每增加10w个区块大约需要 100000 / (24 * 3600 / 13) == 15天

难度炸弹由2^(blockNumber / 100000 - 2) --> 2^(max(blockNumber - 9700000, 0) / 100000 - 2)

目前区块高度 12726276: 当前区块难度 6,454,327,311,954,481,目前难度炸弹大约为 2^((12726276 - 9700000) / 100000 - 2) == 2^28 == 268,435,456

要显著起作用 2 ^ 50 == 1,125,899,906,842,624,

难度炸弹显著生效区块高度 ( (50 + 2) * 100000 + 9700000 ) == 14900000

需要时间 (14900000 - 12726276) * 13 / 3600 / 24 == 327 天

暂无评论

发送评论 编辑评论


				
上一篇
下一篇