|
45 | 45 |
|
46 | 46 | var ( |
47 | 47 | errNoFetchesPending = errors.New("no fetches pending") |
48 | | - errStateSyncPending = errors.New("state trie sync already scheduled") |
49 | 48 | errStaleDelivery = errors.New("stale delivery") |
50 | 49 | ) |
51 | 50 |
|
@@ -74,18 +73,13 @@ type queue struct { |
74 | 73 | mode SyncMode // Synchronisation mode to decide on the block parts to schedule for fetching |
75 | 74 | fastSyncPivot uint64 // Block number where the fast sync pivots into archive synchronisation mode |
76 | 75 |
|
77 | | - hashPool map[common.Hash]int // [eth/61] Pending hashes, mapping to their insertion index (priority) |
78 | | - hashQueue *prque.Prque // [eth/61] Priority queue of the block hashes to fetch |
79 | | - hashCounter int // [eth/61] Counter indexing the added hashes to ensure retrieval order |
80 | | - |
81 | 76 | headerHead common.Hash // [eth/62] Hash of the last queued header to verify order |
82 | 77 |
|
83 | 78 | // Headers are "special", they download in batches, supported by a skeleton chain |
84 | 79 | headerTaskPool map[uint64]*types.Header // [eth/62] Pending header retrieval tasks, mapping starting indexes to skeleton headers |
85 | 80 | headerTaskQueue *prque.Prque // [eth/62] Priority queue of the skeleton indexes to fetch the filling headers for |
86 | 81 | headerPeerMiss map[string]map[uint64]struct{} // [eth/62] Set of per-peer header batches known to be unavailable |
87 | 82 | headerPendPool map[string]*fetchRequest // [eth/62] Currently pending header retrieval operations |
88 | | - headerDonePool map[uint64]struct{} // [eth/62] Set of the completed header fetches |
89 | 83 | headerResults []*types.Header // [eth/62] Result cache accumulating the completed headers |
90 | 84 | headerProced int // [eth/62] Number of headers already processed from the results |
91 | 85 | headerOffset uint64 // [eth/62] Number of the first header in the result cache |
@@ -124,8 +118,6 @@ type queue struct { |
124 | 118 | func newQueue(stateDb ethdb.Database) *queue { |
125 | 119 | lock := new(sync.Mutex) |
126 | 120 | return &queue{ |
127 | | - hashPool: make(map[common.Hash]int), |
128 | | - hashQueue: prque.New(), |
129 | 121 | headerPendPool: make(map[string]*fetchRequest), |
130 | 122 | headerContCh: make(chan bool), |
131 | 123 | blockTaskPool: make(map[common.Hash]*types.Header), |
@@ -158,10 +150,6 @@ func (q *queue) Reset() { |
158 | 150 | q.mode = FullSync |
159 | 151 | q.fastSyncPivot = 0 |
160 | 152 |
|
161 | | - q.hashPool = make(map[common.Hash]int) |
162 | | - q.hashQueue.Reset() |
163 | | - q.hashCounter = 0 |
164 | | - |
165 | 153 | q.headerHead = common.Hash{} |
166 | 154 |
|
167 | 155 | q.headerPendPool = make(map[string]*fetchRequest) |
@@ -208,7 +196,7 @@ func (q *queue) PendingBlocks() int { |
208 | 196 | q.lock.Lock() |
209 | 197 | defer q.lock.Unlock() |
210 | 198 |
|
211 | | - return q.hashQueue.Size() + q.blockTaskQueue.Size() |
| 199 | + return q.blockTaskQueue.Size() |
212 | 200 | } |
213 | 201 |
|
214 | 202 | // PendingReceipts retrieves the number of block receipts pending for retrieval. |
@@ -272,7 +260,7 @@ func (q *queue) Idle() bool { |
272 | 260 | q.lock.Lock() |
273 | 261 | defer q.lock.Unlock() |
274 | 262 |
|
275 | | - queued := q.hashQueue.Size() + q.blockTaskQueue.Size() + q.receiptTaskQueue.Size() + q.stateTaskQueue.Size() |
| 263 | + queued := q.blockTaskQueue.Size() + q.receiptTaskQueue.Size() + q.stateTaskQueue.Size() |
276 | 264 | pending := len(q.blockPendPool) + len(q.receiptPendPool) + len(q.statePendPool) |
277 | 265 | cached := len(q.blockDonePool) + len(q.receiptDonePool) |
278 | 266 |
|
@@ -323,34 +311,6 @@ func (q *queue) ShouldThrottleReceipts() bool { |
323 | 311 | return pending >= len(q.resultCache)-len(q.receiptDonePool) |
324 | 312 | } |
325 | 313 |
|
326 | | -// Schedule61 adds a set of hashes for the download queue for scheduling, returning |
327 | | -// the new hashes encountered. |
328 | | -func (q *queue) Schedule61(hashes []common.Hash, fifo bool) []common.Hash { |
329 | | - q.lock.Lock() |
330 | | - defer q.lock.Unlock() |
331 | | - |
332 | | - // Insert all the hashes prioritised in the arrival order |
333 | | - inserts := make([]common.Hash, 0, len(hashes)) |
334 | | - for _, hash := range hashes { |
335 | | - // Skip anything we already have |
336 | | - if old, ok := q.hashPool[hash]; ok { |
337 | | - glog.V(logger.Warn).Infof("Hash %x already scheduled at index %v", hash, old) |
338 | | - continue |
339 | | - } |
340 | | - // Update the counters and insert the hash |
341 | | - q.hashCounter = q.hashCounter + 1 |
342 | | - inserts = append(inserts, hash) |
343 | | - |
344 | | - q.hashPool[hash] = q.hashCounter |
345 | | - if fifo { |
346 | | - q.hashQueue.Push(hash, -float32(q.hashCounter)) // Lowest gets schedules first |
347 | | - } else { |
348 | | - q.hashQueue.Push(hash, float32(q.hashCounter)) // Highest gets schedules first |
349 | | - } |
350 | | - } |
351 | | - return inserts |
352 | | -} |
353 | | - |
354 | 314 | // ScheduleSkeleton adds a batch of header retrieval tasks to the queue to fill |
355 | 315 | // up an already retrieved header skeleton. |
356 | 316 | func (q *queue) ScheduleSkeleton(from uint64, skeleton []*types.Header) { |
@@ -550,15 +510,6 @@ func (q *queue) ReserveHeaders(p *peer, count int) *fetchRequest { |
550 | 510 | return request |
551 | 511 | } |
552 | 512 |
|
553 | | -// ReserveBlocks reserves a set of block hashes for the given peer, skipping any |
554 | | -// previously failed download. |
555 | | -func (q *queue) ReserveBlocks(p *peer, count int) *fetchRequest { |
556 | | - q.lock.Lock() |
557 | | - defer q.lock.Unlock() |
558 | | - |
559 | | - return q.reserveHashes(p, count, q.hashQueue, nil, q.blockPendPool, len(q.resultCache)-len(q.blockDonePool)) |
560 | | -} |
561 | | - |
562 | 513 | // ReserveNodeData reserves a set of node data hashes for the given peer, skipping |
563 | 514 | // any previously failed download. |
564 | 515 | func (q *queue) ReserveNodeData(p *peer, count int) *fetchRequest { |
@@ -753,11 +704,6 @@ func (q *queue) CancelHeaders(request *fetchRequest) { |
753 | 704 | q.cancel(request, q.headerTaskQueue, q.headerPendPool) |
754 | 705 | } |
755 | 706 |
|
756 | | -// CancelBlocks aborts a fetch request, returning all pending hashes to the queue. |
757 | | -func (q *queue) CancelBlocks(request *fetchRequest) { |
758 | | - q.cancel(request, q.hashQueue, q.blockPendPool) |
759 | | -} |
760 | | - |
761 | 707 | // CancelBodies aborts a body fetch request, returning all pending headers to the |
762 | 708 | // task queue. |
763 | 709 | func (q *queue) CancelBodies(request *fetchRequest) { |
@@ -801,9 +747,6 @@ func (q *queue) Revoke(peerId string) { |
801 | 747 | defer q.lock.Unlock() |
802 | 748 |
|
803 | 749 | if request, ok := q.blockPendPool[peerId]; ok { |
804 | | - for hash, index := range request.Hashes { |
805 | | - q.hashQueue.Push(hash, float32(index)) |
806 | | - } |
807 | 750 | for _, header := range request.Headers { |
808 | 751 | q.blockTaskQueue.Push(header, -float32(header.Number.Uint64())) |
809 | 752 | } |
@@ -832,15 +775,6 @@ func (q *queue) ExpireHeaders(timeout time.Duration) map[string]int { |
832 | 775 | return q.expire(timeout, q.headerPendPool, q.headerTaskQueue, headerTimeoutMeter) |
833 | 776 | } |
834 | 777 |
|
835 | | -// ExpireBlocks checks for in flight requests that exceeded a timeout allowance, |
836 | | -// canceling them and returning the responsible peers for penalisation. |
837 | | -func (q *queue) ExpireBlocks(timeout time.Duration) map[string]int { |
838 | | - q.lock.Lock() |
839 | | - defer q.lock.Unlock() |
840 | | - |
841 | | - return q.expire(timeout, q.blockPendPool, q.hashQueue, blockTimeoutMeter) |
842 | | -} |
843 | | - |
844 | 778 | // ExpireBodies checks for in flight block body requests that exceeded a timeout |
845 | 779 | // allowance, canceling them and returning the responsible peers for penalisation. |
846 | 780 | func (q *queue) ExpireBodies(timeout time.Duration) map[string]int { |
@@ -907,74 +841,6 @@ func (q *queue) expire(timeout time.Duration, pendPool map[string]*fetchRequest, |
907 | 841 | return expiries |
908 | 842 | } |
909 | 843 |
|
910 | | -// DeliverBlocks injects a block retrieval response into the download queue. The |
911 | | -// method returns the number of blocks accepted from the delivery and also wakes |
912 | | -// any threads waiting for data delivery. |
913 | | -func (q *queue) DeliverBlocks(id string, blocks []*types.Block) (int, error) { |
914 | | - q.lock.Lock() |
915 | | - defer q.lock.Unlock() |
916 | | - |
917 | | - // Short circuit if the blocks were never requested |
918 | | - request := q.blockPendPool[id] |
919 | | - if request == nil { |
920 | | - return 0, errNoFetchesPending |
921 | | - } |
922 | | - blockReqTimer.UpdateSince(request.Time) |
923 | | - delete(q.blockPendPool, id) |
924 | | - |
925 | | - // If no blocks were retrieved, mark them as unavailable for the origin peer |
926 | | - if len(blocks) == 0 { |
927 | | - for hash, _ := range request.Hashes { |
928 | | - request.Peer.MarkLacking(hash) |
929 | | - } |
930 | | - } |
931 | | - // Iterate over the downloaded blocks and add each of them |
932 | | - accepted, errs := 0, make([]error, 0) |
933 | | - for _, block := range blocks { |
934 | | - // Skip any blocks that were not requested |
935 | | - hash := block.Hash() |
936 | | - if _, ok := request.Hashes[hash]; !ok { |
937 | | - errs = append(errs, fmt.Errorf("non-requested block %x", hash)) |
938 | | - continue |
939 | | - } |
940 | | - // Reconstruct the next result if contents match up |
941 | | - index := int(block.Number().Int64() - int64(q.resultOffset)) |
942 | | - if index >= len(q.resultCache) || index < 0 { |
943 | | - errs = []error{errInvalidChain} |
944 | | - break |
945 | | - } |
946 | | - q.resultCache[index] = &fetchResult{ |
947 | | - Header: block.Header(), |
948 | | - Transactions: block.Transactions(), |
949 | | - Uncles: block.Uncles(), |
950 | | - } |
951 | | - q.blockDonePool[block.Hash()] = struct{}{} |
952 | | - |
953 | | - delete(request.Hashes, hash) |
954 | | - delete(q.hashPool, hash) |
955 | | - accepted++ |
956 | | - } |
957 | | - // Return all failed or missing fetches to the queue |
958 | | - for hash, index := range request.Hashes { |
959 | | - q.hashQueue.Push(hash, float32(index)) |
960 | | - } |
961 | | - // Wake up WaitResults |
962 | | - if accepted > 0 { |
963 | | - q.active.Signal() |
964 | | - } |
965 | | - // If none of the blocks were good, it's a stale delivery |
966 | | - switch { |
967 | | - case len(errs) == 0: |
968 | | - return accepted, nil |
969 | | - case len(errs) == 1 && (errs[0] == errInvalidChain || errs[0] == errInvalidBlock): |
970 | | - return accepted, errs[0] |
971 | | - case len(errs) == len(blocks): |
972 | | - return accepted, errStaleDelivery |
973 | | - default: |
974 | | - return accepted, fmt.Errorf("multiple failures: %v", errs) |
975 | | - } |
976 | | -} |
977 | | - |
978 | 844 | // DeliverHeaders injects a header retrieval response into the header results |
979 | 845 | // cache. This method either accepts all headers it received, or none of them |
980 | 846 | // if they do not map correctly to the skeleton. |
|
0 commit comments