insertBlocks return true if insert successful
(p SyncPeer, cnt *int32, blocks types.Blocks, receipts []types.Receipts, headers []*types.Header, bodies [][]*types.Transaction)
| 640 | |
| 641 | // insertBlocks return true if insert successful |
| 642 | func (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 | |
| 666 | func (s *Synchronizer) sendRequestLoop() { |
| 667 | for { |
no test coverage detected