eth: discard fetched blocks that don't fit (no goroutine)

This commit is contained in:
Péter Szilágyi 2015-06-10 12:17:06 +03:00
parent 858a6f0be9
commit b9affbf9fe
1 changed files with 13 additions and 13 deletions

View File

@ -200,23 +200,23 @@ func (pm *ProtocolManager) fetcher() {
case <-pm.quitSync: case <-pm.quitSync:
return return
} }
// If any explicit fetches were replied to, import them // Create a closure with the retrieved blocks and origin peers
if count := len(explicit); count > 0 { peers := make([]*peer, 0, len(explicit))
glog.V(logger.Debug).Infof("Importing %d explicitly fetched blocks", count) blocks = make([]*types.Block, 0, len(explicit))
for _, block := range explicit {
// Create a closure with the retrieved blocks and origin peers hash := block.Hash()
peers := make([]*peer, 0, count) if announce := pending[hash]; announce != nil {
blocks := make([]*types.Block, 0, count) // Filter out blocks too new to import anyway
for _, block := range explicit { if !pm.chainman.HasBlock(hash) && pm.chainman.HasBlock(block.ParentHash()) {
hash := block.Hash()
if announce := pending[hash]; announce != nil {
peers = append(peers, announce.peer) peers = append(peers, announce.peer)
blocks = append(blocks, block) 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() { go func() {
for i := 0; i < len(blocks); i++ { for i := 0; i < len(blocks); i++ {
if err := pm.importBlock(peers[i], blocks[i], nil); err != nil { if err := pm.importBlock(peers[i], blocks[i], nil); err != nil {