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

trie_prefetcher: alternate structure #666

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

darioush
Copy link
Collaborator

@darioush darioush commented Oct 1, 2024

Why this should be merged

The current trie_prefetcher is modified significantly compared to upstream, which makes it difficult to merge changes from upstream.
This PR aims to preserve the existing behavior but only with minor inline modifications to upstream code.

I would be open to other structures with the same idea.

How this works

Uses a wrapper for DB to track the central worker pool.
Adds a couple hooks for stopping the background processes.

How this was tested

CI

@@ -59,7 +59,8 @@ func filledStateDB() *StateDB {

func TestCopyAndClose(t *testing.T) {
db := filledStateDB()
prefetcher := newTriePrefetcher(db.db, db.originalRoot, "", maxConcurrency)
prefetchDb := newPrefetcherDatabase(db.db, maxConcurrency)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to preserve existing UT behavior for now

@darioush darioush closed this Nov 18, 2024
@darioush darioush reopened this Nov 18, 2024

// triePrefetcher is an active prefetcher, which receives accounts or storage
// items and does trie-loading of them. The goal is to get as much useful content
// into the caches as possible.
//
// Note, the prefetcher's API is not thread safe.
type triePrefetcher struct {
db Database // Database to fetch trie nodes through
db PrefetcherDB // Database to fetch trie nodes through
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed compared to upstream

Comment on lines +65 to +69
var pdb PrefetcherDB
pdb = withPrefetcherDefaults{db}
if db, ok := db.(withPrefetcherDB); ok {
pdb = db.PrefetcherDB()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed compared to upstream

storageFetchers int64
largestLoad int64
)
defer p.db.Close()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added compared to upstream

p *triePrefetcher

db Database // Database to load trie nodes through
db PrefetcherDB // Database to load trie nodes through
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified compared to upstream

return 0
}
return sf.to.copies
sf.db.WaitTrie(sf.trie)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added compared to upstream

Comment on lines +365 to +367
sf.db.PrefetchAccount(sf.trie, common.BytesToAddress(task))
} else {
sf.db.PrefetchStorage(sf.trie, sf.addr, task)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified. compared to upstream (made this more explicit to avoid overriding GetAccount and GetStorage)

@darioush
Copy link
Collaborator Author

Adding do not merge label prior to verifying performance

@darioush darioush marked this pull request as ready for review November 19, 2024 01:35
@darioush darioush requested review from ceyonur and a team as code owners November 19, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant