Skip to content
Open
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
47 changes: 44 additions & 3 deletions triedb/pathdb/history_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,47 @@ func (i *indexIniter) remain() uint64 {
}
}

// getHistoryRangeInfo returns a formatted string describing the available history range.
func (i *indexIniter) getHistoryRangeInfo(lastID uint64) []interface{} {
// Get the number of available history ID
tail, err := i.freezer.Tail()
if err != nil {
return []interface{}{"last", lastID, "error", err}
}
head, err := i.freezer.Ancients()
if err != nil {
return []interface{}{"last", lastID, "error", err}
}

firstID := tail + 1
lastAvailID := head - 1
count := uint64(0)
if lastAvailID >= firstID {
count = lastAvailID - firstID + 1
}

// Get the actual block numbers
if count == 0 {
return []interface{}{"last", lastID, "count", 0}
}

firstBlock, lastBlock := uint64(0), uint64(0)
if i.typ == typeStateHistory {
if fh, err := readStateHistory(i.freezer, firstID); err == nil {
firstBlock = fh.meta.block
}
if lh, err := readStateHistory(i.freezer, lastID); err == nil {
lastBlock = lh.meta.block
}
}

return []interface{}{
"last", lastID,
"count", count,
"blocks", fmt.Sprintf("%d-%d", firstBlock, lastBlock),
}
}

func (i *indexIniter) run(lastID uint64) {
defer i.wg.Done()

Expand Down Expand Up @@ -434,7 +475,7 @@ func (i *indexIniter) run(lastID uint64) {
}
close(i.done)
signal.result <- nil
i.log.Info("Histories have been fully indexed", "last", lastID-1)
i.log.Info("State histories have been fully indexed", i.getHistoryRangeInfo(lastID-1)...)
return
}
// Adjust the indexing target and relaunch the process
Expand All @@ -448,7 +489,7 @@ func (i *indexIniter) run(lastID uint64) {
case <-done:
if checkDone() {
close(i.done)
i.log.Info("Histories have been fully indexed", "last", lastID)
i.log.Info("State histories have been fully indexed", i.getHistoryRangeInfo(lastID)...)
return
}
// Relaunch the background runner if some tasks are left
Expand Down Expand Up @@ -519,7 +560,7 @@ func (i *indexIniter) index(done chan struct{}, interrupt *atomic.Int32, lastID
storeIndexMetadata(i.disk, i.typ, 0)
i.log.Info("Initialized history indexing flag")
} else {
i.log.Debug("History is fully indexed", "last", lastID)
i.log.Debug("History is fully indexed", i.getHistoryRangeInfo(lastID)...)
}
return
}
Expand Down