Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
solution: terminate state sync cleanly
Browse files Browse the repository at this point in the history
via karalabe's un-cherry-pickable 4cf1ece5ba7c28e9ef7edabe0f53e5ae1fe37b76
  • Loading branch information
whilei committed May 28, 2018
1 parent 6c1bf83 commit 57192ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,19 @@ func (d *Downloader) processFastSyncContent(latest *types.Header) error {
)
for {
// Wait for the next batch of downloaded data to be available, and if the pivot
// block became stale, move the goalpost.
// block became stale, move the goalpost
results := d.queue.Results(oldPivot == nil) // Block if we're not monitoring pivot staleness
if len(results) == 0 && oldPivot == nil {
return stateSync.Cancel()
if len(results) == 0 {
// If pivot sync is done, stop
if oldPivot == nil {
return stateSync.Cancel()
}
// If sync failed, stop
select {
case <-d.cancelCh:
return stateSync.Cancel()
default:
}
}
if d.chainInsertHook != nil {
d.chainInsertHook(results)
Expand Down
4 changes: 4 additions & 0 deletions eth/downloader/statesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ func (s *stateSync) loop() error {
case <-s.cancel:
return errCancelStateFetch

case <-s.d.cancelCh:
return errCancelStateFetch

case req := <-s.deliver:
// Response, disconnect or timeout triggered, drop the peer if stalling
glog.V(logger.Debug).Infoln("Received node data response", "peer", req.peer.id, "count", len(req.response), "dropped", req.dropped, "timeout", !req.dropped && req.timedOut())
Expand Down Expand Up @@ -348,6 +351,7 @@ func (s *stateSync) assignTasks() {
case s.d.trackStateReq <- req:
req.peer.FetchNodeData(req.items)
case <-s.cancel:
case <-s.d.cancelCh:
}
}
}
Expand Down

0 comments on commit 57192ef

Please sign in to comment.