From ecb67d52a6f65b8fd6c59d84d27f5c2b22e095da Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Sat, 2 Sep 2023 09:58:47 -0500 Subject: [PATCH] feat: add chainsync status field for whether chain tip has been reached --- input/chainsync/chainsync.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/input/chainsync/chainsync.go b/input/chainsync/chainsync.go index fa5e253..efdf050 100644 --- a/input/chainsync/chainsync.go +++ b/input/chainsync/chainsync.go @@ -53,6 +53,7 @@ type ChainSyncStatus struct { BlockHash string TipSlotNumber uint64 TipBlockHash string + TipReached bool } type StatusUpdateFunc func(ChainSyncStatus) @@ -246,6 +247,16 @@ func (c *ChainSync) handleBlockFetchBlock(block ledger.Block) error { } func (c *ChainSync) updateStatus(slotNumber uint64, blockNumber uint64, blockHash string, tipSlotNumber uint64, tipBlockHash string) { + // Determine if we've reached the chain tip + if !c.status.TipReached { + // Make sure we're past the end slot in any bulk range, since we don't update the tip during bulk sync + if slotNumber > c.bulkRangeEnd.Slot { + // Make sure our current slot is equal/higher than our last known tip slot + if c.status.SlotNumber > 0 && slotNumber >= c.status.TipSlotNumber { + c.status.TipReached = true + } + } + } c.status.SlotNumber = slotNumber c.status.BlockNumber = blockNumber c.status.BlockHash = blockHash