core/rawdb, core/state: polish the transition state implementation#544
Open
rjl493456442 wants to merge 7 commits intogballet:rebase-master-add-transition-statefrom
Open
Conversation
rjl493456442
commented
Jun 3, 2025
consensus/beacon/consensus.go
Outdated
| // This step needs to happen as late as possible to catch all access events. | ||
| if chain.Config().IsVerkle(header.Number, header.Time) { | ||
| // TODO(gballet) move this to the end of the overlay conversion function in a subsequent PR | ||
| statedb.Database().(*state.CachingDB).SaveTransitionState(header.Root, &overlay.TransitionState{Ended: true}) |
Author
There was a problem hiding this comment.
&overlay.TransitionState{Ended: true}) is apparently wrong here. Let's remove it for now.
rjl493456442
commented
Jun 3, 2025
|
|
||
| func GenerateVerkleChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int, gen func(int, *BlockGen)) (common.Hash, ethdb.Database, []*types.Block, []types.Receipts, []*verkle.VerkleProof, []verkle.StateDiff) { | ||
| db := rawdb.NewMemoryDatabase() | ||
| saveVerkleTransitionStatusAtVerlkeGenesis(db) |
Author
There was a problem hiding this comment.
Duplicated with the one in genesis.Commit(db, triedb). It's also not correct to persist a transition-state with zero root.
rjl493456442
commented
Jun 3, 2025
| emptyRoot = types.EmptyVerkleHash | ||
| } | ||
| db := rawdb.NewMemoryDatabase() | ||
| if isVerkle { |
Author
There was a problem hiding this comment.
It's unnecessary to persist any transition flag, as this function is supposed to calculate the state root of genesis only.
rjl493456442
commented
Jun 3, 2025
| if genesis != nil && genesis.Config == nil { | ||
| return nil, common.Hash{}, nil, errGenesisNoConfig | ||
| } | ||
| // In case of verkle-at-genesis, we need to ensure that the conversion |
Author
There was a problem hiding this comment.
Duplicated with the one in genesis.Commit(db, triedb). It's also not correct to persist a transition-state with zero root.
c38f272 to
c0578c1
Compare
e3f7af8 to
86183a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this pull request, several changes have been made:
(a) Replaced
CurrentAccountAddress *common.AddresswithCurrentAccountHash common.HashManaging a nullable pointer adds unnecessary complexity. This change simplifies the
logic by replacing the pointer with a value based flag:
CurrentAccountAddress == nilindicated that no account had been migrated yet.CurrentAccountHash == common.Hash{}serves the same purpose.This approach is already used in
CurrentSlotHash, so this change aligns the handling of both fields.(b) Removed
LoadTransitionStatecall sites from the trie readerThe current usage of
LoadTransitionStatein the trie reader is not correct. We should considerfive different scenarios:
However, in your implementation, e.g., in the code below, it's wrong. As you mentioned,
the migration is only started if the base merkle state if finalized.
!ts.InTransition() && !ts.Transitioned()can refer to the situation that Verkle has been activated but the migration is not. In this
case, Overlay tree should be used instead of Merkle here. We should separate this part
of logic into a following PR.