From 538ea2dea140428692afaa34183d19321d811727 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Wed, 18 Jun 2025 23:16:19 +0800 Subject: [PATCH] eth: stop insert if terminate invoked Signed-off-by: jsvisa --- eth/downloader/downloader.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 762fb9283e..8f8f219597 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -199,6 +199,9 @@ type BlockChain interface { // InsertChain inserts a batch of blocks into the local chain. InsertChain(types.Blocks) (int, error) + // StopInsert interrupts the inserting process. + StopInsert() + // InsertReceiptChain inserts a batch of blocks along with their receipts // into the local chain. Blocks older than the specified `ancientLimit` // are stored directly in the ancient store, while newer blocks are stored @@ -634,6 +637,9 @@ func (d *Downloader) Cancel() { // Terminate interrupts the downloader, canceling all pending operations. // The downloader cannot be reused after calling Terminate. func (d *Downloader) Terminate() { + // Signal to stop inserting in-flight blocks + d.blockchain.StopInsert() + // Close the termination channel (make sure double close is allowed) d.quitLock.Lock() select {