chain_manager.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. package core
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "math/big"
  7. "sync"
  8. "time"
  9. "github.com/ethereum/go-ethereum/common"
  10. "github.com/ethereum/go-ethereum/core/state"
  11. "github.com/ethereum/go-ethereum/core/types"
  12. "github.com/ethereum/go-ethereum/event"
  13. "github.com/ethereum/go-ethereum/logger"
  14. "github.com/ethereum/go-ethereum/logger/glog"
  15. "github.com/ethereum/go-ethereum/params"
  16. "github.com/ethereum/go-ethereum/rlp"
  17. )
  18. var (
  19. chainlogger = logger.NewLogger("CHAIN")
  20. jsonlogger = logger.NewJsonLogger()
  21. blockHashPre = []byte("block-hash-")
  22. blockNumPre = []byte("block-num-")
  23. )
  24. const (
  25. blockCacheLimit = 10000
  26. maxFutureBlocks = 256
  27. )
  28. func CalcDifficulty(block, parent *types.Header) *big.Int {
  29. diff := new(big.Int)
  30. adjust := new(big.Int).Div(parent.Difficulty, params.DifficultyBoundDivisor)
  31. if big.NewInt(int64(block.Time)-int64(parent.Time)).Cmp(params.DurationLimit) < 0 {
  32. diff.Add(parent.Difficulty, adjust)
  33. } else {
  34. diff.Sub(parent.Difficulty, adjust)
  35. }
  36. if diff.Cmp(params.MinimumDifficulty) < 0 {
  37. return params.MinimumDifficulty
  38. }
  39. return diff
  40. }
  41. func CalculateTD(block, parent *types.Block) *big.Int {
  42. td := new(big.Int).Add(parent.Td, block.Header().Difficulty)
  43. return td
  44. }
  45. func CalcGasLimit(parent *types.Block) *big.Int {
  46. // ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024
  47. previous := new(big.Int).Mul(big.NewInt(1024-1), parent.GasLimit())
  48. current := new(big.Rat).Mul(new(big.Rat).SetInt(parent.GasUsed()), big.NewRat(6, 5))
  49. curInt := new(big.Int).Div(current.Num(), current.Denom())
  50. result := new(big.Int).Add(previous, curInt)
  51. result.Div(result, big.NewInt(1024))
  52. return common.BigMax(params.GenesisGasLimit, result)
  53. }
  54. type ChainManager struct {
  55. //eth EthManager
  56. blockDb common.Database
  57. stateDb common.Database
  58. processor types.BlockProcessor
  59. eventMux *event.TypeMux
  60. genesisBlock *types.Block
  61. // Last known total difficulty
  62. mu sync.RWMutex
  63. tsmu sync.RWMutex
  64. td *big.Int
  65. currentBlock *types.Block
  66. lastBlockHash common.Hash
  67. currentGasLimit *big.Int
  68. transState *state.StateDB
  69. txState *state.ManagedState
  70. cache *BlockCache
  71. futureBlocks *BlockCache
  72. quit chan struct{}
  73. }
  74. func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *ChainManager {
  75. bc := &ChainManager{
  76. blockDb: blockDb,
  77. stateDb: stateDb,
  78. genesisBlock: GenesisBlock(stateDb),
  79. eventMux: mux,
  80. quit: make(chan struct{}),
  81. cache: NewBlockCache(blockCacheLimit),
  82. currentGasLimit: new(big.Int),
  83. }
  84. bc.setLastBlock()
  85. // Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
  86. for _, hash := range badHashes {
  87. if block := bc.GetBlock(hash); block != nil {
  88. glog.V(logger.Error).Infof("Found bad hash. Reorganising chain to state %x\n", block.ParentHash().Bytes()[:4])
  89. block = bc.GetBlock(block.ParentHash())
  90. if block == nil {
  91. glog.Fatal("Unable to complete. Parent block not found. Corrupted DB?")
  92. }
  93. bc.SetHead(block)
  94. glog.V(logger.Error).Infoln("Chain reorg was successfull. Resuming normal operation")
  95. }
  96. }
  97. bc.transState = bc.State().Copy()
  98. // Take ownership of this particular state
  99. bc.txState = state.ManageState(bc.State().Copy())
  100. bc.futureBlocks = NewBlockCache(maxFutureBlocks)
  101. bc.makeCache()
  102. go bc.update()
  103. return bc
  104. }
  105. func (bc *ChainManager) SetHead(head *types.Block) {
  106. bc.mu.Lock()
  107. defer bc.mu.Unlock()
  108. for block := bc.currentBlock; block != nil && block.Hash() != head.Hash(); block = bc.GetBlock(block.Header().ParentHash) {
  109. bc.removeBlock(block)
  110. }
  111. bc.cache = NewBlockCache(blockCacheLimit)
  112. bc.currentBlock = head
  113. bc.makeCache()
  114. statedb := state.New(head.Root(), bc.stateDb)
  115. bc.txState = state.ManageState(statedb)
  116. bc.transState = statedb.Copy()
  117. bc.setTotalDifficulty(head.Td)
  118. bc.insert(head)
  119. bc.setLastBlock()
  120. }
  121. func (self *ChainManager) Td() *big.Int {
  122. self.mu.RLock()
  123. defer self.mu.RUnlock()
  124. return self.td
  125. }
  126. func (self *ChainManager) GasLimit() *big.Int {
  127. return self.currentGasLimit
  128. }
  129. func (self *ChainManager) LastBlockHash() common.Hash {
  130. self.mu.RLock()
  131. defer self.mu.RUnlock()
  132. return self.lastBlockHash
  133. }
  134. func (self *ChainManager) CurrentBlock() *types.Block {
  135. self.mu.RLock()
  136. defer self.mu.RUnlock()
  137. return self.currentBlock
  138. }
  139. func (self *ChainManager) Status() (td *big.Int, currentBlock common.Hash, genesisBlock common.Hash) {
  140. self.mu.RLock()
  141. defer self.mu.RUnlock()
  142. return self.td, self.currentBlock.Hash(), self.genesisBlock.Hash()
  143. }
  144. func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
  145. self.processor = proc
  146. }
  147. func (self *ChainManager) State() *state.StateDB {
  148. return state.New(self.CurrentBlock().Root(), self.stateDb)
  149. }
  150. func (self *ChainManager) TransState() *state.StateDB {
  151. self.tsmu.RLock()
  152. defer self.tsmu.RUnlock()
  153. return self.transState
  154. }
  155. func (self *ChainManager) TxState() *state.ManagedState {
  156. self.tsmu.RLock()
  157. defer self.tsmu.RUnlock()
  158. return self.txState
  159. }
  160. func (self *ChainManager) setTxState(statedb *state.StateDB) {
  161. self.tsmu.Lock()
  162. defer self.tsmu.Unlock()
  163. self.txState = state.ManageState(statedb)
  164. }
  165. func (self *ChainManager) setTransState(statedb *state.StateDB) {
  166. self.transState = statedb
  167. }
  168. func (bc *ChainManager) setLastBlock() {
  169. data, _ := bc.blockDb.Get([]byte("LastBlock"))
  170. if len(data) != 0 {
  171. block := bc.GetBlock(common.BytesToHash(data))
  172. bc.currentBlock = block
  173. bc.lastBlockHash = block.Hash()
  174. // Set the last know difficulty (might be 0x0 as initial value, Genesis)
  175. bc.td = common.BigD(bc.blockDb.LastKnownTD())
  176. } else {
  177. bc.Reset()
  178. }
  179. if glog.V(logger.Info) {
  180. glog.Infof("Last block (#%v) %x TD=%v\n", bc.currentBlock.Number(), bc.currentBlock.Hash(), bc.td)
  181. }
  182. }
  183. func (bc *ChainManager) makeCache() {
  184. if bc.cache == nil {
  185. bc.cache = NewBlockCache(blockCacheLimit)
  186. }
  187. // load in last `blockCacheLimit` - 1 blocks. Last block is the current.
  188. ancestors := bc.GetAncestors(bc.currentBlock, blockCacheLimit-1)
  189. ancestors = append(ancestors, bc.currentBlock)
  190. for _, block := range ancestors {
  191. bc.cache.Push(block)
  192. }
  193. }
  194. // Block creation & chain handling
  195. func (bc *ChainManager) NewBlock(coinbase common.Address) *types.Block {
  196. bc.mu.RLock()
  197. defer bc.mu.RUnlock()
  198. var (
  199. root common.Hash
  200. parentHash common.Hash
  201. )
  202. if bc.currentBlock != nil {
  203. root = bc.currentBlock.Header().Root
  204. parentHash = bc.lastBlockHash
  205. }
  206. block := types.NewBlock(
  207. parentHash,
  208. coinbase,
  209. root,
  210. common.BigPow(2, 32),
  211. 0,
  212. nil)
  213. block.SetUncles(nil)
  214. block.SetTransactions(nil)
  215. block.SetReceipts(nil)
  216. parent := bc.currentBlock
  217. if parent != nil {
  218. header := block.Header()
  219. header.Difficulty = CalcDifficulty(block.Header(), parent.Header())
  220. header.Number = new(big.Int).Add(parent.Header().Number, common.Big1)
  221. header.GasLimit = CalcGasLimit(parent)
  222. }
  223. return block
  224. }
  225. func (bc *ChainManager) Reset() {
  226. bc.mu.Lock()
  227. defer bc.mu.Unlock()
  228. for block := bc.currentBlock; block != nil; block = bc.GetBlock(block.Header().ParentHash) {
  229. bc.removeBlock(block)
  230. }
  231. if bc.cache == nil {
  232. bc.cache = NewBlockCache(blockCacheLimit)
  233. }
  234. // Prepare the genesis block
  235. bc.write(bc.genesisBlock)
  236. bc.insert(bc.genesisBlock)
  237. bc.currentBlock = bc.genesisBlock
  238. bc.makeCache()
  239. bc.setTotalDifficulty(common.Big("0"))
  240. }
  241. func (bc *ChainManager) removeBlock(block *types.Block) {
  242. bc.blockDb.Delete(append(blockHashPre, block.Hash().Bytes()...))
  243. }
  244. func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
  245. bc.mu.Lock()
  246. defer bc.mu.Unlock()
  247. for block := bc.currentBlock; block != nil; block = bc.GetBlock(block.Header().ParentHash) {
  248. bc.removeBlock(block)
  249. }
  250. // Prepare the genesis block
  251. bc.genesisBlock = gb
  252. bc.write(bc.genesisBlock)
  253. bc.insert(bc.genesisBlock)
  254. bc.currentBlock = bc.genesisBlock
  255. bc.makeCache()
  256. }
  257. // Export writes the active chain to the given writer.
  258. func (self *ChainManager) Export(w io.Writer) error {
  259. self.mu.RLock()
  260. defer self.mu.RUnlock()
  261. glog.V(logger.Info).Infof("exporting %v blocks...\n", self.currentBlock.Header().Number)
  262. last := self.currentBlock.NumberU64()
  263. for nr := uint64(0); nr <= last; nr++ {
  264. block := self.GetBlockByNumber(nr)
  265. if block == nil {
  266. return fmt.Errorf("export failed on #%d: not found", nr)
  267. }
  268. if err := block.EncodeRLP(w); err != nil {
  269. return err
  270. }
  271. }
  272. return nil
  273. }
  274. func (bc *ChainManager) insert(block *types.Block) {
  275. key := append(blockNumPre, block.Number().Bytes()...)
  276. bc.blockDb.Put(key, block.Hash().Bytes())
  277. // Push block to cache
  278. bc.cache.Push(block)
  279. bc.blockDb.Put([]byte("LastBlock"), block.Hash().Bytes())
  280. bc.currentBlock = block
  281. bc.lastBlockHash = block.Hash()
  282. }
  283. func (bc *ChainManager) write(block *types.Block) {
  284. enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block))
  285. key := append(blockHashPre, block.Hash().Bytes()...)
  286. bc.blockDb.Put(key, enc)
  287. }
  288. // Accessors
  289. func (bc *ChainManager) Genesis() *types.Block {
  290. return bc.genesisBlock
  291. }
  292. // Block fetching methods
  293. func (bc *ChainManager) HasBlock(hash common.Hash) bool {
  294. data, _ := bc.blockDb.Get(append(blockHashPre, hash[:]...))
  295. return len(data) != 0
  296. }
  297. func (self *ChainManager) GetBlockHashesFromHash(hash common.Hash, max uint64) (chain []common.Hash) {
  298. block := self.GetBlock(hash)
  299. if block == nil {
  300. return
  301. }
  302. // XXX Could be optimised by using a different database which only holds hashes (i.e., linked list)
  303. for i := uint64(0); i < max; i++ {
  304. block = self.GetBlock(block.ParentHash())
  305. if block == nil {
  306. break
  307. }
  308. chain = append(chain, block.Hash())
  309. if block.Number().Cmp(common.Big0) <= 0 {
  310. break
  311. }
  312. }
  313. return
  314. }
  315. func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
  316. if block := self.cache.Get(hash); block != nil {
  317. return block
  318. }
  319. data, _ := self.blockDb.Get(append(blockHashPre, hash[:]...))
  320. if len(data) == 0 {
  321. return nil
  322. }
  323. var block types.StorageBlock
  324. if err := rlp.Decode(bytes.NewReader(data), &block); err != nil {
  325. glog.V(logger.Error).Infof("invalid block RLP for hash %x: %v", hash, err)
  326. return nil
  327. }
  328. return (*types.Block)(&block)
  329. }
  330. func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block {
  331. self.mu.RLock()
  332. defer self.mu.RUnlock()
  333. return self.getBlockByNumber(num)
  334. }
  335. // non blocking version
  336. func (self *ChainManager) getBlockByNumber(num uint64) *types.Block {
  337. key, _ := self.blockDb.Get(append(blockNumPre, big.NewInt(int64(num)).Bytes()...))
  338. if len(key) == 0 {
  339. return nil
  340. }
  341. return self.GetBlock(common.BytesToHash(key))
  342. }
  343. func (self *ChainManager) GetUnclesInChain(block *types.Block, length int) (uncles []*types.Header) {
  344. for i := 0; block != nil && i < length; i++ {
  345. uncles = append(uncles, block.Uncles()...)
  346. block = self.GetBlock(block.ParentHash())
  347. }
  348. return
  349. }
  350. func (self *ChainManager) GetAncestors(block *types.Block, length int) (blocks []*types.Block) {
  351. for i := 0; i < length; i++ {
  352. block = self.GetBlock(block.ParentHash())
  353. if block == nil {
  354. break
  355. }
  356. blocks = append(blocks, block)
  357. }
  358. return
  359. }
  360. func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
  361. bc.blockDb.Put([]byte("LTD"), td.Bytes())
  362. bc.td = td
  363. }
  364. func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) {
  365. parent := self.GetBlock(block.Header().ParentHash)
  366. if parent == nil {
  367. return nil, fmt.Errorf("Unable to calculate total diff without known parent %x", block.Header().ParentHash)
  368. }
  369. parentTd := parent.Td
  370. uncleDiff := new(big.Int)
  371. for _, uncle := range block.Uncles() {
  372. uncleDiff = uncleDiff.Add(uncleDiff, uncle.Difficulty)
  373. }
  374. td := new(big.Int)
  375. td = td.Add(parentTd, uncleDiff)
  376. td = td.Add(td, block.Header().Difficulty)
  377. return td, nil
  378. }
  379. func (bc *ChainManager) Stop() {
  380. close(bc.quit)
  381. }
  382. type queueEvent struct {
  383. queue []interface{}
  384. canonicalCount int
  385. sideCount int
  386. splitCount int
  387. }
  388. func (self *ChainManager) procFutureBlocks() {
  389. blocks := make([]*types.Block, len(self.futureBlocks.blocks))
  390. self.futureBlocks.Each(func(i int, block *types.Block) {
  391. blocks[i] = block
  392. })
  393. types.BlockBy(types.Number).Sort(blocks)
  394. self.InsertChain(blocks)
  395. }
  396. func (self *ChainManager) InsertChain(chain types.Blocks) error {
  397. // A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
  398. var (
  399. queue = make([]interface{}, len(chain))
  400. queueEvent = queueEvent{queue: queue}
  401. stats struct{ queued, processed int }
  402. tstart = time.Now()
  403. )
  404. for i, block := range chain {
  405. if block == nil {
  406. continue
  407. }
  408. // Call in to the block processor and check for errors. It's likely that if one block fails
  409. // all others will fail too (unless a known block is returned).
  410. logs, err := self.processor.Process(block)
  411. if err != nil {
  412. if IsKnownBlockErr(err) {
  413. continue
  414. }
  415. block.Td = new(big.Int)
  416. // Do not penelise on future block. We'll need a block queue eventually that will queue
  417. // future block for future use
  418. if err == BlockFutureErr {
  419. block.SetQueued(true)
  420. self.futureBlocks.Push(block)
  421. stats.queued++
  422. continue
  423. }
  424. if IsParentErr(err) && self.futureBlocks.Has(block.ParentHash()) {
  425. block.SetQueued(true)
  426. self.futureBlocks.Push(block)
  427. stats.queued++
  428. continue
  429. }
  430. h := block.Header()
  431. glog.V(logger.Error).Infof("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes())
  432. glog.V(logger.Error).Infoln(err)
  433. glog.V(logger.Debug).Infoln(block)
  434. return err
  435. }
  436. block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
  437. self.mu.Lock()
  438. {
  439. cblock := self.currentBlock
  440. // Write block to database. Eventually we'll have to improve on this and throw away blocks that are
  441. // not in the canonical chain.
  442. self.write(block)
  443. // Compare the TD of the last known block in the canonical chain to make sure it's greater.
  444. // At this point it's possible that a different chain (fork) becomes the new canonical chain.
  445. if block.Td.Cmp(self.td) > 0 {
  446. //if block.Header().Number.Cmp(new(big.Int).Add(cblock.Header().Number, common.Big1)) < 0 {
  447. if block.Number().Cmp(cblock.Number()) <= 0 {
  448. chash := cblock.Hash()
  449. hash := block.Hash()
  450. if glog.V(logger.Info) {
  451. glog.Infof("Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v\n", block.Header().Number, hash[:4], block.Td, cblock.Header().Number, chash[:4], self.td)
  452. }
  453. // during split we merge two different chains and create the new canonical chain
  454. self.merge(self.getBlockByNumber(block.NumberU64()), block)
  455. queue[i] = ChainSplitEvent{block, logs}
  456. queueEvent.splitCount++
  457. }
  458. self.setTotalDifficulty(block.Td)
  459. self.insert(block)
  460. jsonlogger.LogJson(&logger.EthChainNewHead{
  461. BlockHash: block.Hash().Hex(),
  462. BlockNumber: block.Number(),
  463. ChainHeadHash: cblock.Hash().Hex(),
  464. BlockPrevHash: block.ParentHash().Hex(),
  465. })
  466. self.setTransState(state.New(block.Root(), self.stateDb))
  467. self.txState.SetState(state.New(block.Root(), self.stateDb))
  468. queue[i] = ChainEvent{block, logs}
  469. queueEvent.canonicalCount++
  470. if glog.V(logger.Debug) {
  471. glog.Infof("inserted block #%d (%d TXs %d UNCs) (%x...)\n", block.Number(), len(block.Transactions()), len(block.Uncles()), block.Hash().Bytes()[0:4])
  472. }
  473. } else {
  474. queue[i] = ChainSideEvent{block, logs}
  475. queueEvent.sideCount++
  476. }
  477. }
  478. self.mu.Unlock()
  479. stats.processed++
  480. self.futureBlocks.Delete(block.Hash())
  481. }
  482. if (stats.queued > 0 || stats.processed > 0) && bool(glog.V(logger.Info)) {
  483. tend := time.Since(tstart)
  484. start, end := chain[0], chain[len(chain)-1]
  485. glog.Infof("imported %d block(s) %d queued in %v. #%v [%x / %x]\n", stats.processed, stats.queued, tend, end.Number(), start.Hash().Bytes()[:4], end.Hash().Bytes()[:4])
  486. }
  487. go self.eventMux.Post(queueEvent)
  488. return nil
  489. }
  490. // merge takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them
  491. // to be part of the new canonical chain.
  492. func (self *ChainManager) merge(oldBlock, newBlock *types.Block) {
  493. glog.V(logger.Debug).Infof("Applying diff to %x & %x\n", oldBlock.Hash().Bytes()[:4], newBlock.Hash().Bytes()[:4])
  494. var oldChain, newChain types.Blocks
  495. // First find the split (common ancestor) so we can perform an adequate merge
  496. for {
  497. oldBlock, newBlock = self.GetBlock(oldBlock.ParentHash()), self.GetBlock(newBlock.ParentHash())
  498. if oldBlock.Hash() == newBlock.Hash() {
  499. break
  500. }
  501. oldChain = append(oldChain, oldBlock)
  502. newChain = append(newChain, newBlock)
  503. }
  504. // insert blocks
  505. for _, block := range newChain {
  506. self.insert(block)
  507. }
  508. if glog.V(logger.Detail) {
  509. for i, oldBlock := range oldChain {
  510. glog.Infof("- %.10v = %x\n", oldBlock.Number(), oldBlock.Hash())
  511. glog.Infof("+ %.10v = %x\n", newChain[i].Number(), newChain[i].Hash())
  512. }
  513. }
  514. }
  515. func (self *ChainManager) update() {
  516. events := self.eventMux.Subscribe(queueEvent{})
  517. futureTimer := time.NewTicker(5 * time.Second)
  518. out:
  519. for {
  520. select {
  521. case ev := <-events.Chan():
  522. switch ev := ev.(type) {
  523. case queueEvent:
  524. for i, event := range ev.queue {
  525. switch event := event.(type) {
  526. case ChainEvent:
  527. // We need some control over the mining operation. Acquiring locks and waiting for the miner to create new block takes too long
  528. // and in most cases isn't even necessary.
  529. if i+1 == ev.canonicalCount {
  530. self.currentGasLimit = CalcGasLimit(event.Block)
  531. self.eventMux.Post(ChainHeadEvent{event.Block})
  532. }
  533. case ChainSplitEvent:
  534. // On chain splits we need to reset the transaction state. We can't be sure whether the actual
  535. // state of the accounts are still valid.
  536. if i == ev.splitCount {
  537. self.setTxState(state.New(event.Block.Root(), self.stateDb))
  538. }
  539. }
  540. self.eventMux.Post(event)
  541. }
  542. }
  543. case <-futureTimer.C:
  544. self.procFutureBlocks()
  545. case <-self.quit:
  546. break out
  547. }
  548. }
  549. }