diff --git a/core/block_validator.go b/core/block_validator.go index b1ceab9d5c6c..d977c1d63d96 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -131,6 +131,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root { return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error()) } + statedb.Database().SaveTransitionState(header.Root) return nil } diff --git a/core/blockchain.go b/core/blockchain.go index 39485505bb05..ec12f57fc1ee 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1757,6 +1757,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) parent = bc.GetHeader(block.ParentHash(), block.NumberU64()-1) } + if bc.Config().IsPrague(block.Number(), block.Time()) { + bc.stateCache.LoadTransitionState(parent.Root) + + // pragueTime has been reached. If the transition isn't active, it means this + // is the fork block and that the conversion needs to be marked at started. + if !bc.stateCache.InTransition() && !bc.stateCache.Transitioned() { + bc.stateCache.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), bc.Config().PragueTime, parent.Root) + } + } if parent.Number.Uint64() == conversionBlock { bc.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), &parent.Time, parent.Root) bc.stateCache.SetLastMerkleRoot(parent.Root) diff --git a/core/state/database.go b/core/state/database.go index 43e0569c638b..21280359794e 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -342,7 +342,7 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) { // TODO separate both cases when I can be certain that it won't // find a Verkle trie where is expects a Transitoion trie. - if db.CurrentTransitionState != nil && (db.CurrentTransitionState.started || db.CurrentTransitionState.ended) { + if db.InTransition() || db.Transitioned() { // NOTE this is a kaustinen-only change, it will break replay vkt, err := db.openVKTrie(root) if err != nil { @@ -542,7 +542,11 @@ func (db *cachingDB) SaveTransitionState(root common.Hash) { db.TransitionStatePerRoot = make(map[common.Hash]*TransitionState) } - db.TransitionStatePerRoot[root] = db.CurrentTransitionState + if db.CurrentTransitionState != nil { + // Copy so that the address pointer isn't updated after + // it has been saved. + db.TransitionStatePerRoot[root] = db.CurrentTransitionState.Copy() + } } func (db *cachingDB) LoadTransitionState(root common.Hash) { @@ -556,9 +560,7 @@ func (db *cachingDB) LoadTransitionState(root common.Hash) { ts = &TransitionState{ended: db.triedb.IsVerkle()} } + // Copy so that the CurrentAddress pointer in the map + // doesn't get overwritten. db.CurrentTransitionState = ts.Copy() - - if db.CurrentTransitionState != nil { - fmt.Println("address", db.CurrentTransitionState.CurrentAccountAddress) - } }