Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add chain tip info to chainsync input status callback #66

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions input/chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ type ChainSync struct {
}

type ChainSyncStatus struct {
SlotNumber uint64
BlockNumber uint64
BlockHash string
SlotNumber uint64
BlockNumber uint64
BlockHash string
TipSlotNumber uint64
TipBlockHash string
}

type StatusUpdateFunc func(ChainSyncStatus)
Expand Down Expand Up @@ -187,7 +189,7 @@ func (c *ChainSync) handleRollForward(blockType uint, blockData interface{}, tip
case ledger.Block:
evt := event.New("chainsync.block", time.Now(), NewBlockEvent(v, c.includeCbor))
c.eventChan <- evt
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash())
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash(), tip.Point.Slot, hex.EncodeToString(tip.Point.Hash))
case ledger.BlockHeader:
blockSlot := v.SlotNumber()
blockHash, _ := hex.DecodeString(v.Hash())
Expand All @@ -201,15 +203,17 @@ func (c *ChainSync) handleRollForward(blockType uint, blockData interface{}, tip
txEvt := event.New("chainsync.transaction", time.Now(), NewTransactionEvent(block, transaction, c.includeCbor))
c.eventChan <- txEvt
}
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash())
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash(), tip.Point.Slot, hex.EncodeToString(tip.Point.Hash))
}
return nil
}

func (c *ChainSync) updateStatus(slotNumber uint64, blockNumber uint64, blockHash string) {
func (c *ChainSync) updateStatus(slotNumber uint64, blockNumber uint64, blockHash string, tipSlotNumber uint64, tipBlockHash string) {
c.status.SlotNumber = slotNumber
c.status.BlockNumber = blockNumber
c.status.BlockHash = blockHash
c.status.TipSlotNumber = tipSlotNumber
c.status.TipBlockHash = tipBlockHash
if c.statusUpdateFunc != nil {
c.statusUpdateFunc(*(c.status))
}
Expand Down
Loading