aboutsummaryrefslogtreecommitdiffstats
path: root/eth/sync.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-09 20:09:15 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-09 20:09:15 +0800
commitd09ead546cbdf8e4659e65581f23715101f5b686 (patch)
treee27d333200bc37070c2a488360e11db32f5cf483 /eth/sync.go
parentf86707713c42da02b70a3a389684e19e902d8759 (diff)
downloadgo-tangerine-d09ead546cbdf8e4659e65581f23715101f5b686.tar.gz
go-tangerine-d09ead546cbdf8e4659e65581f23715101f5b686.tar.zst
go-tangerine-d09ead546cbdf8e4659e65581f23715101f5b686.zip
eth: fix a data race in the hash announcement processing
Diffstat (limited to 'eth/sync.go')
-rw-r--r--eth/sync.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/eth/sync.go b/eth/sync.go
index 3a33fe149..8e4e3cfbe 100644
--- a/eth/sync.go
+++ b/eth/sync.go
@@ -109,17 +109,25 @@ func (pm *ProtocolManager) fetcher() {
// If any explicit fetches were replied to, import them
if count := len(explicit); count > 0 {
glog.V(logger.Debug).Infof("Importing %d explicitly fetched blocks", count)
+
+ // Create a closure with the retrieved blocks and origin peers
+ peers := make([]*peer, 0, count)
+ blocks := make([]*types.Block, 0, count)
+ for _, block := range explicit {
+ hash := block.Hash()
+ if announce := pending[hash]; announce != nil {
+ peers = append(peers, announce.peer)
+ blocks = append(blocks, block)
+
+ delete(pending, hash)
+ }
+ }
+ // Run the importer on a new thread
go func() {
- for _, block := range explicit {
- hash := block.Hash()
-
- // Make sure there's still something pending to import
- if announce := pending[hash]; announce != nil {
- delete(pending, hash)
- if err := pm.importBlock(announce.peer, block, nil); err != nil {
- glog.V(logger.Detail).Infof("Failed to import explicitly fetched block: %v", err)
- return
- }
+ for i := 0; i < len(blocks); i++ {
+ if err := pm.importBlock(peers[i], blocks[i], nil); err != nil {
+ glog.V(logger.Detail).Infof("Failed to import explicitly fetched block: %v", err)
+ return
}
}
}()