From b48521a3e7fdc7e5aacfc737b947f9a5e0de9b04 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 31 May 2017 03:53:34 +0200 Subject: [PATCH] eth/downloader: fix vet, megacheck --- eth/downloader/metrics.go | 6 ++-- eth/downloader/queue.go | 61 +------------------------------------ eth/downloader/statesync.go | 2 +- 3 files changed, 4 insertions(+), 65 deletions(-) diff --git a/eth/downloader/metrics.go b/eth/downloader/metrics.go index 0d76c7dfd2..58764ccf06 100644 --- a/eth/downloader/metrics.go +++ b/eth/downloader/metrics.go @@ -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") ) diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 9e59522658..8a7735d673 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -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. diff --git a/eth/downloader/statesync.go b/eth/downloader/statesync.go index 73ca97bad0..46c33ad724 100644 --- a/eth/downloader/statesync.go +++ b/eth/downloader/statesync.go @@ -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)