Documentation
¶
Overview ¶
Package fetcher contains the block announcement based synchronisation.
Index ¶
- type Fetcher
- func (f *Fetcher) Enqueue(peer string, block *types.Block) error
- func (f *Fetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, ...) ([][]*types.Transaction, [][]*types.Header)
- func (f *Fetcher) FilterHeaders(peer string, headers []*types.Header, time time.Time) []*types.Header
- func (f *Fetcher) Notify(peer string, hash common.Hash, number uint64, time time.Time, ...) error
- func (f *Fetcher) Start()
- func (f *Fetcher) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
fetcher 模块和 downloader 模块所承担的任务是不同的. downloader 功能比较重,用来保证自己的 chain 和其它节点之间不会有太多差距 fetcher 功能较轻,只会对 miner 新产生的 block 进行同步和广播
Fetcher is responsible for accumulating block announcements from various peers and scheduling them for retrieval.
Fetcher负责 累积来自 各个 对端 peer 的 block公告,并安排它们以进行处理.
Fetcher 模块的功能:
就是收集其他Peer通知它的区块信息: 1)完整的 block 2)区块Hash消息 根据通知的消息,获取完整的区块,然后传递给eth模块把区块插入区块链.
todo 即 Fecther 是专门处理 对端 peer 的 (pm *ProtocolManager) minedBroadcastLoop() 方法中 广播过来的完整 block 或者 blockHash
如果是完整 block,就可以传递给eth插入区块 如果只有 blockHash,则需要从其他的Peer获取此完整的区块,然后再传递给eth插入区块
func New ¶
func New(getBlock blockRetrievalFn, verifyHeader headerVerifierFn, broadcastBlock blockBroadcasterFn, chainHeight chainHeightFn, insertChain chainInsertFn, dropPeer peerDropFn) *Fetcher
New creates a block fetcher to retrieve blocks based on hash announcements.
只有一个地方调用:
eth\handler.go 的 NewProtocolManager() <可以知道 fecther 只针对 全节点的 full 和 fast 模式>
func (*Fetcher) Enqueue ¶
Enqueue tries to fill gaps the the fetcher's future import queue.
用来对 对端peer 发来的 block 做本地chain插入准备
在 ProtocolManager.handleMsg() 的 `case msg.Code == NewBlockMsg` 中被调用
func (*Fetcher) FilterBodies ¶
func (f *Fetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, time time.Time) ([][]*types.Transaction, [][]*types.Header)
FilterBodies extracts all the block bodies that were explicitly requested by the fetcher, returning those that should be handled differently.
和 FilterHeaders() 类似的处理方式
func (*Fetcher) FilterHeaders ¶
func (f *Fetcher) FilterHeaders(peer string, headers []*types.Header, time time.Time) []*types.Header
FilterHeaders extracts all the headers that were explicitly requested by the fetcher, returning those that should be handled differently.
用来对接收到 对端peer 发来的blockHeader 做处理
在 ProtocolManager.handleMsg() 的 `case msg.Code == BlockHeadersMsg` 中被调用
func (*Fetcher) Notify ¶
func (f *Fetcher) Notify(peer string, hash common.Hash, number uint64, time time.Time, headerFetcher headerRequesterFn, bodyFetcher bodyRequesterFn) error
Notify announces the fetcher of the potential availability of a new block in the network.
根据 blockHash 发起 (往对端 peer 抓取目标 block 的通知信息)
在 ProtocolManager.handleMsg() 的 `case msg.Code == NewBlockMsg` 中被调用