From 154b9a9ca252866db8c6df062493a6a0522f346f Mon Sep 17 00:00:00 2001
From: ledgerwatch <akhounov@gmail.com>
Date: Mon, 25 May 2020 08:19:08 +0100
Subject: [PATCH] Stop blockchain when terminating downloader (#574)

* Print

* Stop blockchain on Terminate

* Remove prints
---
 eth/downloader/downloader.go      | 4 ++++
 eth/downloader/downloader_test.go | 3 +++
 eth/downloader/stagedsync_test.go | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 0cf03d61c2..50fb76179a 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -231,6 +231,9 @@ type BlockChain interface {
 
 	// GetVMConfig is necessary for staged sync
 	GetVMConfig() *vm.Config
+
+	// Stop the import that is going on
+	Stop()
 }
 
 // New creates a new downloader to fetch hashes and blocks from remote peers.
@@ -609,6 +612,7 @@ func (d *Downloader) Cancel() {
 // Terminate interrupts the downloader, canceling all pending operations.
 // The downloader cannot be reused after calling Terminate.
 func (d *Downloader) Terminate() {
+	d.blockchain.Stop()
 	// Close the termination channel (make sure double close is allowed)
 	d.quitLock.Lock()
 	select {
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go
index f75a66cf9f..ba142586a0 100644
--- a/eth/downloader/downloader_test.go
+++ b/eth/downloader/downloader_test.go
@@ -390,6 +390,9 @@ func (dl *downloadTester) GetHeader(common.Hash, uint64) *types.Header {
 	panic("not implemented and should not be called")
 }
 
+func (dl *downloadTester) Stop() {
+}
+
 type downloadTesterPeer struct {
 	dl            *downloadTester
 	id            string
diff --git a/eth/downloader/stagedsync_test.go b/eth/downloader/stagedsync_test.go
index 65c149812d..0e1db2e29d 100644
--- a/eth/downloader/stagedsync_test.go
+++ b/eth/downloader/stagedsync_test.go
@@ -275,6 +275,9 @@ func (st *stagedSyncTester) sync(id string, td *big.Int) error {
 	return err
 }
 
+func (st *stagedSyncTester) Stop() {
+}
+
 type stagedSyncTesterPeer struct {
 	st    *stagedSyncTester
 	id    string
-- 
GitLab