|
|
|
@ -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) |
|
|
|
|