MCPcopy Create free account
hub / github.com/CPChain/chain / insertBlocks

Method insertBlocks

protocols/cpc/syncer/syncer.go:642–664  ·  view source on GitHub ↗

insertBlocks return true if insert successful

(p SyncPeer, cnt *int32, blocks types.Blocks,
	receipts []types.Receipts, headers []*types.Header, bodies [][]*types.Transaction)

Source from the content-addressed store, hash-verified

640
641// insertBlocks return true if insert successful
642func (s *Synchronizer) insertBlocks(p SyncPeer, cnt *int32, blocks types.Blocks,
643 receipts []types.Receipts, headers []*types.Header, bodies [][]*types.Transaction) (bool, int, error) {
644 // handle received blocks
645 log.Debug("prepare", "cnt", atomic.LoadInt32(cnt))
646 if atomic.LoadInt32(cnt) < 2 {
647 atomic.AddInt32(cnt, 1)
648 return false, 0, nil
649 }
650 minCnt := math.Min(float64(len(headers)), float64(len(bodies)))
651 minCnt = math.Min(minCnt, float64(len(receipts)))
652 receipts = receipts[:int(minCnt)]
653 headers = headers[:int(minCnt)]
654 bodies = bodies[:int(minCnt)]
655
656 err := s.blocksQueue.put(resultTask{
657 blocksWithReceipts{headers, bodies, receipts},
658 })
659 if err != nil {
660 log.Warn("blocks queue put err", "err", err)
661 return false, 0, err
662 }
663 return true, int(minCnt), nil
664}
665
666func (s *Synchronizer) sendRequestLoop() {
667 for {

Callers 1

synchroniseMethod · 0.95

Calls 3

DebugMethod · 0.80
WarnMethod · 0.65
putMethod · 0.45

Tested by

no test coverage detected