@@ -28,7 +28,6 @@ import (
2828 "time"
2929
3030 "github.com/ethereum/go-ethereum/common"
31- "github.com/ethereum/go-ethereum/core/rawdb"
3231 "github.com/ethereum/go-ethereum/core/state/snapshot"
3332 "github.com/ethereum/go-ethereum/core/stateless"
3433 "github.com/ethereum/go-ethereum/core/tracing"
@@ -149,8 +148,7 @@ type StateDB struct {
149148 StorageReads time.Duration
150149 StorageUpdates time.Duration
151150 StorageCommits time.Duration
152- SnapshotCommits time.Duration
153- TrieDBCommits time.Duration
151+ DatabaseCommits time.Duration
154152
155153 AccountLoaded int // Number of accounts retrieved from the database during the state transition
156154 AccountUpdated int // Number of accounts updated during the state transition
@@ -1160,7 +1158,7 @@ func (s *StateDB) GetTrie() Trie {
11601158
11611159// commit gathers the state mutations accumulated along with the associated
11621160// trie changes, resetting all internal flags with the new state as the base.
1163- func (s * StateDB ) commit (deleteEmptyObjects bool , noStorageWiping bool , blockNumber uint64 ) (* stateUpdate , error ) {
1161+ func (s * StateDB ) commit (deleteEmptyObjects bool , rawStorageKey bool , blockNumber uint64 ) (* stateUpdate , error ) {
11641162 // Short circuit in case any database failure occurred earlier.
11651163 if s .dbErr != nil {
11661164 return nil , fmt .Errorf ("commit aborted due to earlier error: %v" , s .dbErr )
@@ -1214,7 +1212,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool, noStorageWiping bool, blockNum
12141212 // the same block, account deletions must be processed first. This ensures
12151213 // that the storage trie nodes deleted during destruction and recreated
12161214 // during subsequent resurrection can be combined correctly.
1217- deletes , delNodes , err := s .handleDestruction (noStorageWiping )
1215+ deletes , delNodes , err := s .handleDestruction (rawStorageKey )
12181216 if err != nil {
12191217 return nil , err
12201218 }
@@ -1308,57 +1306,19 @@ func (s *StateDB) commit(deleteEmptyObjects bool, noStorageWiping bool, blockNum
13081306 // Clear all internal flags and update state root at the end.
13091307 s .mutations = make (map [common.Address ]* mutation )
13101308 s .stateObjectsDestruct = make (map [common.Address ]* stateObject )
1309+ s .reader , _ = s .db .Reader (root )
13111310
13121311 origin := s .originalRoot
13131312 s .originalRoot = root
13141313
1315- return newStateUpdate (noStorageWiping , origin , root , blockNumber , deletes , updates , nodes ), nil
1316- }
1314+ update := newStateUpdate (rawStorageKey , origin , root , blockNumber , deletes , updates , nodes )
13171315
1318- // commitAndFlush is a wrapper of commit which also commits the state mutations
1319- // to the configured data stores.
1320- func (s * StateDB ) commitAndFlush (block uint64 , deleteEmptyObjects bool , noStorageWiping bool ) (* stateUpdate , error ) {
1321- ret , err := s .commit (deleteEmptyObjects , noStorageWiping , block )
1322- if err != nil {
1316+ start = time .Now ()
1317+ if err := s .db .Commit (update ); err != nil {
13231318 return nil , err
13241319 }
1325- // Commit dirty contract code if any exists
1326- if db := s .db .TrieDB ().Disk (); db != nil && len (ret .codes ) > 0 {
1327- batch := db .NewBatch ()
1328- for _ , code := range ret .codes {
1329- rawdb .WriteCode (batch , code .hash , code .blob )
1330- }
1331- if err := batch .Write (); err != nil {
1332- return nil , err
1333- }
1334- }
1335- if ! ret .empty () {
1336- // If snapshotting is enabled, update the snapshot tree with this new version
1337- if snap := s .db .Snapshot (); snap != nil && snap .Snapshot (ret .originRoot ) != nil {
1338- start := time .Now ()
1339- if err := snap .Update (ret .root , ret .originRoot , ret .accounts , ret .storages ); err != nil {
1340- log .Warn ("Failed to update snapshot tree" , "from" , ret .originRoot , "to" , ret .root , "err" , err )
1341- }
1342- // Keep 128 diff layers in the memory, persistent layer is 129th.
1343- // - head layer is paired with HEAD state
1344- // - head-1 layer is paired with HEAD-1 state
1345- // - head-127 layer(bottom-most diff layer) is paired with HEAD-127 state
1346- if err := snap .Cap (ret .root , TriesInMemory ); err != nil {
1347- log .Warn ("Failed to cap snapshot tree" , "root" , ret .root , "layers" , TriesInMemory , "err" , err )
1348- }
1349- s .SnapshotCommits += time .Since (start )
1350- }
1351- // If trie database is enabled, commit the state update as a new layer
1352- if db := s .db .TrieDB (); db != nil {
1353- start := time .Now ()
1354- if err := db .Update (ret .root , ret .originRoot , block , ret .nodes , ret .stateSet ()); err != nil {
1355- return nil , err
1356- }
1357- s .TrieDBCommits += time .Since (start )
1358- }
1359- }
1360- s .reader , _ = s .db .Reader (s .originalRoot )
1361- return ret , err
1320+ s .DatabaseCommits = time .Since (start )
1321+ return update , nil
13621322}
13631323
13641324// Commit writes the state mutations into the configured data stores.
@@ -1375,8 +1335,8 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool, noStorag
13751335// Since self-destruction was deprecated with the Cancun fork and there are
13761336// no empty accounts left that could be deleted by EIP-158, storage wiping
13771337// should not occur.
1378- func (s * StateDB ) Commit (block uint64 , deleteEmptyObjects bool , noStorageWiping bool ) (common.Hash , error ) {
1379- ret , err := s .commitAndFlush ( block , deleteEmptyObjects , noStorageWiping )
1338+ func (s * StateDB ) Commit (blockNumber uint64 , deleteEmptyObjects bool , rawStorageKey bool ) (common.Hash , error ) {
1339+ ret , err := s .commit ( deleteEmptyObjects , rawStorageKey , blockNumber )
13801340 if err != nil {
13811341 return common.Hash {}, err
13821342 }
@@ -1385,8 +1345,8 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool, noStorageWiping
13851345
13861346// CommitWithUpdate writes the state mutations and returns both the root hash and the state update.
13871347// This is useful for tracking state changes at the blockchain level.
1388- func (s * StateDB ) CommitWithUpdate (block uint64 , deleteEmptyObjects bool , noStorageWiping bool ) (common.Hash , * stateUpdate , error ) {
1389- ret , err := s .commitAndFlush ( block , deleteEmptyObjects , noStorageWiping )
1348+ func (s * StateDB ) CommitWithUpdate (blockNumber uint64 , deleteEmptyObjects bool , rawStorageKey bool ) (common.Hash , * stateUpdate , error ) {
1349+ ret , err := s .commit ( deleteEmptyObjects , rawStorageKey , blockNumber )
13901350 if err != nil {
13911351 return common.Hash {}, nil , err
13921352 }
0 commit comments