From 29c8f983293538eb485c055b53f574c959a97ea3 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 10 Aug 2023 21:38:07 +0200 Subject: [PATCH] save last MPT root for transition --- core/state/database.go | 11 +++++++++++ core/state/statedb.go | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/state/database.go b/core/state/database.go index c6ebbd1fba..7ee8489d3f 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -92,6 +92,8 @@ type Database interface { SetCurrentPreimageOffset(int64) AddRootTranslation(originalRoot, translatedRoot common.Hash) + + SetLastMerkleRoot(root common.Hash) } // Trie is a Ethereum Merkle Patricia trie. @@ -272,6 +274,7 @@ type cachingDB struct { origRoots [32]common.Hash translationIndex int translatedRootsLock sync.RWMutex + LastMerkleRoot common.Hash // root hash of the read-only base tree addrToPoint *utils.PointCache @@ -379,6 +382,10 @@ func (db *cachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Addre } } if db.started { + mpt, err := db.openStorageMPTrie(db.LastMerkleRoot, address, root, nil) + if err != nil { + return nil, err + } // Return a "storage trie" that is an adapter between the storge MPT // and the unique verkle tree. switch self := self.(type) { @@ -506,3 +513,7 @@ func (db *cachingDB) GetStorageProcessed() bool { func (db *cachingDB) AddRootTranslation(originalRoot, translatedRoot common.Hash) { db.AddTranslation(originalRoot, translatedRoot) } + +func (db *cachingDB) SetLastMerkleRoot(root common.Hash) { + db.LastMerkleRoot = root +} diff --git a/core/state/statedb.go b/core/state/statedb.go index a3d320e6f8..a3616e7a58 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1051,7 +1051,14 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash { if metrics.EnabledExpensive { defer func(start time.Time) { s.AccountHashes += time.Since(start) }(time.Now()) } - return s.trie.Hash() + root := s.trie.Hash() + + // Save the root of the MPT so that it can be used during the transition + if !s.Database().InTransition() && !s.Database().Transitioned() { + s.Database().SetLastMerkleRoot(root) + } + + return root } // SetTxContext sets the current transaction hash and index which are