mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
triedb/pathdb: polish
This commit is contained in:
parent
a22c7b5745
commit
f0b38d6fae
2 changed files with 12 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue