-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
all: unify the trie database and snapshot in path mode #30159
base: master
Are you sure you want to change the base?
Conversation
3669e84
to
9634ae2
Compare
3ce906c
to
51812ea
Compare
51812ea
to
af54be1
Compare
ee78428
to
ebc0454
Compare
0c48fce
to
d5fdd5a
Compare
d5fdd5a
to
ad2046a
Compare
if chain.TrieDB().Scheme() == rawdb.HashScheme { | ||
it, err = chain.Snapshots().AccountIterator(req.Root, req.Origin) | ||
} else { | ||
it, err = chain.TrieDB().AccountIterator(req.Root, req.Origin) |
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.
I don't understand this. Why are you using triedb account iterator in pbss-mode? (also below)
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.
In the path mode, the legacy state snapshot is not existent anymore. The original state snapshot data will be over taken by the pathdb (the states inside of pathdb).
Therefore, constructing the iterator from pathdb is the only efficient/equivalent way to serve the snap state requests
@@ -704,7 +704,7 @@ func syncWithHookWriter(t *testing.T, root common.Hash, db ethdb.Database, srcDb | |||
syncPath: NewSyncPath([]byte(paths[i])), | |||
}) | |||
} | |||
reader, err := srcDb.Reader(root) |
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.
If we want to make the change smaller, how about first a pure refactoring/renaming-PR, changing e.g. this Reader->NodeReader
, and Database
to NodeDatabase
, and other similar pure changes?
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.
sounds good to me!
"github.com/ethereum/go-ethereum/trie/trienode" | ||
) | ||
|
||
// buffer is a collection of modified states along with the modified trie nodes. |
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.
Is there any relation between this buffer implementation, and the one PR:ed in #30464 ? Or rather, what is the relation between the two? Orthogonal, or one is an evolution of the other?
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.
The buffer here contains (a) trie node data (b) state data, it's still a singleton structure for aggregating db writes;
The #30464 introduces an notion called "frozen" buffer. There are two buffers (totally equal) in the pathdb. If the first buffer is full, it will be scheduled for flushing in the background and once it's fully flushed. In the same time, the new db writes will be accumulated in the second buffer to not block the system.
// newFastIterator creates a new hierarchical account or storage iterator with one | ||
// element per diff layer. The returned combo iterator can be used to walk over | ||
// the entire snapshot diff stack simultaneously. | ||
func newFastIterator(db *Database, root common.Hash, account common.Hash, seek common.Hash, accountIterator bool) (*fastIterator, error) { |
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.
is this an exact replica of iterator_fast.go
in core/state/snapshot
? If so, couldn't we put it into some shared (possibly internal) package?
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.
Ah right I guess it cannot be exactly identical, they use different iterators under the hood :/
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.
Yeah, there are some tiny differences unfortunately
root: root, | ||
account: accountIterator, | ||
} | ||
loop: |
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.
when I see labels , I usually think that it ought to be a closure with return
s instead of goto label
.
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.
2nd pass, left a few nitpicks. I am yet to start trying to implement verkle on top of it to see if I have more comments. I don't see how this PR could be broken into smaller pieces, unfortunately, at least in a significant way.
} | ||
} | ||
if scheme == rawdb.PathScheme { | ||
if err := chain.TrieDB().WaitGeneration(); err != 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.
nit: WaitForGeneration
// | ||
// The passed in maps(nodes, states) will be retained to avoid copying | ||
// everything. Therefore, these maps must not be changed afterwards. | ||
Update(root common.Hash, parent common.Hash, block uint64, nodes *trienode.MergedNodeSet, states *triestate.Set) error |
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.
can't you just pass nil
in the case of hashdb
and not remove this from the interface?
ad2046a
to
8c6bf3b
Compare
This change ports some non-important changes from #30159, including interface renaming and some trivial refactorings.
Hello~ what is the purpose of this PR? Is it just simplifying the logic and making the trie code clearer? |
This change ports some non-important changes from #30159, including interface renaming and some trivial refactorings.
No description provided.