MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / mainCycle

Method mainCycle

blockproducer/chain.go:580–617  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

578}
579
580func (c *Chain) mainCycle(ctx context.Context) {
581 var timer = time.NewTimer(0)
582 defer func() {
583 if !timer.Stop() {
584 <-timer.C
585 }
586 }()
587 for {
588 select {
589 case <-timer.C:
590 // Try to fetch block at height `nextHeight-1` until enough peers are reachable
591 if err := c.blockingSyncCurrentHead(ctx, c.getRequiredConfirms()); err != nil {
592 log.WithError(err).Info("abort main cycle")
593 timer.Reset(0)
594 return
595 }
596
597 var t, d = c.nextTick()
598 if d <= 0 {
599 // Try to produce block at `nextHeight` if it's my turn, and increase height by 1
600 c.advanceNextHeight(t, d)
601 } else {
602 log.WithFields(log.Fields{
603 "peer": c.getLocalBPInfo(),
604 "next_height": c.getNextHeight(),
605 "head_height": c.head().height,
606 "head_block": c.head().hash.Short(4),
607 "now_time": t.Format(time.RFC3339Nano),
608 "duration": d,
609 }).Debug("main cycle")
610 }
611 timer.Reset(d)
612 case <-ctx.Done():
613 log.WithError(ctx.Err()).Info("abort main cycle")
614 return
615 }
616 }
617}
618
619func (c *Chain) blockingSyncCurrentHead(ctx context.Context, requiredReachable uint32) (err error) {
620 var (

Callers

nothing calls this directly

Calls 15

getRequiredConfirmsMethod · 0.95
nextTickMethod · 0.95
advanceNextHeightMethod · 0.95
getLocalBPInfoMethod · 0.95
getNextHeightMethod · 0.95
headMethod · 0.95
WithErrorFunction · 0.92
WithFieldsFunction · 0.92
InfoMethod · 0.80
DebugMethod · 0.80
ShortMethod · 0.80

Tested by

no test coverage detected