mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
eth/downloader: fix vet, megacheck
This commit is contained in:
parent
50d0c3f874
commit
b48521a3e7
3 changed files with 4 additions and 65 deletions
|
|
@ -38,8 +38,6 @@ var (
|
|||
receiptDropMeter = metrics.NewMeter("eth/downloader/receipts/drop")
|
||||
receiptTimeoutMeter = metrics.NewMeter("eth/downloader/receipts/timeout")
|
||||
|
||||
stateInMeter = metrics.NewMeter("eth/downloader/states/in")
|
||||
stateReqTimer = metrics.NewTimer("eth/downloader/states/req")
|
||||
stateDropMeter = metrics.NewMeter("eth/downloader/states/drop")
|
||||
stateTimeoutMeter = metrics.NewMeter("eth/downloader/states/timeout")
|
||||
stateInMeter = metrics.NewMeter("eth/downloader/states/in")
|
||||
stateDropMeter = metrics.NewMeter("eth/downloader/states/drop")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -32,10 +32,7 @@ import (
|
|||
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
||||
)
|
||||
|
||||
var (
|
||||
blockCacheLimit = 8192 // Maximum number of blocks to cache before throttling the download
|
||||
maxInFlightStates = 8192 // Maximum number of state downloads to allow concurrently
|
||||
)
|
||||
var blockCacheLimit = 8192 // Maximum number of blocks to cache before throttling the download
|
||||
|
||||
var (
|
||||
errNoFetchesPending = errors.New("no fetches pending")
|
||||
|
|
@ -432,62 +429,6 @@ func (q *queue) ReserveHeaders(p *peer, count int) *fetchRequest {
|
|||
return request
|
||||
}
|
||||
|
||||
// reserveHashes reserves a set of hashes for the given peer, skipping previously
|
||||
// failed ones.
|
||||
//
|
||||
// Note, this method expects the queue lock to be already held for writing. The
|
||||
// reason the lock is not obtained in here is because the parameters already need
|
||||
// to access the queue, so they already need a lock anyway.
|
||||
func (q *queue) reserveHashes(p *peer, count int, taskQueue *prque.Prque, taskGen func(int), pendPool map[string]*fetchRequest, maxPending int) *fetchRequest {
|
||||
// Short circuit if the peer's already downloading something (sanity check to
|
||||
// not corrupt state)
|
||||
if _, ok := pendPool[p.id]; ok {
|
||||
return nil
|
||||
}
|
||||
// Calculate an upper limit on the hashes we might fetch (i.e. throttling)
|
||||
allowance := maxPending
|
||||
if allowance > 0 {
|
||||
for _, request := range pendPool {
|
||||
allowance -= len(request.Hashes)
|
||||
}
|
||||
}
|
||||
// If there's a task generator, ask it to fill our task queue
|
||||
if taskGen != nil && taskQueue.Size() < allowance {
|
||||
taskGen(allowance - taskQueue.Size())
|
||||
}
|
||||
if taskQueue.Empty() {
|
||||
return nil
|
||||
}
|
||||
// Retrieve a batch of hashes, skipping previously failed ones
|
||||
send := make(map[common.Hash]int)
|
||||
skip := make(map[common.Hash]int)
|
||||
|
||||
for proc := 0; (allowance == 0 || proc < allowance) && len(send) < count && !taskQueue.Empty(); proc++ {
|
||||
hash, priority := taskQueue.Pop()
|
||||
if p.Lacks(hash.(common.Hash)) {
|
||||
skip[hash.(common.Hash)] = int(priority)
|
||||
} else {
|
||||
send[hash.(common.Hash)] = int(priority)
|
||||
}
|
||||
}
|
||||
// Merge all the skipped hashes back
|
||||
for hash, index := range skip {
|
||||
taskQueue.Push(hash, float32(index))
|
||||
}
|
||||
// Assemble and return the block download request
|
||||
if len(send) == 0 {
|
||||
return nil
|
||||
}
|
||||
request := &fetchRequest{
|
||||
Peer: p,
|
||||
Hashes: send,
|
||||
Time: time.Now(),
|
||||
}
|
||||
pendPool[p.id] = request
|
||||
|
||||
return request
|
||||
}
|
||||
|
||||
// ReserveBodies reserves a set of body fetches for the given peer, skipping any
|
||||
// previously failed downloads. Beside the next batch of needed fetches, it also
|
||||
// returns a flag whether empty blocks were queued requiring processing.
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ func (s *stateSync) process(req *stateReq) (nproc int, err error) {
|
|||
for _, blob := range req.response {
|
||||
hash, err := s.processNodeData(blob, batch)
|
||||
if err != nil && err != trie.ErrNotRequested {
|
||||
return 0, fmt.Errorf("invalid state node %s: %v", err)
|
||||
return 0, fmt.Errorf("invalid state node %s: %v", hash.TerminalString(), err)
|
||||
} else if err == nil {
|
||||
nproc++
|
||||
delete(req.tasks, hash)
|
||||
|
|
|
|||
Loading…
Reference in a new issue