runCurrentTurn does the check and runs block producing if its my turn.
(now time.Time, d time.Duration)
| 653 | |
| 654 | // runCurrentTurn does the check and runs block producing if its my turn. |
| 655 | func (c *Chain) runCurrentTurn(now time.Time, d time.Duration) { |
| 656 | elapsed := -d |
| 657 | h := c.rt.getNextTurn() |
| 658 | le := c.logEntryWithHeadState().WithFields(log.Fields{ |
| 659 | "using_timestamp": now.Format(time.RFC3339Nano), |
| 660 | "elapsed_seconds": elapsed.Seconds(), |
| 661 | }) |
| 662 | |
| 663 | defer func() { |
| 664 | c.stat() |
| 665 | c.pruneBlockCache() |
| 666 | c.rt.IncNextTurn() |
| 667 | c.ai.advance(c.rt.getMinValidHeight()) |
| 668 | // Info the block processing goroutine that the chain height has grown, so please return |
| 669 | // any stashed blocks for further check. |
| 670 | select { |
| 671 | case c.heights <- h: |
| 672 | case <-c.rt.ctx.Done(): |
| 673 | le.Debug("abort publishing height") |
| 674 | } |
| 675 | }() |
| 676 | |
| 677 | le.Debug("run current turn") |
| 678 | if c.rt.getHead().Height < c.rt.getNextTurn()-1 { |
| 679 | le.Debug("a block will be skipped") |
| 680 | } |
| 681 | if !c.rt.isMyTurn() { |
| 682 | return |
| 683 | } |
| 684 | if elapsed+c.rt.tick > c.rt.period { |
| 685 | le.Warn("too much time elapsed in the new period, skip this block") |
| 686 | return |
| 687 | } |
| 688 | if err := c.produceBlock(now); err != nil { |
| 689 | le.WithError(err).Error("failed to produce block") |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | // mainCycle runs main cycle of the sql-chain. |
| 694 | func (c *Chain) mainCycle(ctx context.Context) { |
no test coverage detected