aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-10 17:17:06 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-11 00:47:59 +0800
commitb9affbf9fe1ca8e76aef5efdc456a43dff38dc8d (patch)
tree657c8e14d8e03d22926d09a3db694271c2d94661 /eth
parent858a6f0be9da459a87004755dffae2c3fc5544d2 (diff)
downloadgo-tangerine-b9affbf9fe1ca8e76aef5efdc456a43dff38dc8d.tar.gz
go-tangerine-b9affbf9fe1ca8e76aef5efdc456a43dff38dc8d.tar.zst
go-tangerine-b9affbf9fe1ca8e76aef5efdc456a43dff38dc8d.zip
eth: discard fetched blocks that don't fit (no goroutine)
Diffstat (limited to 'eth')
-rw-r--r--eth/sync.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/eth/sync.go b/eth/sync.go
index a25d4d4fd..7a3b5fcd4 100644
--- a/eth/sync.go
+++ b/eth/sync.go
@@ -200,23 +200,23 @@ func (pm *ProtocolManager) fetcher() {
case <-pm.quitSync:
return
}
- // If any explicit fetches were replied to, import them
- if count := len(explicit); count > 0 {
- glog.V(logger.Debug).Infof("Importing %d explicitly fetched blocks", count)
-
- // Create a closure with the retrieved blocks and origin peers
- peers := make([]*peer, 0, count)
- blocks := make([]*types.Block, 0, count)
- for _, block := range explicit {
- hash := block.Hash()
- if announce := pending[hash]; announce != nil {
+ // Create a closure with the retrieved blocks and origin peers
+ peers := make([]*peer, 0, len(explicit))
+ blocks = make([]*types.Block, 0, len(explicit))
+ for _, block := range explicit {
+ hash := block.Hash()
+ if announce := pending[hash]; announce != nil {
+ // Filter out blocks too new to import anyway
+ if !pm.chainman.HasBlock(hash) && pm.chainman.HasBlock(block.ParentHash()) {
peers = append(peers, announce.peer)
blocks = append(blocks, block)
-
- delete(pending, hash)
}
+ delete(pending, hash)
}
- // Run the importer on a new thread
+ }
+ // If any explicit fetches were replied to, import them
+ if count := len(blocks); count > 0 {
+ glog.V(logger.Debug).Infof("Importing %d explicitly fetched blocks", len(blocks))
go func() {
for i := 0; i < len(blocks); i++ {
if err := pm.importBlock(peers[i], blocks[i], nil); err != nil {