@@ -72,14 +72,11 @@ var (
72
72
storageUpdateTimer = metrics .NewRegisteredResettingTimer ("chain/storage/updates" , nil )
73
73
storageCommitTimer = metrics .NewRegisteredResettingTimer ("chain/storage/commits" , nil )
74
74
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
-
79
75
accountReadSingleTimer = metrics .NewRegisteredResettingTimer ("chain/account/single/reads" , nil )
80
76
storageReadSingleTimer = metrics .NewRegisteredResettingTimer ("chain/storage/single/reads" , nil )
81
77
82
- triedbCommitTimer = metrics .NewRegisteredResettingTimer ("chain/triedb/commits" , nil )
78
+ snapshotCommitTimer = metrics .NewRegisteredResettingTimer ("chain/snapshot/commits" , nil )
79
+ triedbCommitTimer = metrics .NewRegisteredResettingTimer ("chain/triedb/commits" , nil )
83
80
84
81
blockInsertTimer = metrics .NewRegisteredResettingTimer ("chain/inserts" , nil )
85
82
blockValidationTimer = metrics .NewRegisteredResettingTimer ("chain/validation" , nil )
@@ -220,7 +217,7 @@ type BlockChain struct {
220
217
lastWrite uint64 // Last block when the state was flushed
221
218
flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state
222
219
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)
224
221
txIndexer * txIndexer // Transaction indexer, might be nil if not enabled
225
222
226
223
hc * HeaderChain
@@ -311,7 +308,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
311
308
return nil , err
312
309
}
313
310
bc .flushInterval .Store (int64 (cacheConfig .TrieTimeLimit ))
314
- bc .stateCache = state .NewDatabaseWithNodeDB (bc .db , bc . triedb )
311
+ bc .statedb = state .NewDatabase (bc .triedb , nil )
315
312
bc .validator = NewBlockValidator (chainConfig , bc )
316
313
bc .prefetcher = newStatePrefetcher (chainConfig , bc .hc )
317
314
bc .processor = NewStateProcessor (chainConfig , bc .hc )
@@ -449,7 +446,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
449
446
AsyncBuild : ! bc .cacheConfig .SnapshotWait ,
450
447
}
451
448
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 )
452
452
}
453
+
453
454
// Rewind the chain in case of an incompatible config upgrade.
454
455
if compat , ok := genesisErr .(* params.ConfigCompatError ); ok {
455
456
log .Warn ("Rewinding chain to upgrade configuration" , "err" , compat )
@@ -1767,7 +1768,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
1767
1768
if parent == nil {
1768
1769
parent = bc .GetHeader (block .ParentHash (), block .NumberU64 ()- 1 )
1769
1770
}
1770
- statedb , err := state .New (parent .Root , bc .stateCache , bc . snaps )
1771
+ statedb , err := state .New (parent .Root , bc .statedb )
1771
1772
if err != nil {
1772
1773
return it .index , err
1773
1774
}
@@ -1793,7 +1794,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
1793
1794
var followupInterrupt atomic.Bool
1794
1795
if ! bc .cacheConfig .TrieCleanNoPrefetch {
1795
1796
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 )
1797
1798
1798
1799
go func (start time.Time , followup * types.Block , throwaway * state.StateDB ) {
1799
1800
// Disable tracing for prefetcher executions.
@@ -1914,26 +1915,21 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
1914
1915
proctime := time .Since (start ) // processing + validation
1915
1916
1916
1917
// 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)
1924
1920
if statedb .AccountLoaded != 0 {
1925
- accountReadSingleTimer .Update (accountRead / time .Duration (statedb .AccountLoaded ))
1921
+ accountReadSingleTimer .Update (statedb . AccountReads / time .Duration (statedb .AccountLoaded ))
1926
1922
}
1927
1923
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
1937
1933
1938
1934
// Write the block to the chain and get the status.
1939
1935
var (
0 commit comments