diff options
Diffstat (limited to 'eth/downloader')
-rw-r--r-- | eth/downloader/downloader.go | 2 | ||||
-rw-r--r-- | eth/downloader/downloader_test.go | 2 | ||||
-rw-r--r-- | eth/downloader/peer.go | 4 | ||||
-rw-r--r-- | eth/downloader/queue.go | 19 |
4 files changed, 16 insertions, 11 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index b1f4b8169..9be4bd87d 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1005,7 +1005,7 @@ func (d *Downloader) fetchNodeData() error { // - fetchHook: tester callback to notify of new tasks being initiated (allows testing the scheduling logic) // - fetch: network callback to actually send a particular download request to a physical remote peer // - cancel: task callback to abort an in-flight download request and allow rescheduling it (in case of lost peer) -// - capacity: network callback to retreive the estimated type-specific bandwidth capacity of a peer (traffic shaping) +// - capacity: network callback to retrieve the estimated type-specific bandwidth capacity of a peer (traffic shaping) // - idle: network callback to retrieve the currently (type specific) idle peers that can be assigned tasks // - setIdle: network callback to set a peer back to idle and update its estimated capacity (traffic shaping) // - kind: textual label of the type being downloaded to display in log mesages diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 86638ae2d..b43edf53e 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -119,7 +119,7 @@ func (dl *downloadTester) makeChain(n int, seed byte, parent *types.Block, paren // If the block number is multiple of 3, send a bonus transaction to the miner if parent == dl.genesis && i%3 == 0 { signer := types.MakeSigner(params.TestChainConfig, block.Number()) - tx, err := types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(signer, testKey) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil), signer, testKey) if err != nil { panic(err) } diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go index b0bfc66c8..ea4b6a6f2 100644 --- a/eth/downloader/peer.go +++ b/eth/downloader/peer.go @@ -205,7 +205,7 @@ func (p *peer) FetchNodeData(request *fetchRequest) error { // Convert the hash set to a retrievable slice hashes := make([]common.Hash, 0, len(request.Hashes)) - for hash, _ := range request.Hashes { + for hash := range request.Hashes { hashes = append(hashes, hash) } go p.getNodeData(hashes) @@ -314,7 +314,7 @@ func (p *peer) MarkLacking(hash common.Hash) { defer p.lock.Unlock() for len(p.lacking) >= maxLackingHashes { - for drop, _ := range p.lacking { + for drop := range p.lacking { delete(p.lacking, drop) break } diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index b7ad92099..dd9590b28 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -844,7 +844,7 @@ func (q *queue) expire(timeout time.Duration, pendPool map[string]*fetchRequest, } } // Remove the expired requests from the pending pool - for id, _ := range expiries { + for id := range expiries { delete(pendPool, id) } return expiries @@ -1063,7 +1063,7 @@ func (q *queue) DeliverNodeData(id string, data [][]byte, callback func(int, boo // If no data was retrieved, mark their hashes as unavailable for the origin peer if len(data) == 0 { - for hash, _ := range request.Hashes { + for hash := range request.Hashes { request.Peer.MarkLacking(hash) } } @@ -1123,15 +1123,20 @@ func (q *queue) deliverNodeData(results []trie.SyncResult, callback func(int, bo callback(i, progressed, errNoFetchesPending) return } - if prog, _, err := q.stateScheduler.Process([]trie.SyncResult{result}); err != nil { - // Processing a state result failed, bail out + + batch := q.stateDatabase.NewBatch() + prog, _, err := q.stateScheduler.Process([]trie.SyncResult{result}, batch) + if err != nil { + q.stateSchedLock.Unlock() + callback(i, progressed, err) + } + if err = batch.Write(); err != nil { q.stateSchedLock.Unlock() callback(i, progressed, err) - return - } else if prog { - progressed = true } + // Item processing succeeded, release the lock (temporarily) + progressed = progressed || prog q.stateSchedLock.Unlock() } callback(len(results), progressed, nil) |