diff options
author | Sonic <sonic@dexon.org> | 2019-03-20 14:48:21 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:58 +0800 |
commit | 4364f00e2204debb48edf2940e1f89f46d7a9a18 (patch) | |
tree | 58fbb811448899b5160ceb36bd36787516d181c8 /dex/sync.go | |
parent | bbd2910687e9e5cd5c52e887f837f5c992ba2261 (diff) | |
download | dexon-4364f00e2204debb48edf2940e1f89f46d7a9a18.tar dexon-4364f00e2204debb48edf2940e1f89f46d7a9a18.tar.gz dexon-4364f00e2204debb48edf2940e1f89f46d7a9a18.tar.bz2 dexon-4364f00e2204debb48edf2940e1f89f46d7a9a18.tar.lz dexon-4364f00e2204debb48edf2940e1f89f46d7a9a18.tar.xz dexon-4364f00e2204debb48edf2940e1f89f46d7a9a18.tar.zst dexon-4364f00e2204debb48edf2940e1f89f46d7a9a18.zip |
dex: ignore acceptableDist when force synchronise (#285)
Diffstat (limited to 'dex/sync.go')
-rw-r--r-- | dex/sync.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/dex/sync.go b/dex/sync.go index 927c04bc3..93bed87c4 100644 --- a/dex/sync.go +++ b/dex/sync.go @@ -245,11 +245,11 @@ func (pm *ProtocolManager) syncer() { if pm.peers.Len() < minDesiredPeerCount { break } - go pm.synchronise(pm.peers.BestPeer()) + go pm.synchronise(pm.peers.BestPeer(), false) case <-forceSync.C: // Force a sync even if not enough peers are present - go pm.synchronise(pm.peers.BestPeer()) + go pm.synchronise(pm.peers.BestPeer(), false) case <-pm.noMorePeers: return @@ -258,7 +258,7 @@ func (pm *ProtocolManager) syncer() { } // synchronise tries to sync up our local block chain with a remote peer. -func (pm *ProtocolManager) synchronise(peer *peer) { +func (pm *ProtocolManager) synchronise(peer *peer, force bool) { // Short circuit if no peers are available if peer == nil { return @@ -271,9 +271,15 @@ func (pm *ProtocolManager) synchronise(peer *peer) { // If we are behind the peer, but not more than acceptable distance, don't // trigger a sync. Fetcher is able to cover this. - if pNumber <= number+acceptableDist { + var dist uint64 + if !force { + dist = acceptableDist + } + + if pNumber <= number+dist { return } + // Otherwise try to sync with the downloader mode := downloader.FullSync if atomic.LoadUint32(&pm.fastSync) == 1 { |