diff --git a/triedb/pathdb/history_indexer.go b/triedb/pathdb/history_indexer.go index ff07f1e438..054d43e946 100644 --- a/triedb/pathdb/history_indexer.go +++ b/triedb/pathdb/history_indexer.go @@ -428,6 +428,7 @@ func (i *indexIniter) run(lastID uint64) { // Adjust the indexing target and relaunch the process lastID = newLastID signal.result <- nil + done, interrupt = make(chan struct{}), new(atomic.Int32) go i.index(done, interrupt, lastID) log.Debug("Shortened state history range", "last", lastID) diff --git a/triedb/pathdb/history_indexer_test.go b/triedb/pathdb/history_indexer_test.go index 2e237a6b07..abfcafc945 100644 --- a/triedb/pathdb/history_indexer_test.go +++ b/triedb/pathdb/history_indexer_test.go @@ -21,29 +21,29 @@ import ( "time" "github.com/ethereum/go-ethereum/core/rawdb" - "github.com/ethereum/go-ethereum/ethdb" ) // TestHistoryIndexerShortenDeadlock tests that a call to shorten does not // deadlock when the indexer is active. This specifically targets the case where // signal.result must be sent to unblock the caller. func TestHistoryIndexerShortenDeadlock(t *testing.T) { + //log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) db := rawdb.NewMemoryDatabase() freezer, _ := rawdb.NewStateFreezer(t.TempDir(), false, false) - histories := makeHistories(1000) - - // Assume we only have 100 histories indexed - for i, h := range histories[:100] { - accountData, storageData, accountIndex, storageIndex := h.encode() - rawdb.WriteStateHistory(freezer.(ethdb.AncientWriter), uint64(i+1), h.meta.encode(), accountIndex, storageIndex, accountData, storageData) - } - indexer := newHistoryIndexer(db, freezer, uint64(len(histories))) - defer indexer.close() defer freezer.Close() + histories := makeHistories(100) + for i, h := range histories { + accountData, storageData, accountIndex, storageIndex := h.encode() + rawdb.WriteStateHistory(freezer, uint64(i+1), h.meta.encode(), accountIndex, storageIndex, accountData, storageData) + } + // As a workaround, assign a future block to keep the initer running indefinitely + indexer := newHistoryIndexer(db, freezer, 200) + defer indexer.close() + done := make(chan error, 1) go func() { - done <- indexer.shorten(uint64(len(histories))) + done <- indexer.shorten(200) }() select {