@@ -24,6 +24,7 @@ import (
2424
2525 "github.com/ethereum/go-ethereum/common"
2626 "github.com/ethereum/go-ethereum/common/lru"
27+ "github.com/ethereum/go-ethereum/core/overlay"
2728 "github.com/ethereum/go-ethereum/core/rawdb"
2829 "github.com/ethereum/go-ethereum/core/state/snapshot"
2930 "github.com/ethereum/go-ethereum/core/types"
@@ -145,50 +146,6 @@ type Trie interface {
145146 IsVerkle () bool
146147}
147148
148- // TransitionState is a structure that holds the progress markers of the
149- // translation process.
150- type TransitionState struct {
151- CurrentAccountAddress * common.Address // addresss of the last translated account
152- CurrentSlotHash common.Hash // hash of the last translated storage slot
153- CurrentPreimageOffset int64 // next byte to read from the preimage file
154- Started , Ended bool
155-
156- // Mark whether the storage for an account has been processed. This is useful if the
157- // maximum number of leaves of the conversion is reached before the whole storage is
158- // processed.
159- StorageProcessed bool
160-
161- BaseRoot common.Hash // hash of the last read-only MPT base tree
162- }
163-
164- // InTransition returns true if the translation process is in progress.
165- func (ts * TransitionState ) InTransition () bool {
166- return ts != nil && ts .Started && ! ts .Ended
167- }
168-
169- // Transitioned returns true if the translation process has been completed.
170- func (ts * TransitionState ) Transitioned () bool {
171- return ts != nil && ts .Ended
172- }
173-
174- // Copy returns a deep copy of the TransitionState object.
175- func (ts * TransitionState ) Copy () * TransitionState {
176- ret := & TransitionState {
177- Started : ts .Started ,
178- Ended : ts .Ended ,
179- CurrentSlotHash : ts .CurrentSlotHash ,
180- CurrentPreimageOffset : ts .CurrentPreimageOffset ,
181- StorageProcessed : ts .StorageProcessed ,
182- }
183-
184- if ts .CurrentAccountAddress != nil {
185- ret .CurrentAccountAddress = & common.Address {}
186- copy (ret .CurrentAccountAddress [:], ts .CurrentAccountAddress [:])
187- }
188-
189- return ret
190- }
191-
192149// CachingDB is an implementation of Database interface. It leverages both trie and
193150// state snapshot to provide functionalities for state access. It's meant to be a
194151// long-live object and has a few caches inside for sharing between blocks.
@@ -201,7 +158,7 @@ type CachingDB struct {
201158 pointCache * utils.PointCache
202159
203160 // Transition-specific fields
204- TransitionStatePerRoot lru.BasicLRU [common.Hash , * TransitionState ]
161+ TransitionStatePerRoot lru.BasicLRU [common.Hash , * overlay. TransitionState ]
205162}
206163
207164// NewDatabase creates a state database with the provided data sources.
@@ -213,7 +170,7 @@ func NewDatabase(triedb *triedb.Database, snap *snapshot.Tree) *CachingDB {
213170 codeCache : lru.NewSizeConstrainedCache [common.Hash , []byte ](codeCacheSize ),
214171 codeSizeCache : lru.NewCache [common.Hash , int ](codeSizeCacheSize ),
215172 pointCache : utils .NewPointCache (pointCacheSize ),
216- TransitionStatePerRoot : lru.NewBasicLRU [common.Hash , * TransitionState ](1000 ),
173+ TransitionStatePerRoot : lru.NewBasicLRU [common.Hash , * overlay. TransitionState ](1000 ),
217174 }
218175}
219176
@@ -338,7 +295,7 @@ func mustCopyTrie(t Trie) Trie {
338295
339296// SaveTransitionState saves the transition state to the cache and commits
340297// it to the database if it's not already in the cache.
341- func (db * CachingDB ) SaveTransitionState (root common.Hash , ts * TransitionState ) {
298+ func (db * CachingDB ) SaveTransitionState (root common.Hash , ts * overlay. TransitionState ) {
342299 if ts == nil {
343300 panic ("nil transition state" )
344301 }
@@ -370,22 +327,18 @@ func (db *CachingDB) SaveTransitionState(root common.Hash, ts *TransitionState)
370327 log .Debug ("saving transition state" , "storage processed" , ts .StorageProcessed , "addr" , ts .CurrentAccountAddress , "slot hash" , ts .CurrentSlotHash , "root" , root , "ended" , ts .Ended , "started" , ts .Started )
371328}
372329
373- func (db * CachingDB ) LoadTransitionState (root common.Hash ) * TransitionState {
330+ func (db * CachingDB ) LoadTransitionState (root common.Hash ) * overlay. TransitionState {
374331 // Try to get the transition state from the cache and
375332 // the DB if it's not there.
376333 ts , ok := db .TransitionStatePerRoot .Get (root )
377334 if ! ok {
378335 // Not in the cache, try getting it from the DB
379336 data , _ := rawdb .ReadVerkleTransitionState (db .TrieDB ().Disk (), root )
380- // if err != nil && errors.Is(err, triedb.ErrNotFound) {
381- // log.Error("failed to read transition state", "err", err)
382- // return nil
383- // }
384337
385338 // if a state could be read from the db, attempt to decode it
386339 if len (data ) > 0 {
387340 var (
388- newts TransitionState
341+ newts overlay. TransitionState
389342 buf = bytes .NewBuffer (data [:])
390343 dec = gob .NewDecoder (buf )
391344 )
@@ -405,7 +358,7 @@ func (db *CachingDB) LoadTransitionState(root common.Hash) *TransitionState {
405358 // as a verkle database.
406359 log .Debug ("no transition state found, starting fresh" , "is verkle" , db .triedb .IsVerkle ())
407360 // Start with a fresh state
408- ts = & TransitionState {Ended : db .triedb .IsVerkle ()}
361+ ts = & overlay. TransitionState {Ended : db .triedb .IsVerkle ()}
409362 }
410363
411364 db .TransitionStatePerRoot .Add (root , ts )
0 commit comments