@@ -3,6 +3,7 @@ package fetcher
3
3
4
4
import (
5
5
"errors"
6
+ "fmt"
6
7
"math/rand"
7
8
"time"
8
9
@@ -15,9 +16,10 @@ import (
15
16
16
17
const (
17
18
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
18
20
fetchTimeout = 5 * time .Second // Maximum alloted time to return an explicitly requested block
19
21
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
21
23
)
22
24
23
25
var (
@@ -239,7 +241,7 @@ func (f *Fetcher) loop() {
239
241
request := make (map [string ][]common.Hash )
240
242
241
243
for hash , announces := range f .announced {
242
- if time .Since (announces [0 ].time ) > arriveTimeout {
244
+ if time .Since (announces [0 ].time ) > arriveTimeout - gatherSlack {
243
245
announce := announces [rand .Intn (len (announces ))]
244
246
if f .getBlock (hash ) == nil {
245
247
request [announce .origin ] = append (request [announce .origin ], hash )
@@ -249,7 +251,16 @@ func (f *Fetcher) loop() {
249
251
}
250
252
}
251
253
// 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
+ }
253
264
go f .fetching [hashes [0 ]].fetch (hashes )
254
265
}
255
266
// Schedule the next fetch if blocks are still pending
@@ -319,7 +330,7 @@ func (f *Fetcher) enqueue(peer string, block *types.Block) {
319
330
320
331
// Discard any past or too distant blocks
321
332
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 )
323
334
return
324
335
}
325
336
// Schedule the block for future importing
0 commit comments