core: changed interrupt strategy
Removed chain manager's select/channel approach when checking for interrupts. Now using an atomic int32 instead which checked for every block processed.
This commit is contained in:
parent
90c4493a10
commit
645dfd9693
@ -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,8 @@ type ChainManager struct {
|
|||||||
futureBlocks *BlockCache
|
futureBlocks *BlockCache
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
procInterupt chan struct{} // interupt signaler for block processing
|
// procInterrupt must be atomically called
|
||||||
|
procInterrupt int32 // interrupt signaler for block processing
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
|
||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
@ -114,7 +116,6 @@ func NewChainManager(genesis *types.Block, blockDb, stateDb common.Database, pow
|
|||||||
genesisBlock: GenesisBlock(42, stateDb),
|
genesisBlock: GenesisBlock(42, stateDb),
|
||||||
eventMux: mux,
|
eventMux: mux,
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
procInterupt: make(chan struct{}),
|
|
||||||
cache: NewBlockCache(blockCacheLimit),
|
cache: NewBlockCache(blockCacheLimit),
|
||||||
pow: pow,
|
pow: pow,
|
||||||
}
|
}
|
||||||
@ -518,7 +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)
|
||||||
close(bc.procInterupt)
|
atomic.StoreInt32(&bc.procInterrupt, 1)
|
||||||
|
|
||||||
bc.wg.Wait()
|
bc.wg.Wait()
|
||||||
|
|
||||||
@ -571,13 +572,12 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
|||||||
defer close(nonceQuit)
|
defer close(nonceQuit)
|
||||||
|
|
||||||
txcount := 0
|
txcount := 0
|
||||||
done:
|
|
||||||
for i, block := range chain {
|
for i, block := range chain {
|
||||||
select {
|
if atomic.LoadInt32(&self.procInterrupt) == 1 {
|
||||||
case <-self.procInterupt:
|
|
||||||
glog.V(logger.Debug).Infoln("Premature abort during chain processing")
|
glog.V(logger.Debug).Infoln("Premature abort during chain processing")
|
||||||
break done
|
break
|
||||||
default:
|
}
|
||||||
|
|
||||||
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.
|
||||||
@ -691,7 +691,6 @@ done:
|
|||||||
stats.processed++
|
stats.processed++
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (stats.queued > 0 || stats.processed > 0 || stats.ignored > 0) && bool(glog.V(logger.Info)) {
|
if (stats.queued > 0 || stats.processed > 0 || stats.ignored > 0) && bool(glog.V(logger.Info)) {
|
||||||
tend := time.Since(tstart)
|
tend := time.Since(tstart)
|
||||||
|
Loading…
Reference in New Issue
Block a user