mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
This commit is contained in:
parent
7267895b82
commit
b743f7c61f
1 changed files with 8 additions and 33 deletions
|
|
@ -64,13 +64,6 @@ type stateObject struct {
|
||||||
addrHash common.Hash // hash of ethereum address of the account
|
addrHash common.Hash // hash of ethereum address of the account
|
||||||
data types.StateAccount // Account data with all mutations applied in the scope of block
|
data types.StateAccount // Account data with all mutations applied in the scope of block
|
||||||
|
|
||||||
// DB error.
|
|
||||||
// State objects are used by the consensus core and VM which are
|
|
||||||
// unable to deal with database-level errors. Any error that occurs
|
|
||||||
// during a database read is memoized here and will eventually be returned
|
|
||||||
// by StateDB.Commit.
|
|
||||||
dbErr error
|
|
||||||
|
|
||||||
// Write caches.
|
// Write caches.
|
||||||
trie Trie // storage trie, which becomes non-nil on first access
|
trie Trie // storage trie, which becomes non-nil on first access
|
||||||
code Code // contract bytecode, which gets set when code is loaded
|
code Code // contract bytecode, which gets set when code is loaded
|
||||||
|
|
@ -127,13 +120,6 @@ func (s *stateObject) EncodeRLP(w io.Writer) error {
|
||||||
return rlp.Encode(w, &s.data)
|
return rlp.Encode(w, &s.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// setError remembers the first non-nil error it is called with.
|
|
||||||
func (s *stateObject) setError(err error) {
|
|
||||||
if s.dbErr == nil {
|
|
||||||
s.dbErr = err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *stateObject) markSelfdestructed() {
|
func (s *stateObject) markSelfdestructed() {
|
||||||
s.selfDestructed = true
|
s.selfDestructed = true
|
||||||
}
|
}
|
||||||
|
|
@ -196,20 +182,20 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
|
||||||
// Otherwise load the value from the database
|
// Otherwise load the value from the database
|
||||||
tr, err := s.getTrie(db)
|
tr, err := s.getTrie(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(err)
|
s.db.setError(err)
|
||||||
return common.Hash{}
|
return common.Hash{}
|
||||||
}
|
}
|
||||||
enc, err := tr.GetStorage(s.address, key.Bytes())
|
enc, err := tr.GetStorage(s.address, key.Bytes())
|
||||||
s.db.StorageReads += time.Since(start)
|
s.db.StorageReads += time.Since(start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(err)
|
s.db.setError(err)
|
||||||
return common.Hash{}
|
return common.Hash{}
|
||||||
}
|
}
|
||||||
var value common.Hash
|
var value common.Hash
|
||||||
if len(enc) > 0 {
|
if len(enc) > 0 {
|
||||||
_, content, _, err := rlp.Split(enc)
|
_, content, _, err := rlp.Split(enc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(err)
|
s.db.setError(err)
|
||||||
}
|
}
|
||||||
value.SetBytes(content)
|
value.SetBytes(content)
|
||||||
}
|
}
|
||||||
|
|
@ -263,7 +249,7 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
|
||||||
defer func(start time.Time) { s.db.StorageUpdates += time.Since(start) }(time.Now())
|
defer func(start time.Time) { s.db.StorageUpdates += time.Since(start) }(time.Now())
|
||||||
tr, err := s.getTrie(db)
|
tr, err := s.getTrie(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(err)
|
s.db.setError(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Insert all the pending updates into the trie
|
// Insert all the pending updates into the trie
|
||||||
|
|
@ -276,7 +262,7 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
|
||||||
|
|
||||||
if (value == common.Hash{}) {
|
if (value == common.Hash{}) {
|
||||||
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
||||||
s.setError(err)
|
s.db.setError(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.db.StorageDeleted += 1
|
s.db.StorageDeleted += 1
|
||||||
|
|
@ -284,7 +270,7 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
|
||||||
// Encoding []byte cannot fail, ok to ignore the error.
|
// Encoding []byte cannot fail, ok to ignore the error.
|
||||||
v, _ := rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))
|
v, _ := rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))
|
||||||
if err := tr.UpdateStorage(s.address, key[:], v); err != nil {
|
if err := tr.UpdateStorage(s.address, key[:], v); err != nil {
|
||||||
s.setError(err)
|
s.db.setError(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.db.StorageUpdated += 1
|
s.db.StorageUpdated += 1
|
||||||
|
|
@ -301,7 +287,6 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
|
||||||
func (s *stateObject) updateRoot(db Database) {
|
func (s *stateObject) updateRoot(db Database) {
|
||||||
tr, err := s.updateTrie(db)
|
tr, err := s.updateTrie(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(fmt.Errorf("updateRoot (%x) error: %w", s.address, err))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If nothing changed, don't bother with hashing anything
|
// If nothing changed, don't bother with hashing anything
|
||||||
|
|
@ -321,9 +306,6 @@ func (s *stateObject) commitTrie(db Database) (*trie.NodeSet, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if s.dbErr != nil {
|
|
||||||
return nil, s.dbErr
|
|
||||||
}
|
|
||||||
// If nothing changed, don't bother with hashing anything
|
// If nothing changed, don't bother with hashing anything
|
||||||
if tr == nil {
|
if tr == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -399,7 +381,7 @@ func (s *stateObject) Code(db Database) []byte {
|
||||||
}
|
}
|
||||||
code, err := db.ContractCode(s.addrHash, common.BytesToHash(s.CodeHash()))
|
code, err := db.ContractCode(s.addrHash, common.BytesToHash(s.CodeHash()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(fmt.Errorf("can't load code hash %x: %v", s.CodeHash(), err))
|
s.db.setError(fmt.Errorf("can't load code hash %x: %v", s.CodeHash(), err))
|
||||||
}
|
}
|
||||||
s.code = code
|
s.code = code
|
||||||
return code
|
return code
|
||||||
|
|
@ -417,7 +399,7 @@ func (s *stateObject) CodeSize(db Database) int {
|
||||||
}
|
}
|
||||||
size, err := db.ContractCodeSize(s.addrHash, common.BytesToHash(s.CodeHash()))
|
size, err := db.ContractCodeSize(s.addrHash, common.BytesToHash(s.CodeHash()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.setError(fmt.Errorf("can't load code size %x: %v", s.CodeHash(), err))
|
s.db.setError(fmt.Errorf("can't load code size %x: %v", s.CodeHash(), err))
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
@ -462,10 +444,3 @@ func (s *stateObject) Nonce() uint64 {
|
||||||
func (s *stateObject) Root() common.Hash {
|
func (s *stateObject) Root() common.Hash {
|
||||||
return s.data.Root
|
return s.data.Root
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value is never called, but must be present to allow stateObject to be used
|
|
||||||
// as a vm.Account interface that also satisfies the vm.ContractRef
|
|
||||||
// interface. Interfaces are awesome.
|
|
||||||
func (s *stateObject) Value() *big.Int {
|
|
||||||
panic("Value on stateObject should never be called")
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue