chain_manager.go 17 KB

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