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:
@ -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
|
||||
|
Reference in New Issue
Block a user