aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-12 23:04:02 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-12 23:04:02 +0800
commit6f5c6150b7060b6b2ee68ac95b30f46c5c2c7f90 (patch)
treec000cf8a13294c91e608e28db98977e43f0c0752 /core
parent1bca2f6ec4df5adfe2ff58affb9fe5ef1e84c954 (diff)
parent645dfd96932c87e256c3edc9035843c6baf4a2e8 (diff)
downloaddexon-6f5c6150b7060b6b2ee68ac95b30f46c5c2c7f90.tar.gz
dexon-6f5c6150b7060b6b2ee68ac95b30f46c5c2c7f90.tar.zst
dexon-6f5c6150b7060b6b2ee68ac95b30f46c5c2c7f90.zip
Merge pull request #1255 from obscuren/chain-proc-interupt
eth, core: interrupt the chain processing on stop
Diffstat (limited to 'core')
-rw-r--r--core/chain_manager.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index be64b54f4..e56d82cce 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -8,6 +8,7 @@ import (
"os"
"runtime"
"sync"
+ "sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common"
@@ -101,7 +102,9 @@ type ChainManager struct {
futureBlocks *BlockCache
quit chan struct{}
- wg sync.WaitGroup
+ // procInterrupt must be atomically called
+ procInterrupt int32 // interrupt signaler for block processing
+ wg sync.WaitGroup
pow pow.PoW
}
@@ -516,6 +519,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
func (bc *ChainManager) Stop() {
close(bc.quit)
+ atomic.StoreInt32(&bc.procInterrupt, 1)
bc.wg.Wait()
@@ -569,6 +573,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
txcount := 0
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()
// Wait for block i's nonce to be verified before processing
// its state transition.