eth: interrupt chain insertion on shutdown (#21114)

This adds a new API method on core.BlockChain to allow interrupting
running data inserts, and calls the method before shutting down the
downloader.

The BlockChain interrupt checks are now done through a method instead
of inlining the atomic load everywhere. There is no loss of efficiency from
this and it makes the interrupt protocol a lot clearer because the check is
defined next to the method that sets the flag.
This commit is contained in:
Felix Lange
2020-05-26 21:37:37 +02:00
committed by GitHub
parent 4873a9d3c3
commit 9219e0fba4
3 changed files with 38 additions and 22 deletions

View File

@ -314,10 +314,16 @@ func (lc *LightChain) Stop() {
return
}
close(lc.quit)
atomic.StoreInt32(&lc.procInterrupt, 1)
lc.StopInsert()
lc.wg.Wait()
log.Info("Blockchain manager stopped")
log.Info("Blockchain stopped")
}
// StopInsert interrupts all insertion methods, causing them to return
// errInsertionInterrupted as soon as possible. Insertion is permanently disabled after
// calling this method.
func (lc *LightChain) StopInsert() {
atomic.StoreInt32(&lc.procInterrupt, 1)
}
// Rollback is designed to remove a chain of links from the database that aren't