trie: add getter for preimage store in trie.Database (#28155)

This commit is contained in:
Guillaume Ballet 2023-09-19 14:47:24 +02:00 committed by GitHub
parent 30d5d7c1b3
commit 7ed5bc021a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -189,6 +189,15 @@ func (db *Database) WritePreimages() {
}
}
// Preimage retrieves a cached trie node pre-image from memory. If it cannot be
// found cached, the method queries the persistent database for the content.
func (db *Database) Preimage(hash common.Hash) []byte {
if db.preimages == nil {
return nil
}
return db.preimages.preimage(hash)
}
// Cap iteratively flushes old but still referenced trie nodes until the total
// memory usage goes below the given threshold. The held pre-images accumulated
// up to this point will be flushed in case the size exceeds the threshold.