diff --git a/core/blockchain.go b/core/blockchain.go index fec5410ae2..b57eb48e3a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -214,8 +214,6 @@ func (self *BlockChain) loadLastState() error { return err } self.stateCache = statedb - // XXX Reviewers: what's this for? I need to know if I need to backport this somehow - //self.stateCache.GetAccount(common.Address{}) // Issue a status log for the user headerTd := self.GetTd(currentHeader.Hash(), currentHeader.Number.Uint64()) diff --git a/core/state/state_object.go b/core/state/state_object.go index de5bec09f0..4fb69b6462 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -381,19 +381,3 @@ func (self *stateObject) Nonce() uint64 { func (self *stateObject) Value() *big.Int { panic("Value on stateObject should never be called") } - -func (self *stateObject) ForEachStorage(cb func(key, value common.Hash) bool) { - // When iterating over the storage check the cache first - for h, value := range self.cachedStorage { - cb(h, value) - } - - it := self.getTrie(self.db.db).Iterator() - for it.Next() { - // ignore cached values - key := common.BytesToHash(self.trie.GetKey(it.Key)) - if _, ok := self.cachedStorage[key]; !ok { - cb(key, common.BytesToHash(it.Value)) - } - } -} diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index 0cb2ad15a0..597de3be53 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -332,11 +332,10 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error { checkeq("GetCodeSize", state.GetCodeSize(addr), checkstate.GetCodeSize(addr)) // Check storage. if obj := state.getStateObject(addr); obj != nil { - obj.ForEachStorage(func(key, val common.Hash) bool { + state.ForEachStorage(addr, func(key, val common.Hash) bool { return checkeq("GetState("+key.Hex()+")", val, checkstate.GetState(addr, key)) }) - checkobj := checkstate.getStateObject(addr) - checkobj.ForEachStorage(func(key, checkval common.Hash) bool { + checkstate.ForEachStorage(addr, func(key, checkval common.Hash) bool { return checkeq("GetState("+key.Hex()+")", state.GetState(addr, key), checkval) }) } diff --git a/core/state_transition.go b/core/state_transition.go index 9be0e923ae..6acc784793 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -142,7 +142,7 @@ func (self *StateTransition) from() vm.AccountRef { if !self.state.Exist(f) { self.state.CreateAccount(f) } - return vm.Reference(f) + return vm.AccountRef(f) } func (self *StateTransition) to() vm.AccountRef { @@ -154,7 +154,7 @@ func (self *StateTransition) to() vm.AccountRef { return vm.AccountRef{} // contract creation } - reference := vm.Reference(*to) + reference := vm.AccountRef(*to) if !self.state.Exist(*to) { self.state.CreateAccount(*to) } diff --git a/core/vm/contract.go b/core/vm/contract.go index 5b9b8ee30b..66748e8215 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -39,9 +39,6 @@ type AccountRef common.Address // Address casts AccountRef to a Address func (ar AccountRef) Address() common.Address { return (common.Address)(ar) } -// Reference returns a casted Address to AccountRef -func Reference(addr common.Address) AccountRef { return (AccountRef)(addr) } - // Contract represents an ethereum contract in the state database. It contains // the the contract code, calling arguments. Contract implements ContractRef type Contract struct { diff --git a/core/vm/evm.go b/core/vm/evm.go index 4868f61b22..d1fac6c103 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -116,7 +116,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas } var ( - to = Reference(addr) + to = AccountRef(addr) snapshot = evm.StateDB.Snapshot() ) if !evm.StateDB.Exist(addr) { @@ -167,7 +167,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, var ( snapshot = evm.StateDB.Snapshot() - to = Reference(caller.Address()) + to = AccountRef(caller.Address()) ) // initialise a new contract and set the code that is to be used by the // E The contract is a scoped evmironment for this execution context @@ -203,7 +203,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by var ( snapshot = evm.StateDB.Snapshot() - to = Reference(caller.Address()) + to = AccountRef(caller.Address()) ) // Iinitialise a new contract and make initialise the delegate values @@ -250,7 +250,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I // initialise a new contract and set the code that is to be used by the // E The contract is a scoped evmironment for this execution context // only. - contract := NewContract(caller, Reference(contractAddr), value, gas) + contract := NewContract(caller, AccountRef(contractAddr), value, gas) contract.SetCallCode(&contractAddr, crypto.Keccak256Hash(code), code) ret, err = evm.interpreter.Run(contract, nil) diff --git a/core/vm/noop.go b/core/vm/noop.go index 805d90f181..2a04a95654 100644 --- a/core/vm/noop.go +++ b/core/vm/noop.go @@ -45,25 +45,26 @@ func (NoopEVMCallContext) DelegateCall(me ContractRef, addr common.Address, data type NoopStateDB struct{} -func (NoopStateDB) CreateAccount(common.Address) {} -func (NoopStateDB) SubBalance(common.Address, *big.Int) {} -func (NoopStateDB) AddBalance(common.Address, *big.Int) {} -func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil } -func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 } -func (NoopStateDB) SetNonce(common.Address, uint64) {} -func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} } -func (NoopStateDB) GetCode(common.Address) []byte { return nil } -func (NoopStateDB) SetCode(common.Address, []byte) {} -func (NoopStateDB) GetCodeSize(common.Address) int { return 0 } -func (NoopStateDB) AddRefund(*big.Int) {} -func (NoopStateDB) GetRefund() *big.Int { return nil } -func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} } -func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {} -func (NoopStateDB) Suicide(common.Address) bool { return false } -func (NoopStateDB) HasSuicided(common.Address) bool { return false } -func (NoopStateDB) Exist(common.Address) bool { return false } -func (NoopStateDB) Empty(common.Address) bool { return false } -func (NoopStateDB) RevertToSnapshot(int) {} -func (NoopStateDB) Snapshot() int { return 0 } -func (NoopStateDB) AddLog(*types.Log) {} -func (NoopStateDB) AddPreimage(common.Hash, []byte) {} +func (NoopStateDB) CreateAccount(common.Address) {} +func (NoopStateDB) SubBalance(common.Address, *big.Int) {} +func (NoopStateDB) AddBalance(common.Address, *big.Int) {} +func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil } +func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 } +func (NoopStateDB) SetNonce(common.Address, uint64) {} +func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} } +func (NoopStateDB) GetCode(common.Address) []byte { return nil } +func (NoopStateDB) SetCode(common.Address, []byte) {} +func (NoopStateDB) GetCodeSize(common.Address) int { return 0 } +func (NoopStateDB) AddRefund(*big.Int) {} +func (NoopStateDB) GetRefund() *big.Int { return nil } +func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} } +func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {} +func (NoopStateDB) Suicide(common.Address) bool { return false } +func (NoopStateDB) HasSuicided(common.Address) bool { return false } +func (NoopStateDB) Exist(common.Address) bool { return false } +func (NoopStateDB) Empty(common.Address) bool { return false } +func (NoopStateDB) RevertToSnapshot(int) {} +func (NoopStateDB) Snapshot() int { return 0 } +func (NoopStateDB) AddLog(*types.Log) {} +func (NoopStateDB) AddPreimage(common.Hash, []byte) {} +func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {} diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 65a6291a16..94265626f2 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -107,7 +107,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) { var ( address = common.StringToAddress("contract") vmenv = NewEnv(cfg, cfg.State) - sender = vm.Reference(cfg.Origin) + sender = vm.AccountRef(cfg.Origin) ) cfg.State.CreateAccount(address) // set the receiver's (the executing contract) code for execution. @@ -137,7 +137,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, error) { } var ( vmenv = NewEnv(cfg, cfg.State) - sender = vm.Reference(cfg.Origin) + sender = vm.AccountRef(cfg.Origin) ) // Call the code with the given configuration.