Commit 6f5c6150 authored by Jeffrey Wilcke's avatar Jeffrey Wilcke

Merge pull request #1255 from obscuren/chain-proc-interupt

eth, core: interrupt the chain processing on stop
parents 1bca2f6e 645dfd96
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"os" "os"
"runtime" "runtime"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -101,7 +102,9 @@ type ChainManager struct { ...@@ -101,7 +102,9 @@ type ChainManager struct {
futureBlocks *BlockCache futureBlocks *BlockCache
quit chan struct{} quit chan struct{}
wg sync.WaitGroup // procInterrupt must be atomically called
procInterrupt int32 // interrupt signaler for block processing
wg sync.WaitGroup
pow pow.PoW pow pow.PoW
} }
...@@ -516,6 +519,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) { ...@@ -516,6 +519,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
func (bc *ChainManager) Stop() { func (bc *ChainManager) Stop() {
close(bc.quit) close(bc.quit)
atomic.StoreInt32(&bc.procInterrupt, 1)
bc.wg.Wait() bc.wg.Wait()
...@@ -569,6 +573,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) { ...@@ -569,6 +573,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
txcount := 0 txcount := 0
for i, block := range chain { for i, block := range chain {
if atomic.LoadInt32(&self.procInterrupt) == 1 {
glog.V(logger.Debug).Infoln("Premature abort during chain processing")
break
}
bstart := time.Now() bstart := time.Now()
// Wait for block i's nonce to be verified before processing // Wait for block i's nonce to be verified before processing
// its state transition. // its state transition.
......
...@@ -527,8 +527,8 @@ func (self *Ethereum) AddPeer(nodeURL string) error { ...@@ -527,8 +527,8 @@ func (self *Ethereum) AddPeer(nodeURL string) error {
func (s *Ethereum) Stop() { func (s *Ethereum) Stop() {
s.net.Stop() s.net.Stop()
s.protocolManager.Stop()
s.chainManager.Stop() s.chainManager.Stop()
s.protocolManager.Stop()
s.txPool.Stop() s.txPool.Stop()
s.eventMux.Stop() s.eventMux.Stop()
if s.whisper != nil { if s.whisper != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment