mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 03:10:48 +00:00
Merge b2b84fe9be into dddbaa4bf3
This commit is contained in:
commit
e592d19d54
2 changed files with 39 additions and 23 deletions
|
|
@ -345,6 +345,8 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
||||||
// into a shortnode. This requires `B` to be resolved from disk.
|
// into a shortnode. This requires `B` to be resolved from disk.
|
||||||
// Whereas if the created node is handled first, then the collapse is avoided, and `B` is not resolved.
|
// Whereas if the created node is handled first, then the collapse is avoided, and `B` is not resolved.
|
||||||
var (
|
var (
|
||||||
|
keys = make([][]byte, 0, len(s.uncommittedStorage))
|
||||||
|
values = make([][]byte, 0, len(s.uncommittedStorage))
|
||||||
deletions []common.Hash
|
deletions []common.Hash
|
||||||
used = make([]common.Hash, 0, len(s.uncommittedStorage))
|
used = make([]common.Hash, 0, len(s.uncommittedStorage))
|
||||||
)
|
)
|
||||||
|
|
@ -360,17 +362,23 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (value != common.Hash{}) {
|
if (value != common.Hash{}) {
|
||||||
if err := tr.UpdateStorage(s.address, key[:], common.TrimLeftZeroes(value[:])); err != nil {
|
keys = append(keys, key.Bytes())
|
||||||
s.db.setError(err)
|
values = append(values, common.TrimLeftZeroes(value.Bytes()))
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
s.db.StorageUpdated.Add(1)
|
|
||||||
} else {
|
} else {
|
||||||
deletions = append(deletions, key)
|
deletions = append(deletions, key)
|
||||||
}
|
}
|
||||||
// Cache the items for preloading
|
// Cache the items for preloading
|
||||||
used = append(used, key) // Copy needed for closure
|
used = append(used, key) // Copy needed for closure
|
||||||
}
|
}
|
||||||
|
// Apply the updates in batch mode, allowing the trie nodes on the paths
|
||||||
|
// to be resolved concurrently.
|
||||||
|
if len(keys) > 0 {
|
||||||
|
if err := tr.UpdateStorageBatch(s.address, keys, values); err != nil {
|
||||||
|
s.db.setError(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
s.db.StorageUpdated.Add(int64(len(keys)))
|
||||||
|
}
|
||||||
for _, key := range deletions {
|
for _, key := range deletions {
|
||||||
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
||||||
s.db.setError(err)
|
s.db.setError(err)
|
||||||
|
|
|
||||||
|
|
@ -571,17 +571,6 @@ func (s *StateDB) GetTransientState(addr common.Address, key common.Hash) common
|
||||||
// Setting, updating & deleting state object methods.
|
// Setting, updating & deleting state object methods.
|
||||||
//
|
//
|
||||||
|
|
||||||
// updateStateObject writes the given object to the trie.
|
|
||||||
func (s *StateDB) updateStateObject(obj *stateObject) {
|
|
||||||
// Encode the account and update the account trie
|
|
||||||
if err := s.trie.UpdateAccount(obj.Address(), &obj.data, len(obj.code)); err != nil {
|
|
||||||
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", obj.Address(), err))
|
|
||||||
}
|
|
||||||
if obj.dirtyCode {
|
|
||||||
s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// deleteStateObject removes the given object from the state trie.
|
// deleteStateObject removes the given object from the state trie.
|
||||||
func (s *StateDB) deleteStateObject(addr common.Address) {
|
func (s *StateDB) deleteStateObject(addr common.Address) {
|
||||||
if err := s.trie.DeleteAccount(addr); err != nil {
|
if err := s.trie.DeleteAccount(addr); err != nil {
|
||||||
|
|
@ -1072,7 +1061,11 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
|
||||||
// into a shortnode. This requires `B` to be resolved from disk.
|
// into a shortnode. This requires `B` to be resolved from disk.
|
||||||
// Whereas if the created node is handled first, then the collapse is avoided, and `B` is not resolved.
|
// Whereas if the created node is handled first, then the collapse is avoided, and `B` is not resolved.
|
||||||
var (
|
var (
|
||||||
usedAddrs []common.Address
|
usedAddrs = make([]common.Address, 0, len(s.mutations))
|
||||||
|
updatedAddrs = make([]common.Address, 0, len(s.mutations))
|
||||||
|
accounts = make([]*types.StateAccount, 0, len(s.mutations))
|
||||||
|
codeLens = make([]int, 0, len(s.mutations))
|
||||||
|
dirtyCodeObjs []*stateObject
|
||||||
deletedAddrs []common.Address
|
deletedAddrs []common.Address
|
||||||
)
|
)
|
||||||
for addr, op := range s.mutations {
|
for addr, op := range s.mutations {
|
||||||
|
|
@ -1085,17 +1078,32 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
|
||||||
deletedAddrs = append(deletedAddrs, addr)
|
deletedAddrs = append(deletedAddrs, addr)
|
||||||
} else {
|
} else {
|
||||||
obj := s.stateObjects[addr]
|
obj := s.stateObjects[addr]
|
||||||
s.updateStateObject(obj)
|
updatedAddrs = append(updatedAddrs, addr)
|
||||||
s.AccountUpdated += 1
|
accounts = append(accounts, &obj.data)
|
||||||
|
codeLens = append(codeLens, len(obj.code))
|
||||||
|
|
||||||
// Count code writes post-Finalise so reverted CREATEs are excluded.
|
|
||||||
if obj.dirtyCode {
|
if obj.dirtyCode {
|
||||||
s.CodeUpdated += 1
|
dirtyCodeObjs = append(dirtyCodeObjs, obj)
|
||||||
s.CodeUpdateBytes += len(obj.code)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
usedAddrs = append(usedAddrs, addr) // Copy needed for closure
|
usedAddrs = append(usedAddrs, addr) // Copy needed for closure
|
||||||
}
|
}
|
||||||
|
// Apply the account updates in batch mode, allowing the trie nodes on the
|
||||||
|
// paths to be resolved concurrently.
|
||||||
|
if len(updatedAddrs) > 0 {
|
||||||
|
if err := s.trie.UpdateAccountBatch(updatedAddrs, accounts, codeLens); err != nil {
|
||||||
|
s.setError(fmt.Errorf("account update error: %v", err))
|
||||||
|
}
|
||||||
|
s.AccountUpdated += len(updatedAddrs)
|
||||||
|
}
|
||||||
|
// Apply the code updates after the account updates.
|
||||||
|
for _, obj := range dirtyCodeObjs {
|
||||||
|
s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
|
||||||
|
|
||||||
|
// Count code writes post-Finalise so reverted CREATEs are excluded.
|
||||||
|
s.CodeUpdated += 1
|
||||||
|
s.CodeUpdateBytes += len(obj.code)
|
||||||
|
}
|
||||||
for _, deletedAddr := range deletedAddrs {
|
for _, deletedAddr := range deletedAddrs {
|
||||||
s.deleteStateObject(deletedAddr)
|
s.deleteStateObject(deletedAddr)
|
||||||
s.AccountDeleted += 1
|
s.AccountDeleted += 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue