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

MerkleDB allow warming node cache #2128

Merged
merged 6 commits into from
Oct 4, 2023
Merged
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
31 changes: 31 additions & 0 deletions x/merkledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,37 @@ func (db *merkleDB) Close() error {
return db.baseDB.Put(cleanShutdownKey, hadCleanShutdown)
}

func (db *merkleDB) PrefetchKeys(keys [][]byte) error {
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
db.commitLock.RLock()
defer db.commitLock.RUnlock()

if db.closed {
return database.ErrClosed
}

tempView, err := newTrieView(db, db, ViewChanges{})
if err != nil {
return err
}
for _, key := range keys {
pathToKey, err := tempView.getPathTo(db.newPath(key))
if err != nil {
return err
}
for _, n := range pathToKey {
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
if n.hasValue() {
db.valueNodeDB.nodeCache.Put(n.key, n)
} else {
if err := db.intermediateNodeDB.nodeCache.Put(n.key, n); err != nil {
return err
}
}
}
}

return nil
}

func (db *merkleDB) Get(key []byte) ([]byte, error) {
// this is a duplicate because the database interface doesn't support
// contexts, which are used for tracing
Expand Down