eth: stop insert if terminate invoked

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-06-18 23:16:19 +08:00
parent ff0f3c50e9
commit 538ea2dea1

View file

@ -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 {