fix:commit suggestion

This commit is contained in:
songzhibin97 2024-03-16 08:56:50 +08:00
parent 89f5aa6104
commit 98db98fb42
4 changed files with 21 additions and 19 deletions

View file

@ -1280,12 +1280,12 @@ func (d *Downloader) fetchReceipts(from uint64, beaconMode bool) error {
// queue until the stream ends or a failure occurs. // queue until the stream ends or a failure occurs.
func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode bool) error { func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode bool) error {
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
secondTimer = time.NewTimer(time.Second) timer = time.NewTimer(time.Second)
) )
defer secondTimer.Stop() defer timer.Stop()
for { for {
select { select {
@ -1407,11 +1407,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 {
secondTimer.Reset(time.Second) timer.Reset(time.Second)
select { select {
case <-d.cancelCh: case <-d.cancelCh:
return errCanceled return errCanceled
case <-secondTimer.C: case <-timer.C:
} }
} }
// Otherwise insert the headers for content retrieval // Otherwise insert the headers for content retrieval
@ -1576,11 +1576,11 @@ func (d *Downloader) processSnapSyncContent() error {
// Note, there's no issue with memory piling up since after 64 blocks the // Note, there's no issue with memory piling up since after 64 blocks the
// pivot will forcefully move so these accumulators will be dropped. // pivot will forcefully move so these accumulators will be dropped.
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
secondTimer = time.NewTimer(time.Second) timer = time.NewTimer(time.Second)
) )
defer secondTimer.Stop() 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
@ -1663,7 +1663,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
secondTimer.Reset(time.Second) timer.Reset(time.Second)
select { select {
case <-sync.done: case <-sync.done:
if sync.err != nil { if sync.err != nil {
@ -1674,7 +1674,7 @@ func (d *Downloader) processSnapSyncContent() error {
} }
oldPivot = nil oldPivot = nil
case <-secondTimer.C: case <-timer.C:
oldTail = afterP oldTail = afterP
continue continue
} }

View file

@ -303,7 +303,6 @@ func (n *ExecNode) Stop() error {
go func() { go func() {
waitErr <- n.Cmd.Wait() waitErr <- n.Cmd.Wait()
}() }()
timer := time.NewTimer(5 * time.Second) timer := time.NewTimer(5 * time.Second)
defer timer.Stop() defer timer.Stop()

View file

@ -65,10 +65,13 @@ func startStop(net *Network, quit chan struct{}, nodeCount int) {
if err != nil { if err != nil {
panic("Could not startup node network for mocker") panic("Could not startup node network for mocker")
} }
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
timer := time.NewTimer(3 * time.Second) var (
tick = time.NewTicker(10 * time.Second)
timer = time.NewTimer(3 * time.Second)
)
defer tick.Stop()
defer timer.Stop() defer timer.Stop()
for { for {

View file

@ -1028,14 +1028,14 @@ func (net *Network) Load(snap *Snapshot) error {
} }
} }
snapshotLoadTimeoutTimer := time.NewTimer(snapshotLoadTimeout) timeout := time.NewTimer(snapshotLoadTimeout)
defer snapshotLoadTimeoutTimer.Stop() defer timeout.Stop()
select { select {
// Wait until all connections from the snapshot are established. // Wait until all connections from the snapshot are established.
case <-allConnected: case <-allConnected:
// Make sure that we do not wait forever. // Make sure that we do not wait forever.
case <-snapshotLoadTimeoutTimer.C: case <-timeout.C:
return errors.New("snapshot connections not established") return errors.New("snapshot connections not established")
} }
return nil return nil