MCPcopy Create free account
hub / github.com/DNAProject/DNA / requestBlockInfo

Method requestBlockInfo

consensus/vbft/node_sync.go:467–497  ·  view source on GitHub ↗
(startBlkNum uint32)

Source from the content-addressed store, hash-verified

465}
466
467func (self *PeerSyncer) requestBlockInfo(startBlkNum uint32) ([]*BlockInfo_, error) {
468 msg := self.server.constructBlockInfoFetchMsg(startBlkNum)
469 self.server.msgSendC <- &SendMsgEvent{
470 ToPeer: self.peerIdx,
471 Msg: msg,
472 }
473
474 t := time.NewTimer(makeProposalTimeout * 2)
475 defer t.Stop()
476
477 select {
478 case msg := <-self.msgC:
479 if msg == nil {
480 return nil, fmt.Errorf("nil blockinfo fetch rsp msg received")
481 }
482 switch msg.Type() {
483 case BlockInfoFetchRespMessage:
484 pMsg, ok := msg.(*BlockInfoFetchRespMsg)
485 if !ok {
486 // log error
487 }
488 return pMsg.Blocks, nil
489 }
490 case <-t.C:
491 return nil, fmt.Errorf("timeout fetch blockInfo %d from peer %d", startBlkNum, self.peerIdx)
492 case <-self.server.quitC:
493 return nil, fmt.Errorf("peer syncer %d - %d quit, failed fetching BlockInfo %d",
494 self.server.Index, self.peerIdx, startBlkNum)
495 }
496 return nil, nil
497}
498
499func (self *PeerSyncer) fetchedBlock(blkNum uint32, block *Block) error {
500 self.lock.Lock()

Callers 1

runMethod · 0.95

Calls 4

ErrorfMethod · 0.80
StopMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected