From 907ad70623e1cb2c387bf2642170f42ac9b6f4af Mon Sep 17 00:00:00 2001 From: allen Date: Thu, 2 Oct 2025 10:51:12 -0400 Subject: [PATCH 1/3] triedb/pathdb: improve state history indexing completion log --- triedb/pathdb/history_indexer.go | 45 ++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/triedb/pathdb/history_indexer.go b/triedb/pathdb/history_indexer.go index d6185859291..1ba65fd20c9 100644 --- a/triedb/pathdb/history_indexer.go +++ b/triedb/pathdb/history_indexer.go @@ -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() @@ -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 @@ -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 From 0a290f4509300296916ae4286b0b46341d5785c1 Mon Sep 17 00:00:00 2001 From: allen Date: Thu, 2 Oct 2025 15:15:55 -0400 Subject: [PATCH 2/3] fix --- triedb/pathdb/history_indexer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/triedb/pathdb/history_indexer.go b/triedb/pathdb/history_indexer.go index 1ba65fd20c9..2fe851f71af 100644 --- a/triedb/pathdb/history_indexer.go +++ b/triedb/pathdb/history_indexer.go @@ -560,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 } From 6c49d6aeded8245d84c244b28720fd727acb9222 Mon Sep 17 00:00:00 2001 From: allen Date: Thu, 2 Oct 2025 20:45:33 -0400 Subject: [PATCH 3/3] fix --- triedb/pathdb/history_indexer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/triedb/pathdb/history_indexer.go b/triedb/pathdb/history_indexer.go index 2fe851f71af..03bd68b5bad 100644 --- a/triedb/pathdb/history_indexer.go +++ b/triedb/pathdb/history_indexer.go @@ -560,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", i.getHistoryRangeInfo(lastID)) + i.log.Debug("History is fully indexed", i.getHistoryRangeInfo(lastID)...) } return }