From 78a077372c432e8d6c626f3851dae7ee4ec45b55 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Sun, 26 Jun 2016 11:41:20 +0200 Subject: [PATCH] light fetcher shutdown --- les/fetcher.go | 7 +++++-- les/sync.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/les/fetcher.go b/les/fetcher.go index f8c997162d..ac6fb0021c 100644 --- a/les/fetcher.go +++ b/les/fetcher.go @@ -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() diff --git a/les/sync.go b/les/sync.go index 828ff2ae84..9407df125c 100644 --- a/les/sync.go +++ b/les/sync.go @@ -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.