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

fastcache fix update for v.1.12.1 #267

Merged
merged 8 commits into from
Nov 1, 2023
2 changes: 2 additions & 0 deletions eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (eth *Ethereum) StateAtBlock(ctx context.Context, block *types.Block, reexe
// Create an ephemeral trie.Database for isolating the live one. Otherwise
// the internal junks created by tracing will be persisted into the disk.
database = state.NewDatabaseWithConfig(eth.chainDb, &trie.Config{Cache: 16})
defer database.TrieDB().Close()
if statedb, err = state.New(block.Root(), database, nil); err == nil {
log.Info("Found disk backend for state trie", "root", block.Root(), "number", block.Number())
return statedb, noopReleaser, nil
Expand All @@ -100,6 +101,7 @@ func (eth *Ethereum) StateAtBlock(ctx context.Context, block *types.Block, reexe
// Create an ephemeral trie.Database for isolating the live one. Otherwise
// the internal junks created by tracing will be persisted into the disk.
database = state.NewDatabaseWithConfig(eth.chainDb, &trie.Config{Cache: 16})
defer database.TrieDB().Close()

// If we didn't check the live database, do check state over ephemeral database,
// otherwise we would rewind past a persisted block (specific corner case is
Expand Down
8 changes: 7 additions & 1 deletion trie/triedb/hashdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,13 @@ func (db *Database) Size() common.StorageSize {
}

// Close closes the trie database and releases all held resources.
func (db *Database) Close() error { return nil }
func (db *Database) Close() error {
if db.cleans != nil {
// Reset cleans cache to return mmaped memory chunks to fastcache pool
db.cleans.Reset()
}
return nil
}

// Scheme returns the node scheme used in the database.
func (db *Database) Scheme() string {
Expand Down
7 changes: 7 additions & 0 deletions trie/triedb/pathdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ func (db *Database) Close() error {
db.lock.Lock()
defer db.lock.Unlock()

dl := db.tree.bottom()
if dl.cleans != nil {
// Reset cleans cache to return mmaped memory chunks to fastcache pool
// All diskLayers share the same cleans cache
dl.cleans.Reset()
}

db.readOnly = true
if db.freezer == nil {
return nil
Expand Down