@ -1276,7 +1276,10 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
var (
var (
mode = d . getMode ( )
mode = d . getMode ( )
gotHeaders = false // Wait for batches of headers to process
gotHeaders = false // Wait for batches of headers to process
timer = time . NewTimer ( time . Second )
)
)
defer timer . Stop ( )
for {
for {
select {
select {
case <- d . cancelCh :
case <- d . cancelCh :
@ -1397,10 +1400,11 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
if mode == FullSync || mode == SnapSync {
if mode == FullSync || mode == SnapSync {
// If we've reached the allowed number of pending headers, stall a bit
// If we've reached the allowed number of pending headers, stall a bit
for d . queue . PendingBodies ( ) >= maxQueuedHeaders || d . queue . PendingReceipts ( ) >= maxQueuedHeaders {
for d . queue . PendingBodies ( ) >= maxQueuedHeaders || d . queue . PendingReceipts ( ) >= maxQueuedHeaders {
timer . Reset ( time . Second )
select {
select {
case <- d . cancelCh :
case <- d . cancelCh :
return errCanceled
return errCanceled
case <- time . After ( time . Second ) :
case <- timer . C :
}
}
}
}
// Otherwise insert the headers for content retrieval
// Otherwise insert the headers for content retrieval
@ -1567,7 +1571,10 @@ func (d *Downloader) processSnapSyncContent() error {
var (
var (
oldPivot * fetchResult // Locked in pivot block, might change eventually
oldPivot * fetchResult // Locked in pivot block, might change eventually
oldTail [ ] * fetchResult // Downloaded content after the pivot
oldTail [ ] * fetchResult // Downloaded content after the pivot
timer = time . NewTimer ( time . Second )
)
)
defer timer . Stop ( )
for {
for {
// Wait for the next batch of downloaded data to be available. If we have
// Wait for the next batch of downloaded data to be available. If we have
// not yet reached the pivot point, wait blockingly as there's no need to
// not yet reached the pivot point, wait blockingly as there's no need to
@ -1650,6 +1657,7 @@ func (d *Downloader) processSnapSyncContent() error {
oldPivot = P
oldPivot = P
}
}
// Wait for completion, occasionally checking for pivot staleness
// Wait for completion, occasionally checking for pivot staleness
timer . Reset ( time . Second )
select {
select {
case <- sync . done :
case <- sync . done :
if sync . err != nil {
if sync . err != nil {
@ -1660,7 +1668,7 @@ func (d *Downloader) processSnapSyncContent() error {
}
}
oldPivot = nil
oldPivot = nil
case <- time . After ( time . Second ) :
case <- timer . C :
oldTail = afterP
oldTail = afterP
continue
continue
}
}