|
|
|
@ -107,6 +107,7 @@ WorkLoop: |
|
|
|
|
} else { |
|
|
|
|
// wait a sec and try again
|
|
|
|
|
time.Sleep(1 * time.Second) |
|
|
|
|
log.Infof("error fetching block %d, retry %d (%v)", blockNum, i+1, r.error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -124,6 +125,7 @@ func (self *BlockFetcher) sendWork(b BlockNumber) { |
|
|
|
|
|
|
|
|
|
func (self *BlockFetcher) fetch() *[]FetchedBlock { |
|
|
|
|
log.Debugf("blockfetcher beginning fetch") |
|
|
|
|
startTime := time.Now() |
|
|
|
|
for i := uint(1); i < self.desiredFetcherThreads+uint(1); i++ { |
|
|
|
|
go self.fetcher(i) |
|
|
|
|
} |
|
|
|
@ -141,6 +143,21 @@ func (self *BlockFetcher) fetch() *[]FetchedBlock { |
|
|
|
|
case result := <-self.resultsChannel: |
|
|
|
|
self.receiveResult(result) |
|
|
|
|
default: |
|
|
|
|
|
|
|
|
|
if startTime.Add(30 * time.Second).Before(time.Now()) { |
|
|
|
|
// fetch took too long, return anyway
|
|
|
|
|
log.Infof("30s fetcher batch timeout reached, but not done fetching") |
|
|
|
|
// return what we have
|
|
|
|
|
var final []FetchedBlock |
|
|
|
|
self.lock.Lock() |
|
|
|
|
for _, value := range self.fetchedBlocks { |
|
|
|
|
final = append(final, *value) |
|
|
|
|
} |
|
|
|
|
self.lock.Unlock() |
|
|
|
|
self = nil //this BlockFetcher is now finished.
|
|
|
|
|
return &final |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if self.Done() == true { |
|
|
|
|
log.Infof("blockfetcher %+v considers itself Done()", self) |
|
|
|
|
// if we get here, it's because workList is now empty and there
|
|
|
|
|