Skip to content

Commit

Permalink
Merge pull request #267 from OffchainLabs/merge-v.1.12.1-fastcache-fi…
Browse files Browse the repository at this point in the history
…x-update

fastcache fix update for v.1.12.1
  • Loading branch information
Tristan-Wilson authored Nov 1, 2023
2 parents 93b7de9 + 614c728 commit 4b27832
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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

0 comments on commit 4b27832

Please sign in to comment.