aboutsummaryrefslogtreecommitdiffstats
path: root/eth/sync.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-08 02:07:20 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-05-08 02:07:20 +0800
commit9d188f73b58ee1fe4bda00a9536bda4056755f2c (patch)
treef9f9361b8440865a890df900ea7f7986ba169098 /eth/sync.go
parent43901c92825389b694fb5488c520cf5122f022de (diff)
downloaddexon-9d188f73b58ee1fe4bda00a9536bda4056755f2c.tar
dexon-9d188f73b58ee1fe4bda00a9536bda4056755f2c.tar.gz
dexon-9d188f73b58ee1fe4bda00a9536bda4056755f2c.tar.bz2
dexon-9d188f73b58ee1fe4bda00a9536bda4056755f2c.tar.lz
dexon-9d188f73b58ee1fe4bda00a9536bda4056755f2c.tar.xz
dexon-9d188f73b58ee1fe4bda00a9536bda4056755f2c.tar.zst
dexon-9d188f73b58ee1fe4bda00a9536bda4056755f2c.zip
eth, eth/downloader: make synchronize thread safe
Diffstat (limited to 'eth/sync.go')
-rw-r--r--eth/sync.go16
1 files changed, 4 insertions, 12 deletions
diff --git a/eth/sync.go b/eth/sync.go
index 9e8b21a7c..b259c1d47 100644
--- a/eth/sync.go
+++ b/eth/sync.go
@@ -32,14 +32,14 @@ func (pm *ProtocolManager) update() {
}
itimer.Stop()
- go pm.synchronise(peer)
+ go pm.synchronize(peer)
case <-itimer.C:
// The timer will make sure that the downloader keeps an active state
// in which it attempts to always check the network for highest td peers
// Either select the peer or restart the timer if no peers could
// be selected.
if peer := getBestPeer(pm.peers); peer != nil {
- go pm.synchronise(peer)
+ go pm.synchronize(peer)
} else {
itimer.Reset(5 * time.Second)
}
@@ -63,7 +63,6 @@ func (pm *ProtocolManager) processBlocks() error {
if len(blocks) == 0 {
return nil
}
- defer pm.downloader.Done()
glog.V(logger.Debug).Infof("Inserting chain with %d blocks (#%v - #%v)\n", len(blocks), blocks[0].Number(), blocks[len(blocks)-1].Number())
@@ -78,26 +77,19 @@ func (pm *ProtocolManager) processBlocks() error {
return nil
}
-func (pm *ProtocolManager) synchronise(peer *peer) {
+func (pm *ProtocolManager) synchronize(peer *peer) {
// Make sure the peer's TD is higher than our own. If not drop.
if peer.td.Cmp(pm.chainman.Td()) <= 0 {
return
}
- // Check downloader if it's busy so it doesn't show the sync message
- // for every attempty
- if pm.downloader.IsBusy() {
- return
- }
-
// FIXME if we have the hash in our chain and the TD of the peer is
// much higher than ours, something is wrong with us or the peer.
// Check if the hash is on our own chain
if pm.chainman.HasBlock(peer.recentHash) {
return
}
-
// Get the hashes from the peer (synchronously)
- err := pm.downloader.Synchronise(peer.id, peer.recentHash)
+ err := pm.downloader.Synchronize(peer.id, peer.recentHash)
if err != nil && err == downloader.ErrBadPeer {
glog.V(logger.Debug).Infoln("removed peer from peer set due to bad action")
pm.removePeer(peer)