Skip to content

Commit 73f1388

Browse files
authored
Merge pull request #71 from blinklabs-io/feat/chainsync-status-tip-reached
feat: add chainsync status field for whether chain tip has been reached
2 parents c1f9e2c + ecb67d5 commit 73f1388

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

input/chainsync/chainsync.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type ChainSyncStatus struct {
5353
BlockHash string
5454
TipSlotNumber uint64
5555
TipBlockHash string
56+
TipReached bool
5657
}
5758

5859
type StatusUpdateFunc func(ChainSyncStatus)
@@ -246,6 +247,16 @@ func (c *ChainSync) handleBlockFetchBlock(block ledger.Block) error {
246247
}
247248

248249
func (c *ChainSync) updateStatus(slotNumber uint64, blockNumber uint64, blockHash string, tipSlotNumber uint64, tipBlockHash string) {
250+
// Determine if we've reached the chain tip
251+
if !c.status.TipReached {
252+
// Make sure we're past the end slot in any bulk range, since we don't update the tip during bulk sync
253+
if slotNumber > c.bulkRangeEnd.Slot {
254+
// Make sure our current slot is equal/higher than our last known tip slot
255+
if c.status.SlotNumber > 0 && slotNumber >= c.status.TipSlotNumber {
256+
c.status.TipReached = true
257+
}
258+
}
259+
}
249260
c.status.SlotNumber = slotNumber
250261
c.status.BlockNumber = blockNumber
251262
c.status.BlockHash = blockHash

0 commit comments

Comments
 (0)