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

Method sync

sqlchain/chain.go:717–750  ·  view source on GitHub ↗

sync synchronizes blocks and queries from the other peers.

()

Source from the content-addressed store, hash-verified

715
716// sync synchronizes blocks and queries from the other peers.
717func (c *Chain) sync() (err error) {
718 le := c.logEntry()
719 le.Debug("synchronizing chain state")
720 defer func() {
721 c.stat()
722 c.pruneBlockCache()
723 c.ai.advance(c.rt.getMinValidHeight())
724 }()
725 for {
726 now := c.rt.now()
727 height := c.rt.getHeightFromTime(now)
728 if now.Before(c.rt.chainInitTime) {
729 le.Debug("now time is before genesis time, waiting for genesis")
730 return
731 }
732 if c.rt.getNextTurn() > height {
733 break
734 }
735 for c.rt.getNextTurn() <= height {
736 if err = c.syncHead(); err != nil {
737 if err != ErrInitiating {
738 le.WithError(err).Errorf("failed to sync block at height %d", height)
739 return
740 }
741 // Skip sync and reset error
742 c.rt.SetNextTurn(height + 1)
743 err = nil
744 } else {
745 c.rt.IncNextTurn()
746 }
747 }
748 }
749 return
750}
751
752func (c *Chain) processBlocks(ctx context.Context) {
753 var (

Callers 1

StartMethod · 0.95

Calls 14

logEntryMethod · 0.95
statMethod · 0.95
pruneBlockCacheMethod · 0.95
syncHeadMethod · 0.95
DebugMethod · 0.80
advanceMethod · 0.80
getMinValidHeightMethod · 0.80
getHeightFromTimeMethod · 0.80
getNextTurnMethod · 0.80
ErrorfMethod · 0.80
WithErrorMethod · 0.80
SetNextTurnMethod · 0.80

Tested by

no test coverage detected