wait handles mined blocks.
()
| 310 | |
| 311 | // wait handles mined blocks. |
| 312 | func (e *engine) wait() { |
| 313 | for { |
| 314 | select { |
| 315 | case result := <-e.recv: |
| 316 | atomic.AddInt32(&e.atWork, -1) |
| 317 | |
| 318 | if result == nil { |
| 319 | continue |
| 320 | } |
| 321 | block := result.Block |
| 322 | |
| 323 | if block.NumberU64() <= e.lastBlock { |
| 324 | // ignore the same height new block or old block |
| 325 | log.Warn("detected duplicate blocks with same block number", "number", block.NumberU64()) |
| 326 | continue |
| 327 | } |
| 328 | e.lastBlock = block.NumberU64() |
| 329 | |
| 330 | // broadcast the block and announce chain insertion event |
| 331 | _ = e.mux.Post(core.NewMinedBlockEvent{Block: block}) |
| 332 | |
| 333 | case <-e.quitCh: |
| 334 | log.Info("goroutine wait() quit") |
| 335 | return |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | // push sends a new work task to currently live miner workers. |
| 341 | func (e *engine) push(work *Work) { |