@@ -217,7 +217,7 @@ type BlockChain struct {
217217 lastWrite uint64 // Last block when the state was flushed
218218 flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state
219219 triedb * triedb.Database // The database handler for maintaining trie nodes.
220- stateCache state. Database // State database to reuse between imports (contains state cache)
220+ stateDb * state. CachingDB // State database to reuse between imports (contains state cache)
221221 txIndexer * txIndexer // Transaction indexer, might be nil if not enabled
222222
223223 hc * HeaderChain
@@ -310,7 +310,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
310310 }
311311 bc .flushInterval .Store (int64 (cacheConfig .TrieTimeLimit ))
312312 bc .forker = NewForkChoice (bc , shouldPreserve )
313- bc .stateCache = state .NewDatabaseWithNodeDB (bc .db , bc .triedb )
313+ bc .stateDb = state .NewDatabase (bc .db , bc .triedb , nil )
314314 bc .validator = NewBlockValidator (chainConfig , bc )
315315 bc .prefetcher = newStatePrefetcher (chainConfig , bc .hc )
316316 bc .processor = NewStateProcessor (chainConfig , bc .hc )
@@ -448,7 +448,13 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
448448 AsyncBuild : ! bc .cacheConfig .SnapshotWait ,
449449 }
450450 bc .snaps , _ = snapshot .New (snapconfig , bc .db , bc .triedb , head .Root )
451+
452+ // Register the snapshot into statedb. It's an ugly hack as state snapshot
453+ // is constructed after stateDb. TODO(rjl493456442) improve the construction
454+ // logic.
455+ bc .stateDb .SetSnapshot (bc .snaps )
451456 }
457+
452458 // Rewind the chain in case of an incompatible config upgrade.
453459 if compat , ok := genesisErr .(* params.ConfigCompatError ); ok {
454460 log .Warn ("Rewinding chain to upgrade configuration" , "err" , compat )
@@ -1800,7 +1806,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
18001806 if parent == nil {
18011807 parent = bc .GetHeader (block .ParentHash (), block .NumberU64 ()- 1 )
18021808 }
1803- statedb , err := state .New (parent .Root , bc .stateCache , bc . snaps )
1809+ statedb , err := state .New (parent .Root , bc .stateDb )
18041810 if err != nil {
18051811 return it .index , err
18061812 }
@@ -1826,7 +1832,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
18261832 var followupInterrupt atomic.Bool
18271833 if ! bc .cacheConfig .TrieCleanNoPrefetch {
18281834 if followup , err := it .peek (); followup != nil && err == nil {
1829- throwaway , _ := state .New (parent .Root , bc .stateCache , bc . snaps )
1835+ throwaway , _ := state .New (parent .Root , bc .stateDb )
18301836
18311837 go func (start time.Time , followup * types.Block , throwaway * state.StateDB ) {
18321838 // Disable tracing for prefetcher executions.
0 commit comments