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:
@ -199,7 +199,6 @@ func (cs *chainSyncer) loop() {
|
||||
cs.pm.txFetcher.Start()
|
||||
defer cs.pm.blockFetcher.Stop()
|
||||
defer cs.pm.txFetcher.Stop()
|
||||
defer cs.pm.downloader.Terminate()
|
||||
|
||||
// The force timer lowers the peer count threshold down to one when it fires.
|
||||
// This ensures we'll always start sync even if there aren't enough peers.
|
||||
@ -222,8 +221,13 @@ func (cs *chainSyncer) loop() {
|
||||
cs.forced = true
|
||||
|
||||
case <-cs.pm.quitSync:
|
||||
// Disable all insertion on the blockchain. This needs to happen before
|
||||
// terminating the downloader because the downloader waits for blockchain
|
||||
// inserts, and these can take a long time to finish.
|
||||
cs.pm.blockchain.StopInsert()
|
||||
cs.pm.downloader.Terminate()
|
||||
if cs.doneCh != nil {
|
||||
cs.pm.downloader.Terminate() // Double term is fine, Cancel would block until queue is emptied
|
||||
// Wait for the current sync to end.
|
||||
<-cs.doneCh
|
||||
}
|
||||
return
|
||||
|
Reference in New Issue
Block a user