Skip to content

Commit

Permalink
Merge pull request #71 from blinklabs-io/feat/chainsync-status-tip-re…
Browse files Browse the repository at this point in the history
…ached

feat: add chainsync status field for whether chain tip has been reached
  • Loading branch information
agaffney authored Sep 2, 2023
2 parents c1f9e2c + ecb67d5 commit 73f1388
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions input/chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type ChainSyncStatus struct {
BlockHash string
TipSlotNumber uint64
TipBlockHash string
TipReached bool
}

type StatusUpdateFunc func(ChainSyncStatus)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73f1388

Please sign in to comment.