From eccab312cc50d13d048c5f5e2ed0e2d4e38b3f5b Mon Sep 17 00:00:00 2001 From: pegasas <616672335@qq.com> Date: Tue, 18 Dec 2018 00:37:28 +0800 Subject: [PATCH] pick_more_peer_fetch_header_and_body --- eth/fetcher/fetcher.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go index f0b5e8064b..63ecb5492e 100644 --- a/eth/fetcher/fetcher.go +++ b/eth/fetcher/fetcher.go @@ -369,13 +369,15 @@ func (f *Fetcher) loop() { for hash, announces := range f.announced { if time.Since(announces[0].time) > arriveTimeout-gatherSlack { // Pick a random peer to retrieve from, reset all others - announce := announces[rand.Intn(len(announces))] f.forgetHash(hash) // If the block still didn't arrive, queue for fetching if f.getBlock(hash) == nil { - request[announce.origin] = append(request[announce.origin], hash) - f.fetching[hash] = announce + // Pick more peers to retrieve from + for _, announce := range announces { + request[announce.origin] = append(request[announce.origin], hash) + } + f.fetching[hash] = announces[rand.Intn(len(announces))] } } } @@ -404,13 +406,14 @@ func (f *Fetcher) loop() { for hash, announces := range f.fetched { // Pick a random peer to retrieve from, reset all others - announce := announces[rand.Intn(len(announces))] f.forgetHash(hash) // If the block still didn't arrive, queue for completion if f.getBlock(hash) == nil { - request[announce.origin] = append(request[announce.origin], hash) - f.completing[hash] = announce + for _, announce := range announces { + request[announce.origin] = append(request[announce.origin], hash) + } + f.completing[hash] = announces[rand.Intn(len(announces))] } } // Send out all block body requests