MCPcopy
hub / github.com/bnb-chain/bsc / updateStateObject

Method updateStateObject

core/state/statedb.go:699–726  ·  view source on GitHub ↗

Setting, updating & deleting state object methods. updateStateObject writes the given object to the trie.

(obj *stateObject)

Source from the content-addressed store, hash-verified

697
698// updateStateObject writes the given object to the trie.
699func (s *StateDB) updateStateObject(obj *stateObject) {
700 if s.noTrie {
701 return
702 }
703 // Track the amount of time wasted on updating the account from the trie
704 if metrics.EnabledExpensive {
705 defer func(start time.Time) { s.AccountUpdates += time.Since(start) }(time.Now())
706 }
707 // Encode the account and update the account trie
708 addr := obj.Address()
709 if err := s.trie.UpdateAccount(addr, &obj.data); err != nil {
710 s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
711 }
712 if obj.dirtyCode {
713 s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
714 }
715
716 // Track the original value of mutated account, nil means it was not present.
717 // Skip if it has been tracked (because updateStateObject may be called
718 // multiple times in a block).
719 if _, ok := s.accountsOrigin[obj.address]; !ok {
720 if obj.origin == nil {
721 s.accountsOrigin[obj.address] = nil
722 } else {
723 s.accountsOrigin[obj.address] = types.SlimAccountRLP(*obj.origin)
724 }
725 }
726}
727
728// deleteStateObject removes the given object from the state trie.
729func (s *StateDB) deleteStateObject(obj *stateObject) {

Callers 4

StateIntermediateRootMethod · 0.95
TestDumpFunction · 0.80
TestIterativeDumpFunction · 0.80
TestCopyFunction · 0.80

Calls 9

setErrorMethod · 0.95
BytesToHashFunction · 0.92
SlimAccountRLPFunction · 0.92
ErrorfMethod · 0.80
CodeHashMethod · 0.80
NowMethod · 0.65
AddressMethod · 0.65
UpdateAccountMethod · 0.65
UpdateContractCodeMethod · 0.65

Tested by 3

TestDumpFunction · 0.64
TestIterativeDumpFunction · 0.64
TestCopyFunction · 0.64