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

Method runCurrentTurn

sqlchain/chain.go:655–691  ·  view source on GitHub ↗

runCurrentTurn does the check and runs block producing if its my turn.

(now time.Time, d time.Duration)

Source from the content-addressed store, hash-verified

653
654// runCurrentTurn does the check and runs block producing if its my turn.
655func (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.
694func (c *Chain) mainCycle(ctx context.Context) {

Callers 1

mainCycleMethod · 0.95

Calls 15

logEntryWithHeadStateMethod · 0.95
statMethod · 0.95
pruneBlockCacheMethod · 0.95
produceBlockMethod · 0.95
getNextTurnMethod · 0.80
WithFieldsMethod · 0.80
IncNextTurnMethod · 0.80
advanceMethod · 0.80
getMinValidHeightMethod · 0.80
DebugMethod · 0.80
WarnMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected