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

Method syncCurrentHead

blockproducer/chain.go:645–677  ·  view source on GitHub ↗

syncCurrentHead synchronizes a block at the current height of the local peer from the known remote peers. The return value `ok` indicates that there're at least `requiredReachable-1` replies from these gossip calls.

(ctx context.Context, requiredReachable uint32)

Source from the content-addressed store, hash-verified

643// remote peers. The return value `ok` indicates that there're at least `requiredReachable-1`
644// replies from these gossip calls.
645func (c *Chain) syncCurrentHead(ctx context.Context, requiredReachable uint32) (ok bool) {
646 var currentHeight = c.getNextHeight() - 1
647 if c.head().height >= currentHeight {
648 ok = true
649 return
650 }
651
652 // Initiate blocking gossip calls to fetch block of the current height,
653 // with timeout of one tick.
654 var (
655 unreachable = c.blockingFetchBlock(ctx, currentHeight)
656 serversNum = c.getLocalBPInfo().total
657 )
658
659 switch c.mode {
660 case BPMode:
661 ok = unreachable+requiredReachable <= serversNum
662 case APINodeMode:
663 ok = unreachable < serversNum
664 default:
665 ok = false
666 log.Fatalf("unknown run mode: %v", c.mode)
667 }
668
669 if !ok {
670 log.WithFields(log.Fields{
671 "peer": c.getLocalBPInfo(),
672 "sync_head_height": currentHeight,
673 "unreachable_count": unreachable,
674 }).Warn("one or more block producers are currently unreachable")
675 }
676 return
677}
678
679func (c *Chain) storeTx(tx pi.Transaction) (err error) {
680 var k = tx.Hash()

Callers 1

Calls 7

getNextHeightMethod · 0.95
headMethod · 0.95
blockingFetchBlockMethod · 0.95
getLocalBPInfoMethod · 0.95
FatalfFunction · 0.92
WithFieldsFunction · 0.92
WarnMethod · 0.80

Tested by

no test coverage detected