-
Notifications
You must be signed in to change notification settings - Fork 189
Optimize traceBlock with fastCache/Persistent DB #546
Conversation
Dear reviewers, I will separate this PR and fix the unit test. |
65e9887
to
5be9c9e
Compare
PTAL :) @jeongkyun-oh |
Support state database with exist fast cache for trace block Support to get stateDB with a root trie on persistent DB or its cache
a84afcf
to
60ccc7e
Compare
@@ -357,6 +369,11 @@ func (db *Database) DiskDB() database.DBManager { | |||
return db.diskDB | |||
} | |||
|
|||
// TrieNodeCache retrieves the trieNodeCache of the trie database. | |||
func (db *Database) TrieNodeCache() *fastcache.Cache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, however, it would be better if returning an interface, not a pointer of struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. We don't have an interface for trieNodeCache now.
Let's make a cache interface for trieNodeCache later. :)
storage/statedb/database.go
Outdated
// DoesExistNodeInPersistent returns if the node exists on the persistent database or its cache. | ||
func (db *Database) DoesExistNodeInPersistent(hash common.Hash) bool { | ||
// Retrieve the node from DB cache if available | ||
if enc := db.getCachedNode(hash); enc != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit strange since the function name. According to its name, I think it should directly call db.diskDB.ReadCachedTrieNode
, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, without state migration, if the trie is in fastCache, it means the trie is already in level DB. So I added the check routine like this. :)
return nil, emptyFn, err | ||
} | ||
logger.Debug("Get stateDB by computeStateDB", "block", block.NumberU64()) | ||
emptyFn := func() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about declaring this as a static variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean a static variable?
It means to declare a global variable? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a package variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only used in this function. So I think we don't need to declare it as a package variable. :)
PTAL. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, however, this seems to conflict with #548
Proposed changes
This PR optimizes traceBlock feature like below.
Types of changes
Please put an x in the boxes related to your change.
Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.
$ make test
)Related issues
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...