mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/downloader: fix index error
This commit is contained in:
parent
08e6e27c8f
commit
cd6f573575
1 changed files with 24 additions and 28 deletions
|
|
@ -833,13 +833,8 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header, taskQ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Assemble each of the results with their headers and retrieved data parts
|
// Assemble each of the results with their headers and retrieved data parts
|
||||||
type acceptedItem struct {
|
|
||||||
hash common.Hash
|
|
||||||
index int
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
failure error
|
failure error
|
||||||
acceptedItems []acceptedItem
|
|
||||||
i int
|
i int
|
||||||
)
|
)
|
||||||
// Need the read lock to access resultcache
|
// Need the read lock to access resultcache
|
||||||
|
|
@ -849,38 +844,40 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header, taskQ
|
||||||
if i >= results {
|
if i >= results {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Reconstruct the next result if contents match up
|
// Validate the fields
|
||||||
index := int(header.Number.Int64() - int64(q.resultOffset))
|
if err := validate(i, header.TxHash, header.UncleHash, header.ReceiptHash); err != nil {
|
||||||
if index >= len(q.resultCache) || index < 0 || q.resultCache[index] == nil {
|
|
||||||
failure = errInvalidChain
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err := validate(index, header.TxHash, header.UncleHash, header.ReceiptHash); err != nil {
|
|
||||||
failure = err
|
failure = err
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
hash := header.Hash()
|
header.Hash()
|
||||||
acceptedItems = append(acceptedItems, acceptedItem{hash, index})
|
|
||||||
// Clean up a successful fetch
|
|
||||||
request.Headers[i] = nil
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
q.lock.RUnlock()
|
q.lock.RUnlock()
|
||||||
q.lock.Lock()
|
q.lock.Lock()
|
||||||
for _, item := range acceptedItems {
|
var acceptCount = 0
|
||||||
donePool[item.hash] = struct{}{}
|
for _, header := range request.Headers[:i] {
|
||||||
if item.index < len(q.resultCache) {
|
index := int(header.Number.Int64() - int64(q.resultOffset))
|
||||||
if res := q.resultCache[item.index]; res != nil {
|
if index >= len(q.resultCache) || index < 0 {
|
||||||
reconstruct(item.index, res)
|
// TODO! this should probably be errStaleDelivery instead
|
||||||
res.Pending--
|
failure = errStaleDelivery
|
||||||
delete(taskPool, item.hash)
|
break
|
||||||
}
|
}
|
||||||
|
if res := q.resultCache[index]; res != nil {
|
||||||
|
hash := header.Hash()
|
||||||
|
donePool[hash] = struct{}{}
|
||||||
|
reconstruct(acceptCount, res)
|
||||||
|
res.Pending--
|
||||||
|
delete(taskPool, hash)
|
||||||
}
|
}
|
||||||
// else: betweeen here and above, some other peer filled this result
|
// else: betweeen here and above, some other peer filled this result
|
||||||
// we just ignore and move on
|
// we just ignore and move on
|
||||||
|
|
||||||
|
// Clean up a successful fetch
|
||||||
|
request.Headers[acceptCount] = nil
|
||||||
|
acceptCount++
|
||||||
}
|
}
|
||||||
// Return all failed or missing fetches to the queue
|
// Return all failed or missing fetches to the queue
|
||||||
for _, header := range request.Headers[i:] {
|
for _, header := range request.Headers[acceptCount:] {
|
||||||
if header != nil {
|
if header != nil {
|
||||||
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||||
}
|
}
|
||||||
|
|
@ -888,7 +885,6 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header, taskQ
|
||||||
q.lock.Unlock()
|
q.lock.Unlock()
|
||||||
|
|
||||||
// Wake up Results
|
// Wake up Results
|
||||||
var acceptCount = len(acceptedItems)
|
|
||||||
if acceptCount > 0 {
|
if acceptCount > 0 {
|
||||||
q.active.Signal()
|
q.active.Signal()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue