欢迎来到天天文库
浏览记录
ID:27452634
大小:32.25 KB
页数:16页
时间:2018-12-03
《兄弟连Go语言+区块链技术培训以太坊源码分析(35)eth-fetcher源码分析.docx》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、兄弟连Go语言+区块链技术培训以太坊源码分析(35)eth-fetcher源码分析fetcher包含基于块通知的同步。当我们接收到NewBlockHashesMsg消息得时候,我们只收到了很多Block的hash值。需要通过hash值来同步区块,然后更新本地区块链。fetcher就提供了这样的功能。数据结构 //announceisthehashnotificationoftheavailabilityofanewblockinthe //network. //announce是一个hash通知,表示网络上有合适的新区块出现。 typeannouncestruct{
2、 hashcommon.Hash//Hashoftheblockbeingannounced//新区块的hash值 numberuint64//Numberoftheblockbeingannounced(0=unknown
3、oldprotocol)区块的高度值, header*types.Header//Headeroftheblockpartiallyreassembled(newprotocol) 重新组装的区块头 timetime.Time//Timestampoftheannouncement ori
4、ginstring//Identifierofthepeeroriginatingthenotification fetchHeaderheaderRequesterFn//Fetcherfunctiontoretrievetheheaderofanannouncedblock获取区块头的函数指针,里面包含了peer的信息。就是说找谁要这个区块头 fetchBodiesbodyRequesterFn//Fetcherfunctiontoretrievethebodyofanannouncedblock获取区块体的函数指针 } //hea
5、derFilterTaskrepresentsabatchofheadersneedingfetcherfiltering. typeheaderFilterTaskstruct{ peerstring//Thesourcepeerofblockheaders headers[]*types.Header//Collectionofheaderstofilter timetime.Time//Arrivaltimeoftheheaders } //headerFilterTaskrepresentsabatchofblock
6、bodies(transactionsanduncles) //needingfetcherfiltering. typebodyFilterTaskstruct{ peerstring//Thesourcepeerofblockbodies transactions[][]*types.Transaction//Collectionoftransactionsperblockbodies uncles[][]*types.Header//Collectionofunclesperblockbodies timetime.T
7、ime//Arrivaltimeoftheblocks'contents } //injectrepresentsaschedulesimportoperation. //当节点收到NewBlockMsg的消息时候,会插入一个区块 typeinjectstruct{ originstring block*types.Block } //Fetcherisresponsibleforaccumulatingblockannouncementsfromvariouspeers //andschedulingth
8、emforretrieval. typeFetcherstruct{ //Variouseventchannels notifychan*announce //announce的通道, injectchan*inject //inject的通道 blockFilterchanchan[]*types.Block //通道的通
此文档下载收益归作者所有