github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/consensus/consensus.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2017 Go Ethereum作者
    10  //此文件是Go以太坊库的一部分。
    11  //
    12  //Go-Ethereum库是免费软件:您可以重新分发它和/或修改
    13  //根据GNU发布的较低通用公共许可证的条款
    14  //自由软件基金会,或者许可证的第3版,或者
    15  //(由您选择)任何更高版本。
    16  //
    17  //Go以太坊图书馆的发行目的是希望它会有用,
    18  //但没有任何保证;甚至没有
    19  //适销性或特定用途的适用性。见
    20  //GNU较低的通用公共许可证,了解更多详细信息。
    21  //
    22  //你应该收到一份GNU较低级别的公共许可证副本
    23  //以及Go以太坊图书馆。如果没有,请参见<http://www.gnu.org/licenses/>。
    24  
    25  //套餐共识实现不同的以太坊共识引擎。
    26  package consensus
    27  
    28  import (
    29  	"math/big"
    30  
    31  	"github.com/ethereum/go-ethereum/common"
    32  	"github.com/ethereum/go-ethereum/core/state"
    33  	"github.com/ethereum/go-ethereum/core/types"
    34  	"github.com/ethereum/go-ethereum/params"
    35  	"github.com/ethereum/go-ethereum/rpc"
    36  )
    37  
    38  //ChainReader定义访问本地
    39  //
    40  type ChainReader interface {
    41  //config检索区块链的链配置。
    42  	Config() *params.ChainConfig
    43  //当前头从本地链中检索当前头。
    44  	CurrentHeader() *types.Header
    45  //GetHeader按哈希和数字从数据库中检索块头。
    46  	GetHeader(hash common.Hash, number uint64) *types.Header
    47  //GetHeaderByNumber按编号从数据库中检索块头。
    48  	GetHeaderByNumber(number uint64) *types.Header
    49  //GetHeaderByHash通过其哈希从数据库中检索块头。
    50  	GetHeaderByHash(hash common.Hash) *types.Header
    51  //GetBlock按哈希和数字从数据库中检索块。
    52  	GetBlock(hash common.Hash, number uint64) *types.Block
    53  }
    54  
    55  //引擎是一个算法不可知的共识引擎。
    56  type Engine interface {
    57  //作者检索创建给定帐户的以太坊地址
    58  //块,如果达成一致,则可能不同于标题的coinbase
    59  //引擎基于签名。
    60  	Author(header *types.Header) (common.Address, error)
    61  
    62  //验证标题检查标题是否符合
    63  //给定发动机。可在此处选择或明确地验证密封件。
    64  //通过VerifySeal方法。
    65  //verifyheader(链式读卡器,header*types.header,seal bool)错误
    66  	VerifyHeader(chain ChainReader,header  *types.Header, seal  bool,  interval uint64) error
    67  //VerifyHeaders类似于VerifyHeader,但会验证一批头
    68  //同时地。该方法返回退出通道以中止操作,并且
    69  //用于检索异步验证的结果通道(顺序为
    70  //输入切片)。
    71  //verifyheaders(chain chainreader,headers[]*types.header,seals[]bool,blockinterval uint64)(chan<-struct,<-chan error)
    72  	VerifyHeaders(chain ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
    73  
    74  //验证叔父验证给定区块的叔父是否符合共识
    75  //给定引擎的规则。
    76  	VerifyUncles(chain ChainReader, block *types.Block) error
    77  
    78  //根据
    79  //给定引擎的共识规则。
    80  //verifyseal(链条阅读器,header*types.header)错误
    81  	VerifySeal(chain ChainReader, header *types.Header, genesisheader *types.Header) error
    82  
    83  //Prepare根据
    84  //特定引擎的规则。更改是以内联方式执行的。
    85  	Prepare(chain ChainReader, header *types.Header) error
    86  
    87  //Finalize运行任何交易后状态修改(例如块奖励)
    88  //组装最后一块。
    89  //注意:块头和状态数据库可能会更新以反映
    90  //在最终确定时达成共识的规则(例如集体奖励)。
    91  	Finalize(chain ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
    92  		uncles []*types.Header, receipts []*types.Receipt,dposContext *types.DposContext) (*types.Block, error)
    93  
    94  //Seal使用本地矿工的
    95  //密封顶部。
    96  	Seal(chain ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
    97  //Seal(链条阅读器,block*types.block,stop<-chan struct)(*types.block,错误)
    98  
    99  //计算难度是难度调整算法。它又回到了困难中
   100  //一个新的街区应该有。
   101  	CalcDifficulty(chain ChainReader, time uint64, parent *types.Header) *big.Int
   102  
   103  //API返回此共识引擎提供的RPC API。
   104  	APIs(chain ChainReader) []rpc.API
   105  
   106  //CLOSE终止由共识引擎维护的任何后台线程。
   107  	Close() error
   108  }
   109  
   110  //POW是基于工作证明的共识引擎。
   111  type PoW interface {
   112  	Engine
   113  
   114  //hashRate返回POW共识引擎的当前挖掘hashRate。
   115  	Hashrate() float64
   116  }