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

core, trie: flush preimages to db on database close #25533

Merged
merged 3 commits into from Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/blockchain.go
Expand Up @@ -899,6 +899,10 @@ func (bc *BlockChain) Stop() {
triedb := bc.stateCache.TrieDB()
triedb.SaveCache(bc.cacheConfig.TrieCleanJournal)
}
// Flush the preimages to disk
if err := bc.stateCache.TrieDB().CommitPreimages(); err != nil {
log.Error("Error closing Trie database", "err", err)
}
log.Info("Blockchain stopped")
}

Expand Down
12 changes: 12 additions & 0 deletions trie/database.go
Expand Up @@ -852,3 +852,15 @@ func (db *Database) SaveCachePeriodically(dir string, interval time.Duration, st
}
}
}

// CommitPreimages will flush the dangling preimages to disk. It is meant to be called when closing
// the blockchain object, so that all preimages are persisted to the db.
func (db *Database) CommitPreimages() error {
db.lock.Lock()
defer db.lock.Unlock()

if db.preimages != nil {
return db.preimages.commit(true)
}
return nil
}