light fetcher shutdown

This commit is contained in:
zsfelfoldi 2016-06-26 11:41:20 +02:00
parent a09e88d4bf
commit 78a077372c
2 changed files with 6 additions and 3 deletions

View file

@ -115,6 +115,8 @@ func (f *lightFetcher) fetchBestFromPool() *peer {
func (f *lightFetcher) syncLoop() {
for {
select {
case <-f.pm.quitSync:
return
case <-f.syncPoolNotify:
chn := f.pm.getSyncLock(false)
if chn != nil {
@ -131,13 +133,14 @@ func (f *lightFetcher) syncLoop() {
}()
}
}
case <-f.pm.quitSync:
return
}
}
}
func (f *lightFetcher) syncWithPeer(p *peer) bool {
f.pm.wg.Add(1)
defer f.pm.wg.Done()
headNum := f.chain.CurrentHeader().Number.Uint64()
peerHead := p.headBlockInfo()

View file

@ -60,7 +60,7 @@ func (pm *ProtocolManager) syncer() {
func (pm *ProtocolManager) needToSync(peerHead blockInfo) bool {
head := pm.blockchain.CurrentHeader()
currentTd := core.GetTd(pm.chainDb, head.Hash(), head.Number.Uint64())
return peerHead.Td.Cmp(currentTd) > 0
return currentTd != nil && peerHead.Td.Cmp(currentTd) > 0
}
// synchronise tries to sync up our local block chain with a remote peer.