@@ -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"
@@ -300,7 +301,7 @@ type BlockChain struct {
300301 lastWrite uint64 // Last block when the state was flushed
301302 flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state
302303 triedb * triedb.Database // The database handler for maintaining trie nodes.
303- statedb * state. CachingDB // State database to reuse between imports (contains state cache)
304+ codedb * codedb. Database // The database handler for maintaining contract codes
304305 txIndexer * txIndexer // Transaction indexer, might be nil if not enabled
305306
306307 hc * HeaderChain
@@ -381,6 +382,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
381382 cfg : cfg ,
382383 db : db ,
383384 triedb : triedb ,
385+ codedb : codedb .New (db ),
384386 triegc : prque.New [int64 , common.Hash ](nil ),
385387 chainmu : syncx .NewClosableMutex (),
386388 bodyCache : lru.NewCache [common.Hash , * types.Body ](bodyCacheLimit ),
@@ -397,7 +399,6 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
397399 return nil , err
398400 }
399401 bc .flushInterval .Store (int64 (cfg .TrieTimeLimit ))
400- bc .statedb = state .NewDatabase (bc .triedb , nil )
401402 bc .validator = NewBlockValidator (chainConfig , bc )
402403 bc .prefetcher = newStatePrefetcher (chainConfig , bc .hc )
403404 bc .processor = NewStateProcessor (bc .hc )
@@ -574,9 +575,6 @@ func (bc *BlockChain) setupSnapshot() {
574575 AsyncBuild : ! bc .cfg .SnapshotWait ,
575576 }
576577 bc .snaps , _ = snapshot .New (snapconfig , bc .db , bc .triedb , head .Root )
577-
578- // Re-initialize the state database with snapshot
579- bc .statedb = state .NewDatabase (bc .triedb , bc .snaps )
580578 }
581579}
582580
@@ -2008,11 +2006,12 @@ func (bc *BlockChain) ProcessBlock(parentRoot common.Hash, block *types.Block, s
20082006 startTime = time .Now ()
20092007 statedb * state.StateDB
20102008 interrupt atomic.Bool
2009+ sdb = state .NewDatabase (bc .triedb , bc .codedb ).WithSnapshot (bc .snaps )
20112010 )
20122011 defer interrupt .Store (true ) // terminate the prefetch at the end
20132012
20142013 if bc .cfg .NoPrefetch {
2015- statedb , err = state .New (parentRoot , bc . statedb )
2014+ statedb , err = state .New (parentRoot , sdb )
20162015 if err != nil {
20172016 return nil , err
20182017 }
@@ -2022,15 +2021,15 @@ func (bc *BlockChain) ProcessBlock(parentRoot common.Hash, block *types.Block, s
20222021 //
20232022 // Note: the main processor and prefetcher share the same reader with a local
20242023 // cache for mitigating the overhead of state access.
2025- prefetch , process , err := bc . statedb .ReadersWithCacheStats (parentRoot )
2024+ prefetch , process , err := sdb .ReadersWithCacheStats (parentRoot )
20262025 if err != nil {
20272026 return nil , err
20282027 }
2029- throwaway , err := state .NewWithReader (parentRoot , bc . statedb , prefetch )
2028+ throwaway , err := state .NewWithReader (parentRoot , sdb , prefetch )
20302029 if err != nil {
20312030 return nil , err
20322031 }
2033- statedb , err = state .NewWithReader (parentRoot , bc . statedb , process )
2032+ statedb , err = state .NewWithReader (parentRoot , sdb , process )
20342033 if err != nil {
20352034 return nil , err
20362035 }
0 commit comments