Skip to content

Commit

Permalink
eth: fix snap sync cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Feb 16, 2021
1 parent 6291fc9 commit bfdff4c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode
case nil, errBusy, errCanceled:
return err
}

if errors.Is(err, errInvalidChain) || errors.Is(err, errBadPeer) || errors.Is(err, errTimeout) ||
errors.Is(err, errStallingPeer) || errors.Is(err, errUnsyncedPeer) || errors.Is(err, errEmptyHeaderSet) ||
errors.Is(err, errPeersUnavailable) || errors.Is(err, errTooOld) || errors.Is(err, errInvalidAncestor) {
Expand Down Expand Up @@ -1764,7 +1763,7 @@ func (d *Downloader) processFastSyncContent() error {
}()

closeOnErr := func(s *stateSync) {
if err := s.Wait(); err != nil && err != errCancelStateFetch && err != errCanceled {
if err := s.Wait(); err != nil && err != errCancelStateFetch && err != errCanceled && err != snap.ErrCancelled {
d.queue.Close() // wake up Results
}
}
Expand Down
1 change: 0 additions & 1 deletion eth/protocols/snap/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var (
errDecode = errors.New("invalid message")
errInvalidMsgCode = errors.New("invalid message code")
errBadRequest = errors.New("bad request")
errCancelled = errors.New("sync cancelled")
)

// Packet represents a p2p message in the `snap` protocol.
Expand Down
6 changes: 5 additions & 1 deletion eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ var (
requestTimeout = 10 * time.Second // TODO(karalabe): Make it dynamic ala fast-sync?
)

// ErrCancelled is returned from snap syncing if the operation was prematurely
// terminated.
var ErrCancelled = errors.New("sync cancelled")

// accountRequest tracks a pending account range request to ensure responses are
// to actual requests and to validate any security constraints.
//
Expand Down Expand Up @@ -615,7 +619,7 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error {
case id := <-peerDrop:
s.revertRequests(id)
case <-cancel:
return errCancelled
return ErrCancelled

case req := <-s.accountReqFails:
s.revertAccountRequest(req)
Expand Down

0 comments on commit bfdff4c

Please sign in to comment.