mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
core/state: separate hashes and committer, collapse on commit (#20481)
This commit is contained in:
parent
db4dc24094
commit
ff7bcf8d15
2 changed files with 14 additions and 5 deletions
|
|
@ -291,10 +291,13 @@ func (s *stateObject) finalise() {
|
|||
}
|
||||
|
||||
// updateTrie writes cached storage modifications into the object's storage trie.
|
||||
// It will return nil if the trie has not been loaded and no changes have been made
|
||||
func (s *stateObject) updateTrie(db Database) Trie {
|
||||
// Make sure all dirty slots are finalized into the pending storage area
|
||||
s.finalise()
|
||||
|
||||
if len(s.pendingStorage) == 0 {
|
||||
return s.trie
|
||||
}
|
||||
// Track the amount of time wasted on updating the storage trie
|
||||
defer func(start time.Time) { s.db.StorageUpdates += time.Since(start) }(time.Now())
|
||||
// Insert all the pending updates into the trie
|
||||
|
|
@ -322,8 +325,10 @@ func (s *stateObject) updateTrie(db Database) Trie {
|
|||
|
||||
// UpdateRoot sets the trie root to the current root hash of
|
||||
func (s *stateObject) updateRoot(db Database) {
|
||||
s.updateTrie(db)
|
||||
|
||||
// If nothing changed, don't bother with hashing anything
|
||||
if s.updateTrie(db) == nil {
|
||||
return
|
||||
}
|
||||
// Track the amount of time wasted on hashing the storage trie
|
||||
defer func(start time.Time) { s.db.StorageHashes += time.Since(start) }(time.Now())
|
||||
|
||||
|
|
@ -333,7 +338,10 @@ func (s *stateObject) updateRoot(db Database) {
|
|||
// CommitTrie the storage trie of the object to dwb.
|
||||
// This updates the trie root.
|
||||
func (s *stateObject) CommitTrie(db Database) error {
|
||||
s.updateTrie(db)
|
||||
// If nothing changed, don't bother with hashing anything
|
||||
if s.updateTrie(db) == nil {
|
||||
return nil
|
||||
}
|
||||
if s.dbErr != nil {
|
||||
return s.dbErr
|
||||
}
|
||||
|
|
|
|||
|
|
@ -342,7 +342,8 @@ func (s *StateDB) StorageTrie(addr common.Address) Trie {
|
|||
return nil
|
||||
}
|
||||
cpy := stateObject.deepCopy(s, nil)
|
||||
return cpy.updateTrie(s.db)
|
||||
cpy.updateTrie(s.db)
|
||||
return cpy.getTrie(s.db)
|
||||
}
|
||||
|
||||
func (s *StateDB) HasSelfDestructed(addr common.Address) bool {
|
||||
|
|
|
|||
Loading…
Reference in a new issue