•  


core/state: fix prefetcher for verkle by rjl493456442 · Pull Request #29760 · ethereum/go-ethereum · GitHub
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
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본