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

core/state: fix prefetcher for verkle #29760

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

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented May 13, 2024

This pull request fixes a flaw in verkle.

Inside of the statedb, there is a tool named "prefetcher". It will pull the necessary data for state hashing in the background to accelerate the state hashing performance. Unfortunately, it's broken in the verkle context.

The root cause is once verkle is activated, there is only a single trie used for state hashing(instead of two-layer tree structure in merkle). And storage trie commits are schedule before the account trie for performance consideration. If the verkle trie is resolved from the prefetcher after committing the storage changes, the changes caused by storage will be silently dropped.

This pull request disables the prefetching in verkle as a quick fix.

// Don't check prefetcher if Verkle Trie has been used. In the context of Verkle,
// only a single trie is used for state hashing. Replacing a non-nil Verkle tree
// here could result in losing uncommitted changes from storage.
if prefetcher != nil && (s.trie == nil || !s.trie.IsVerkle()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change does not only affect verkle, but also non-verkle, if prefetcher != nil, s.trie != nil would previously enter this clause, but not after this change.
Please elaborate

Copy link
Member Author

Choose a reason for hiding this comment

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

s.trie != nil && !s.trie.IsVerkle() will still entry the clause
only s.trie != nil && s.trie.IsVerkle will be rejected

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm talking about non-verkle (so s.trie.IsVerkle() == false).

So, for prefetcher != nil, s.trie != nil

  • currently, on master: we enter the clause
  • in this PR: we do not enter the clause

Copy link
Member Author

Choose a reason for hiding this comment

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

for the case you mentioned, non-verkle, trie is not nil, we will still enter the clause isn't it?

(s.trie == nil || !s.trie.IsVerkle()), the case will satisfy the second condition !s.trie.IsVerkle()

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, yes, my bad!

// Don't check prefetcher if Verkle Trie has been used. In the context of Verkle,
// only a single trie is used for state hashing. Replacing a non-nil Verkle tree
// here could result in losing uncommitted changes from storage.
if prefetcher != nil && (s.trie == nil || !s.trie.IsVerkle()) {
Copy link
Member

Choose a reason for hiding this comment

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

I am quite surprised that you need this, because in verkle mode the prefetcher should be nil. But in any case, it doesn't hurt to add that check.

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, i have some changes locally and enable the prefetcher for verkle. Tests are broken immediately. I can imagine prefetcher will enabled for verkle as well.

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.

LGTM

@karalabe
Copy link
Member

I'd appreciate getting the prefetcher PR in first because I don't want to rebase that for a 1 liner change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants