Skip to content

Commit 8906b2f

Browse files
committed
eth/downloader: fix reviewer comments
1 parent e86619e commit 8906b2f

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

‎eth/downloader/downloader.go‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var (
6565
maxQueuedHashes = 32 * 1024 // [eth/61] Maximum number of hashes to queue for import (DOS protection)
6666
maxQueuedHeaders = 32 * 1024 // [eth/62] Maximum number of headers to queue for import (DOS protection)
6767
maxHeadersProcess = 2048 // Number of header download results to import at once into the chain
68-
maxResultsProcess = 4096 // Number of content download results to import at once into the chain
68+
maxResultsProcess = 2048 // Number of content download results to import at once into the chain
6969

7070
fsHeaderCheckFrequency = 100 // Verification frequency of the downloaded headers during fast sync
7171
fsHeaderSafetyNet = 2048 // Number of headers to discard in case a chain violation is detected
@@ -716,9 +716,9 @@ func (d *Downloader) fetchHashes61(p *peer, td *big.Int, from uint64) error {
716716
getHashes := func(from uint64) {
717717
glog.V(logger.Detail).Infof("%v: fetching %d hashes from #%d", p, MaxHashFetch, from)
718718

719-
go p.getAbsHashes(from, MaxHashFetch)
720719
request = time.Now()
721720
timeout.Reset(hashTTL)
721+
go p.getAbsHashes(from, MaxHashFetch)
722722
}
723723
// Start pulling hashes, until all are exhausted
724724
getHashes(from)
@@ -1168,7 +1168,7 @@ func (d *Downloader) findAncestor(p *peer, height uint64) (uint64, error) {
11681168
// facilitate concurrency but still protect against malicious nodes sending bad
11691169
// headers, we construct a header chain skeleton using the "origin" peer we are
11701170
// syncing with, and fill in the missing headers using anyone else. Headers from
1171-
// other peers are only accepted if they map cleanly to the skeleton. If noone
1171+
// other peers are only accepted if they map cleanly to the skeleton. If no one
11721172
// can fill in the skeleton - not even the origin peer - it's assumed invalid and
11731173
// the origin is dropped.
11741174
func (d *Downloader) fetchHeaders(p *peer, from uint64) error {
@@ -1183,15 +1183,16 @@ func (d *Downloader) fetchHeaders(p *peer, from uint64) error {
11831183
defer timeout.Stop()
11841184

11851185
getHeaders := func(from uint64) {
1186+
request = time.Now()
1187+
timeout.Reset(headerTTL)
1188+
11861189
if skeleton {
11871190
glog.V(logger.Detail).Infof("%v: fetching %d skeleton headers from #%d", p, MaxHeaderFetch, from)
11881191
go p.getAbsHeaders(from+uint64(MaxHeaderFetch)-1, MaxSkeletonSize, MaxHeaderFetch-1, false)
11891192
} else {
11901193
glog.V(logger.Detail).Infof("%v: fetching %d full headers from #%d", p, MaxHeaderFetch, from)
11911194
go p.getAbsHeaders(from, MaxHeaderFetch, 0, false)
11921195
}
1193-
request = time.Now()
1194-
timeout.Reset(headerTTL)
11951196
}
11961197
// Start pulling the header chain skeleton until all is done
11971198
getHeaders(from)
@@ -1413,6 +1414,28 @@ func (d *Downloader) fetchNodeData() error {
14131414
// fetchParts iteratively downloads scheduled block parts, taking any available
14141415
// peers, reserving a chunk of fetch requests for each, waiting for delivery and
14151416
// also periodically checking for timeouts.
1417+
//
1418+
// As the scheduling/timeout logic mostly is the same for all downloaded data
1419+
// types, this method is used by each for data gathering and is instrumented with
1420+
// various callbacks to handle the slight differences between processing them.
1421+
//
1422+
// The instrumentation parameters:
1423+
// - errCancel: error type to return if the fetch operation is cancelled (mostly makes logging nicer)
1424+
// - deliveryCh: channel from which to retrieve downloaded data packets (merged from all concurrent peers)
1425+
// - deliver: processing callback to deliver data packets into type specific download queues (usually within `queue`)
1426+
// - wakeCh: notification channel for waking the fetcher when new tasks are available (or sync completed)
1427+
// - expire: task callback method to abort requests that took too long and return the faulty peers (traffic shaping)
1428+
// - pending: task callback for the number of requests still needing download (detect completion/non-completability)
1429+
// - inFlight: task callback for the number of in-progress requests (wait for all active downloads to finish)
1430+
// - throttle: task callback to check if the processing queue is full and activate throttling (bound memory use)
1431+
// - reserve: task callback to reserve new download tasks to a particular peer (also signals partial completions)
1432+
// - fetchHook: tester callback to notify of new tasks being initiated (allows testing the scheduling logic)
1433+
// - fetch: network callback to actually send a particular download request to a physical remote peer
1434+
// - cancel: task callback to abort an in-flight download request and allow rescheduling it (in case of lost peer)
1435+
// - capacity: network callback to retreive the estimated type-specific bandwidth capacity of a peer (traffic shaping)
1436+
// - idle: network callback to retrieve the currently (type specific) idle peers that can be assigned tasks
1437+
// - setIdle: network callback to set a peer back to idle and update its estimated capacity (traffic shaping)
1438+
// - kind: textual label of the type being downloaded to display in log mesages
14161439
func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliver func(dataPack) (int, error), wakeCh chan bool,
14171440
expire func() map[string]int, pending func() int, inFlight func() bool, throttle func() bool, reserve func(*peer, int) (*fetchRequest, bool, error),
14181441
fetchHook func([]*types.Header), fetch func(*peer, *fetchRequest) error, cancel func(*fetchRequest), capacity func(*peer) int,
@@ -1581,10 +1604,10 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
15811604
for i, header := range rollback {
15821605
hashes[i] = header.Hash()
15831606
}
1584-
lh, lfb, lb := d.headHeader().Number, d.headFastBlock().Number(), d.headBlock().Number()
1607+
lastHeader, lastFastBlock, lastBlock := d.headHeader().Number, d.headFastBlock().Number(), d.headBlock().Number()
15851608
d.rollback(hashes)
15861609
glog.V(logger.Warn).Infof("Rolled back %d headers (LH: %d->%d, FB: %d->%d, LB: %d->%d)",
1587-
len(hashes), lh, d.headHeader().Number, lfb, d.headFastBlock().Number(), lb, d.headBlock().Number())
1610+
len(hashes), lastHeader, d.headHeader().Number, lastFastBlock, d.headFastBlock().Number(), lastBlock, d.headBlock().Number())
15881611

15891612
// If we're already past the pivot point, this could be an attack, disable fast sync
15901613
if rollback[len(rollback)-1].Number.Uint64() > pivot {

‎eth/downloader/queue.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import (
3939
)
4040

4141
var (
42-
blockCacheLimit = 16384 // Maximum number of blocks to cache before throttling the download
43-
maxInFlightStates = 8192 // Maximum number of state downloads to allow concurrently
42+
blockCacheLimit = 8192 // Maximum number of blocks to cache before throttling the download
43+
maxInFlightStates = 8192 // Maximum number of state downloads to allow concurrently
4444
)
4545

4646
var (

0 commit comments

Comments
 (0)