enqueue schedules a new future import operation, if the block to be imported has not yet been seen.
(peer string, block *types.Block)
| 606 | // enqueue schedules a new future import operation, if the block to be imported |
| 607 | // has not yet been seen. |
| 608 | func (f *Fetcher) enqueue(peer string, block *types.Block) { |
| 609 | hash := block.Hash() |
| 610 | |
| 611 | // Ensure the peer isn't DOSing us |
| 612 | count := f.queues[peer] + 1 |
| 613 | if count > blockLimit { |
| 614 | log.Debug("Discarded propagated block, exceeded allowance", "peer", peer, "number", block.Number(), "hash", hash.Hex(), "limit", blockLimit) |
| 615 | propBroadcastDOSMeter.Mark(1) |
| 616 | f.forgetHash(hash) |
| 617 | return |
| 618 | } |
| 619 | // Discard any past or too distant blocks |
| 620 | if dist := int64(block.NumberU64()) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist { |
| 621 | log.Debug("Discarded propagated block, too far away", "peer", peer, "number", block.Number(), "hash", hash.Hex(), "distance", dist) |
| 622 | propBroadcastDropMeter.Mark(1) |
| 623 | f.forgetHash(hash) |
| 624 | return |
| 625 | } |
| 626 | // Schedule the block for future importing |
| 627 | if _, ok := f.queued[hash]; !ok { |
| 628 | op := &inject{ |
| 629 | origin: peer, |
| 630 | block: block, |
| 631 | } |
| 632 | f.queues[peer] = count |
| 633 | f.queued[hash] = op |
| 634 | f.queue.Push(op, -float32(block.NumberU64())) |
| 635 | if f.queueChangeHook != nil { |
| 636 | f.queueChangeHook(op.block.Hash(), true) |
| 637 | } |
| 638 | log.Debug("Queued propagated block", "peer", peer, "number", block.Number(), "hash", hash.Hex(), "queued", f.queue.Size()) |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | // insert spawns a new goroutine to run a block insertion into the chain. If the |
| 643 | // block's number is at the same height as the current import phase, it updates |
no test coverage detected