Skip to content

Commit 6f5c615

Browse files
committed
Merge pull request #1255 from obscuren/chain-proc-interupt
eth, core: interrupt the chain processing on stop
2 parents 1bca2f6 + 645dfd9 commit 6f5c615

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/chain_manager.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"runtime"
1010
"sync"
11+
"sync/atomic"
1112
"time"
1213

1314
"github.com/ethereum/go-ethereum/common"
@@ -101,7 +102,9 @@ type ChainManager struct {
101102
futureBlocks *BlockCache
102103

103104
quit chan struct{}
104-
wg sync.WaitGroup
105+
// procInterrupt must be atomically called
106+
procInterrupt int32 // interrupt signaler for block processing
107+
wg sync.WaitGroup
105108

106109
pow pow.PoW
107110
}
@@ -516,6 +519,7 @@ func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
516519

517520
func (bc *ChainManager) Stop() {
518521
close(bc.quit)
522+
atomic.StoreInt32(&bc.procInterrupt, 1)
519523

520524
bc.wg.Wait()
521525

@@ -569,6 +573,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
569573

570574
txcount := 0
571575
for i, block := range chain {
576+
if atomic.LoadInt32(&self.procInterrupt) == 1 {
577+
glog.V(logger.Debug).Infoln("Premature abort during chain processing")
578+
break
579+
}
580+
572581
bstart := time.Now()
573582
// Wait for block i's nonce to be verified before processing
574583
// its state transition.

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ func (self *Ethereum) AddPeer(nodeURL string) error {
527527

528528
func (s *Ethereum) Stop() {
529529
s.net.Stop()
530-
s.protocolManager.Stop()
531530
s.chainManager.Stop()
531+
s.protocolManager.Stop()
532532
s.txPool.Stop()
533533
s.eventMux.Stop()
534534
if s.whisper != nil {

0 commit comments

Comments
 (0)