eth, core: interupt the chain processing on stop
Added an additional channel which is used to interupt the chain manager when it's processing blocks.
This commit is contained in:
parent
e2c2d8e15e
commit
90c4493a10
@ -101,6 +101,7 @@ type ChainManager struct {
|
||||
futureBlocks *BlockCache
|
||||
|
||||
quit chan struct{}
|
||||
procInterupt chan struct{} // interupt signaler for block processing
|
||||
wg sync.WaitGroup
|
||||
|
||||
pow pow.PoW
|
||||
@ -113,6 +114,7 @@ func NewChainManager(genesis *types.Block, blockDb, stateDb common.Database, pow
|
||||
genesisBlock: GenesisBlock(42, stateDb),
|
||||
eventMux: mux,
|
||||
quit: make(chan struct{}),
|
||||
procInterupt: make(chan struct{}),
|
||||
cache: NewBlockCache(blockCacheLimit),
|
||||
pow: pow,
|
||||
}
|
||||
@ -516,6 +518,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
|
||||
|
||||
func (bc *ChainManager) Stop() {
|
||||
close(bc.quit)
|
||||
close(bc.procInterupt)
|
||||
|
||||
bc.wg.Wait()
|
||||
|
||||
@ -568,7 +571,13 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
||||
defer close(nonceQuit)
|
||||
|
||||
txcount := 0
|
||||
done:
|
||||
for i, block := range chain {
|
||||
select {
|
||||
case <-self.procInterupt:
|
||||
glog.V(logger.Debug).Infoln("Premature abort during chain processing")
|
||||
break done
|
||||
default:
|
||||
bstart := time.Now()
|
||||
// Wait for block i's nonce to be verified before processing
|
||||
// its state transition.
|
||||
@ -682,6 +691,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
||||
stats.processed++
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (stats.queued > 0 || stats.processed > 0 || stats.ignored > 0) && bool(glog.V(logger.Info)) {
|
||||
tend := time.Since(tstart)
|
||||
|
@ -527,8 +527,8 @@ func (self *Ethereum) AddPeer(nodeURL string) error {
|
||||
|
||||
func (s *Ethereum) Stop() {
|
||||
s.net.Stop()
|
||||
s.protocolManager.Stop()
|
||||
s.chainManager.Stop()
|
||||
s.protocolManager.Stop()
|
||||
s.txPool.Stop()
|
||||
s.eventMux.Stop()
|
||||
if s.whisper != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user