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

all: unify the trie database and snapshot in path mode #30159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rjl493456442
Copy link
Member

No description provided.

@rjl493456442 rjl493456442 force-pushed the snapshot-integration branch 7 times, most recently from 3669e84 to 9634ae2 Compare July 22, 2024 06:36
@rjl493456442 rjl493456442 force-pushed the snapshot-integration branch 5 times, most recently from 3ce906c to 51812ea Compare July 30, 2024 05:46
@rjl493456442 rjl493456442 force-pushed the snapshot-integration branch 5 times, most recently from ee78428 to ebc0454 Compare August 21, 2024 07:41
core/state/database.go Outdated Show resolved Hide resolved
core/state/database.go Outdated Show resolved Hide resolved
@rjl493456442 rjl493456442 force-pushed the snapshot-integration branch 5 times, most recently from 0c48fce to d5fdd5a Compare September 27, 2024 05:51
@rjl493456442 rjl493456442 changed the title [Work-in-progress] Snapshot integration all: unify the trie database and snapshot in path mode Sep 27, 2024
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)
Copy link
Contributor

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)

Copy link
Member Author

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)
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

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?

Copy link
Member Author

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) {
Copy link
Contributor

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?

Copy link
Contributor

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 :/

Copy link
Member Author

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:
Copy link
Contributor

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 returns instead of goto label.

Copy link
Member

@gballet gballet left a 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 {
Copy link
Member

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
Copy link
Member

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?

holiman pushed a commit that referenced this pull request Oct 18, 2024
This change ports some non-important changes from #30159, including interface renaming and some trivial refactorings.
@will-2012
Copy link

Hello~ what is the purpose of this PR? Is it just simplifying the logic and making the trie code clearer?
Btw, the bloomfilter in the flat state is no longer used. Does this harm performance?

holiman pushed a commit that referenced this pull request Nov 19, 2024
This change ports some non-important changes from #30159, including interface renaming and some trivial refactorings.
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.

4 participants