@@ -39,6 +39,7 @@ import (
3939 "github.com/ethereum/go-ethereum/core/history"
4040 "github.com/ethereum/go-ethereum/core/rawdb"
4141 "github.com/ethereum/go-ethereum/core/state"
42+ "github.com/ethereum/go-ethereum/core/state/codedb"
4243 "github.com/ethereum/go-ethereum/core/state/snapshot"
4344 "github.com/ethereum/go-ethereum/core/stateless"
4445 "github.com/ethereum/go-ethereum/core/tracing"
@@ -296,7 +297,7 @@ type BlockChain struct {
296297 lastWrite uint64 // Last block when the state was flushed
297298 flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state
298299 triedb * triedb.Database // The database handler for maintaining trie nodes.
299- statedb * state. CachingDB // State database to reuse between imports (contains state cache)
300+ codedb * codedb. Database // The database handler for maintaining contract codes
300301 txIndexer * txIndexer // Transaction indexer, might be nil if not enabled
301302
302303 hc * HeaderChain
@@ -376,6 +377,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
376377 cfg : cfg ,
377378 db : db ,
378379 triedb : triedb ,
380+ codedb : codedb .New (db ),
379381 triegc : prque.New [int64 , common.Hash ](nil ),
380382 chainmu : syncx .NewClosableMutex (),
381383 bodyCache : lru.NewCache [common.Hash , * types.Body ](bodyCacheLimit ),
@@ -391,7 +393,6 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
391393 return nil , err
392394 }
393395 bc .flushInterval .Store (int64 (cfg .TrieTimeLimit ))
394- bc .statedb = state .NewDatabase (bc .triedb , nil )
395396 bc .validator = NewBlockValidator (chainConfig , bc )
396397 bc .prefetcher = newStatePrefetcher (chainConfig , bc .hc )
397398 bc .processor = NewStateProcessor (bc .hc )
@@ -568,9 +569,6 @@ func (bc *BlockChain) setupSnapshot() {
568569 AsyncBuild : ! bc .cfg .SnapshotWait ,
569570 }
570571 bc .snaps , _ = snapshot .New (snapconfig , bc .db , bc .triedb , head .Root )
571-
572- // Re-initialize the state database with snapshot
573- bc .statedb = state .NewDatabase (bc .triedb , bc .snaps )
574572 }
575573}
576574
@@ -1989,11 +1987,12 @@ func (bc *BlockChain) ProcessBlock(parentRoot common.Hash, block *types.Block, s
19891987 startTime = time .Now ()
19901988 statedb * state.StateDB
19911989 interrupt atomic.Bool
1990+ sdb = state .NewDatabase (bc .triedb , bc .codedb ).WithSnapshot (bc .snaps )
19921991 )
19931992 defer interrupt .Store (true ) // terminate the prefetch at the end
19941993
19951994 if bc .cfg .NoPrefetch {
1996- statedb , err = state .New (parentRoot , bc . statedb )
1995+ statedb , err = state .New (parentRoot , sdb )
19971996 if err != nil {
19981997 return nil , err
19991998 }
@@ -2003,15 +2002,15 @@ func (bc *BlockChain) ProcessBlock(parentRoot common.Hash, block *types.Block, s
20032002 //
20042003 // Note: the main processor and prefetcher share the same reader with a local
20052004 // cache for mitigating the overhead of state access.
2006- prefetch , process , err := bc . statedb .ReadersWithCacheStats (parentRoot )
2005+ prefetch , process , err := sdb .ReadersWithCacheStats (parentRoot )
20072006 if err != nil {
20082007 return nil , err
20092008 }
2010- throwaway , err := state .NewWithReader (parentRoot , bc . statedb , prefetch )
2009+ throwaway , err := state .NewWithReader (parentRoot , sdb , prefetch )
20112010 if err != nil {
20122011 return nil , err
20132012 }
2014- statedb , err = state .NewWithReader (parentRoot , bc . statedb , process )
2013+ statedb , err = state .NewWithReader (parentRoot , sdb , process )
20152014 if err != nil {
20162015 return nil , err
20172016 }
0 commit comments