Skip to content

Commit 1b196c7

Browse files
committed
feat: add chain tip info to chainsync input status callback
1 parent 7d28683 commit 1b196c7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

input/chainsync/chainsync.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ type ChainSync struct {
4444
}
4545

4646
type ChainSyncStatus struct {
47-
SlotNumber uint64
48-
BlockNumber uint64
49-
BlockHash string
47+
SlotNumber uint64
48+
BlockNumber uint64
49+
BlockHash string
50+
TipSlotNumber uint64
51+
TipBlockHash string
5052
}
5153

5254
type StatusUpdateFunc func(ChainSyncStatus)
@@ -187,7 +189,7 @@ func (c *ChainSync) handleRollForward(blockType uint, blockData interface{}, tip
187189
case ledger.Block:
188190
evt := event.New("chainsync.block", time.Now(), NewBlockEvent(v, c.includeCbor))
189191
c.eventChan <- evt
190-
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash())
192+
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash(), tip.Point.Slot, hex.EncodeToString(tip.Point.Hash))
191193
case ledger.BlockHeader:
192194
blockSlot := v.SlotNumber()
193195
blockHash, _ := hex.DecodeString(v.Hash())
@@ -201,15 +203,17 @@ func (c *ChainSync) handleRollForward(blockType uint, blockData interface{}, tip
201203
txEvt := event.New("chainsync.transaction", time.Now(), NewTransactionEvent(block, transaction, c.includeCbor))
202204
c.eventChan <- txEvt
203205
}
204-
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash())
206+
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash(), tip.Point.Slot, hex.EncodeToString(tip.Point.Hash))
205207
}
206208
return nil
207209
}
208210

209-
func (c *ChainSync) updateStatus(slotNumber uint64, blockNumber uint64, blockHash string) {
211+
func (c *ChainSync) updateStatus(slotNumber uint64, blockNumber uint64, blockHash string, tipSlotNumber uint64, tipBlockHash string) {
210212
c.status.SlotNumber = slotNumber
211213
c.status.BlockNumber = blockNumber
212214
c.status.BlockHash = blockHash
215+
c.status.TipSlotNumber = tipSlotNumber
216+
c.status.TipBlockHash = tipBlockHash
213217
if c.statusUpdateFunc != nil {
214218
c.statusUpdateFunc(*(c.status))
215219
}

0 commit comments

Comments
 (0)