mainCycle runs main cycle of the sql-chain.
(ctx context.Context)
| 692 | |
| 693 | // mainCycle runs main cycle of the sql-chain. |
| 694 | func (c *Chain) mainCycle(ctx context.Context) { |
| 695 | for { |
| 696 | select { |
| 697 | case <-ctx.Done(): |
| 698 | c.logEntry().WithError(ctx.Err()).Info("abort main cycle") |
| 699 | return |
| 700 | default: |
| 701 | if err := c.syncHead(); err != nil { |
| 702 | if err != ErrInitiating { |
| 703 | c.logEntry().WithError(err).Error("failed to sync head") |
| 704 | continue |
| 705 | } |
| 706 | } |
| 707 | if t, d := c.rt.nextTick(); d > 0 { |
| 708 | time.Sleep(d) |
| 709 | } else { |
| 710 | c.runCurrentTurn(t, d) |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | // sync synchronizes blocks and queries from the other peers. |
| 717 | func (c *Chain) sync() (err error) { |