diff --git a/core/state/reader.go b/core/state/reader.go index 4628f4d5db..6d5e74c7f4 100644 --- a/core/state/reader.go +++ b/core/state/reader.go @@ -41,14 +41,14 @@ type ContractCodeReader interface { // - Returns nil code along with nil error if the requested contract code // doesn't exist // - Returns an error only if an unexpected issue occurs - Code(addr common.Address, codeHash common.Hash) ([]byte, error) + Code(codeHash common.Hash) ([]byte, error) // CodeSize retrieves a particular contracts code's size. // // - Returns zero code size along with nil error if the requested contract code // doesn't exist // - Returns an error only if an unexpected issue occurs - CodeSize(addr common.Address, codeHash common.Hash) (int, error) + CodeSize(codeHash common.Hash) (int, error) } // StateReader defines the interface for accessing accounts and storage slots @@ -121,7 +121,7 @@ func newCachingCodeReader(db ethdb.KeyValueReader, codeCache *lru.SizeConstraine // Code implements ContractCodeReader, retrieving a particular contract's code. // If the contract code doesn't exist, no error will be returned. -func (r *cachingCodeReader) Code(addr common.Address, codeHash common.Hash) ([]byte, error) { +func (r *cachingCodeReader) Code(codeHash common.Hash) ([]byte, error) { code, _ := r.codeCache.Get(codeHash) if len(code) > 0 { return code, nil @@ -136,11 +136,11 @@ func (r *cachingCodeReader) Code(addr common.Address, codeHash common.Hash) ([]b // CodeSize implements ContractCodeReader, retrieving a particular contracts code's size. // If the contract code doesn't exist, no error will be returned. -func (r *cachingCodeReader) CodeSize(addr common.Address, codeHash common.Hash) (int, error) { +func (r *cachingCodeReader) CodeSize(codeHash common.Hash) (int, error) { if cached, ok := r.codeSizeCache.Get(codeHash); ok { return cached, nil } - code, err := r.Code(addr, codeHash) + code, err := r.Code(codeHash) if err != nil { return 0, err } diff --git a/core/state/statedb.go b/core/state/statedb.go index e805885079..5d66731edf 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -423,19 +423,12 @@ func (s *StateDB) HasSelfDestructed(addr common.Address) bool { // AddBalance adds amount to the account associated with addr. func (s *StateDB) AddBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int { - stateObject := s.getOrNewStateObject(addr) - if stateObject == nil { - return uint256.Int{} - } - return stateObject.AddBalance(amount) + return s.getOrNewStateObject(addr).AddBalance(amount) } // SubBalance subtracts amount from the account associated with addr. func (s *StateDB) SubBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int { stateObject := s.getOrNewStateObject(addr) - if stateObject == nil { - return uint256.Int{} - } if amount.IsZero() { return *(stateObject.Balance()) } @@ -443,32 +436,19 @@ func (s *StateDB) SubBalance(addr common.Address, amount *uint256.Int, reason tr } func (s *StateDB) SetBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason) { - stateObject := s.getOrNewStateObject(addr) - if stateObject != nil { - stateObject.SetBalance(amount) - } + s.getOrNewStateObject(addr).SetBalance(amount) } func (s *StateDB) SetNonce(addr common.Address, nonce uint64, reason tracing.NonceChangeReason) { - stateObject := s.getOrNewStateObject(addr) - if stateObject != nil { - stateObject.SetNonce(nonce) - } + s.getOrNewStateObject(addr).SetNonce(nonce) } func (s *StateDB) SetCode(addr common.Address, code []byte) (prev []byte) { - stateObject := s.getOrNewStateObject(addr) - if stateObject != nil { - return stateObject.SetCode(crypto.Keccak256Hash(code), code) - } - return nil + return s.getOrNewStateObject(addr).SetCode(crypto.Keccak256Hash(code), code) } func (s *StateDB) SetState(addr common.Address, key, value common.Hash) common.Hash { - if stateObject := s.getOrNewStateObject(addr); stateObject != nil { - return stateObject.SetState(key, value) - } - return common.Hash{} + return s.getOrNewStateObject(addr).SetState(key, value) } // SetStorage replaces the entire storage for the specified account with given