Skip to content

Commit 8c4c7ea

Browse files
committed
eth/fetcher: lower max cache size, add timeout slack
1 parent d5871fc commit 8c4c7ea

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

eth/fetcher/fetcher.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fetcher
33

44
import (
55
"errors"
6+
"fmt"
67
"math/rand"
78
"time"
89

@@ -15,9 +16,10 @@ import (
1516

1617
const (
1718
arriveTimeout = 500 * time.Millisecond // Time allowance before an announced block is explicitly requested
19+
gatherSlack = 100 * time.Millisecond // Interval used to collate almost-expired announces with fetches
1820
fetchTimeout = 5 * time.Second // Maximum alloted time to return an explicitly requested block
1921
maxUncleDist = 7 // Maximum allowed backward distance from the chain head
20-
maxQueueDist = 256 // Maximum allowed distance from the chain head to queue
22+
maxQueueDist = 32 // Maximum allowed distance from the chain head to queue
2123
)
2224

2325
var (
@@ -239,7 +241,7 @@ func (f *Fetcher) loop() {
239241
request := make(map[string][]common.Hash)
240242

241243
for hash, announces := range f.announced {
242-
if time.Since(announces[0].time) > arriveTimeout {
244+
if time.Since(announces[0].time) > arriveTimeout-gatherSlack {
243245
announce := announces[rand.Intn(len(announces))]
244246
if f.getBlock(hash) == nil {
245247
request[announce.origin] = append(request[announce.origin], hash)
@@ -249,7 +251,16 @@ func (f *Fetcher) loop() {
249251
}
250252
}
251253
// Send out all block requests
252-
for _, hashes := range request {
254+
for peer, hashes := range request {
255+
if glog.V(logger.Detail) && len(hashes) > 0 {
256+
list := "["
257+
for _, hash := range hashes {
258+
list += fmt.Sprintf("%x, ", hash[:4])
259+
}
260+
list = list[:len(list)-2] + "]"
261+
262+
glog.V(logger.Detail).Infof("Peer %s: fetching %s", peer, list)
263+
}
253264
go f.fetching[hashes[0]].fetch(hashes)
254265
}
255266
// Schedule the next fetch if blocks are still pending
@@ -319,7 +330,7 @@ func (f *Fetcher) enqueue(peer string, block *types.Block) {
319330

320331
// Discard any past or too distant blocks
321332
if dist := int64(block.NumberU64()) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist {
322-
glog.V(logger.Detail).Infof("Peer %s: discarded block #%d [%x], distance %d", peer, block.NumberU64(), hash.Bytes()[:4], dist)
333+
glog.V(logger.Debug).Infof("Peer %s: discarded block #%d [%x], distance %d", peer, block.NumberU64(), hash.Bytes()[:4], dist)
323334
return
324335
}
325336
// Schedule the block for future importing

0 commit comments

Comments
 (0)