@@ -72,14 +72,11 @@ var (
7272 storageUpdateTimer = metrics .NewRegisteredResettingTimer ("chain/storage/updates" , nil )
7373 storageCommitTimer = metrics .NewRegisteredResettingTimer ("chain/storage/commits" , nil )
7474
75- snapshotAccountReadTimer = metrics .NewRegisteredResettingTimer ("chain/snapshot/account/reads" , nil )
76- snapshotStorageReadTimer = metrics .NewRegisteredResettingTimer ("chain/snapshot/storage/reads" , nil )
77- snapshotCommitTimer = metrics .NewRegisteredResettingTimer ("chain/snapshot/commits" , nil )
78-
7975 accountReadSingleTimer = metrics .NewRegisteredResettingTimer ("chain/account/single/reads" , nil )
8076 storageReadSingleTimer = metrics .NewRegisteredResettingTimer ("chain/storage/single/reads" , nil )
8177
82- triedbCommitTimer = metrics .NewRegisteredResettingTimer ("chain/triedb/commits" , nil )
78+ snapshotCommitTimer = metrics .NewRegisteredResettingTimer ("chain/snapshot/commits" , nil )
79+ triedbCommitTimer = metrics .NewRegisteredResettingTimer ("chain/triedb/commits" , nil )
8380
8481 blockInsertTimer = metrics .NewRegisteredResettingTimer ("chain/inserts" , nil )
8582 blockValidationTimer = metrics .NewRegisteredResettingTimer ("chain/validation" , nil )
@@ -220,7 +217,7 @@ type BlockChain struct {
220217 lastWrite uint64 // Last block when the state was flushed
221218 flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state
222219 triedb * triedb.Database // The database handler for maintaining trie nodes.
223- 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)
224221 txIndexer * txIndexer // Transaction indexer, might be nil if not enabled
225222
226223 hc * HeaderChain
@@ -311,7 +308,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
311308 return nil , err
312309 }
313310 bc .flushInterval .Store (int64 (cacheConfig .TrieTimeLimit ))
314- bc .stateCache = state .NewDatabaseWithNodeDB (bc .db , bc . triedb )
311+ bc .statedb = state .NewDatabase (bc .triedb , nil )
315312 bc .validator = NewBlockValidator (chainConfig , bc )
316313 bc .prefetcher = newStatePrefetcher (chainConfig , bc .hc )
317314 bc .processor = NewStateProcessor (chainConfig , bc .hc )
@@ -449,7 +446,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
449446 AsyncBuild : ! bc .cacheConfig .SnapshotWait ,
450447 }
451448 bc .snaps , _ = snapshot .New (snapconfig , bc .db , bc .triedb , head .Root )
449+
450+ // Re-initialize the state database with snapshot
451+ bc .statedb = state .NewDatabase (bc .triedb , bc .snaps )
452452 }
453+
453454 // Rewind the chain in case of an incompatible config upgrade.
454455 if compat , ok := genesisErr .(* params.ConfigCompatError ); ok {
455456 log .Warn ("Rewinding chain to upgrade configuration" , "err" , compat )
@@ -1767,7 +1768,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
17671768 if parent == nil {
17681769 parent = bc .GetHeader (block .ParentHash (), block .NumberU64 ()- 1 )
17691770 }
1770- statedb , err := state .New (parent .Root , bc .stateCache , bc . snaps )
1771+ statedb , err := state .New (parent .Root , bc .statedb )
17711772 if err != nil {
17721773 return it .index , err
17731774 }
@@ -1793,7 +1794,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
17931794 var followupInterrupt atomic.Bool
17941795 if ! bc .cacheConfig .TrieCleanNoPrefetch {
17951796 if followup , err := it .peek (); followup != nil && err == nil {
1796- throwaway , _ := state .New (parent .Root , bc .stateCache , bc . snaps )
1797+ throwaway , _ := state .New (parent .Root , bc .statedb )
17971798
17981799 go func (start time.Time , followup * types.Block , throwaway * state.StateDB ) {
17991800 // Disable tracing for prefetcher executions.
@@ -1914,26 +1915,21 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
19141915 proctime := time .Since (start ) // processing + validation
19151916
19161917 // Update the metrics touched during block processing and validation
1917- accountReadTimer .Update (statedb .AccountReads ) // Account reads are complete(in processing)
1918- storageReadTimer .Update (statedb .StorageReads ) // Storage reads are complete(in processing)
1919- snapshotAccountReadTimer .Update (statedb .SnapshotAccountReads ) // Account reads are complete(in processing)
1920- snapshotStorageReadTimer .Update (statedb .SnapshotStorageReads ) // Storage reads are complete(in processing)
1921-
1922- accountRead := statedb .SnapshotAccountReads + statedb .AccountReads // The time spent on account read
1923- storageRead := statedb .SnapshotStorageReads + statedb .StorageReads // The time spent on storage read
1918+ accountReadTimer .Update (statedb .AccountReads ) // Account reads are complete(in processing)
1919+ storageReadTimer .Update (statedb .StorageReads ) // Storage reads are complete(in processing)
19241920 if statedb .AccountLoaded != 0 {
1925- accountReadSingleTimer .Update (accountRead / time .Duration (statedb .AccountLoaded ))
1921+ accountReadSingleTimer .Update (statedb . AccountReads / time .Duration (statedb .AccountLoaded ))
19261922 }
19271923 if statedb .StorageLoaded != 0 {
1928- storageReadSingleTimer .Update (storageRead / time .Duration (statedb .StorageLoaded ))
1929- }
1930- accountUpdateTimer .Update (statedb .AccountUpdates ) // Account updates are complete(in validation)
1931- storageUpdateTimer .Update (statedb .StorageUpdates ) // Storage updates are complete(in validation)
1932- accountHashTimer .Update (statedb .AccountHashes ) // Account hashes are complete(in validation)
1933- triehash := statedb .AccountHashes // The time spent on tries hashing
1934- trieUpdate := statedb .AccountUpdates + statedb .StorageUpdates // The time spent on tries update
1935- blockExecutionTimer .Update (ptime - (accountRead + storageRead )) // The time spent on EVM processing
1936- blockValidationTimer .Update (vtime - (triehash + trieUpdate )) // The time spent on block validation
1924+ storageReadSingleTimer .Update (statedb . StorageReads / time .Duration (statedb .StorageLoaded ))
1925+ }
1926+ accountUpdateTimer .Update (statedb .AccountUpdates ) // Account updates are complete(in validation)
1927+ storageUpdateTimer .Update (statedb .StorageUpdates ) // Storage updates are complete(in validation)
1928+ accountHashTimer .Update (statedb .AccountHashes ) // Account hashes are complete(in validation)
1929+ triehash := statedb .AccountHashes // The time spent on tries hashing
1930+ trieUpdate := statedb .AccountUpdates + statedb .StorageUpdates // The time spent on tries update
1931+ blockExecutionTimer .Update (ptime - (statedb . AccountReads + statedb . StorageReads )) // The time spent on EVM processing
1932+ blockValidationTimer .Update (vtime - (triehash + trieUpdate )) // The time spent on block validation
19371933
19381934 // Write the block to the chain and get the status.
19391935 var (
0 commit comments