From fc3ee373ab3cd98857560f6da56389b7405d9710 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Tue, 4 Oct 2016 11:05:04 +0200 Subject: [PATCH] core: never use so directly --- core/execution.go | 4 ++-- core/state/dump.go | 18 ++++++++++++++++++ core/state/statedb.go | 11 +++-------- core/state_transition.go | 4 +++- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/core/execution.go b/core/execution.go index 5bc2146b00..7444900cbf 100644 --- a/core/execution.go +++ b/core/execution.go @@ -17,6 +17,7 @@ package core import ( + "fmt" "math/big" "github.com/ethereum/go-ethereum/common" @@ -71,8 +72,7 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A } if !env.CanTransfer(caller.Address(), value) { - caller.ReturnGas(gas, gasPrice) - + fmt.Println("insuf", value) return nil, common.Address{}, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", value, env.Db().GetBalance(caller.Address())) } diff --git a/core/state/dump.go b/core/state/dump.go index 58ecd852b7..d67e4f88d5 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -67,6 +67,24 @@ func (self *StateDB) RawDump() Dump { } dump.Accounts[common.Bytes2Hex(addr)] = account } + for addr, stateObject := range self.stateObjects { + account := DumpAccount{ + Balance: stateObject.data.Balance.String(), + Nonce: stateObject.data.Nonce, + Root: common.Bytes2Hex(stateObject.data.Root[:]), + CodeHash: common.Bytes2Hex(stateObject.data.CodeHash), + Code: common.Bytes2Hex(stateObject.Code(self.db)), + Storage: make(map[string]string), + } + storageIt := stateObject.getTrie(self.db).Iterator() + for storageIt.Next() { + account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value) + } + for storageAddr, value := range stateObject.cachedStorage { + account.Storage[storageAddr.Hex()] = value.Hex() + } + dump.Accounts[addr.Hex()] = account + } return dump } diff --git a/core/state/statedb.go b/core/state/statedb.go index 3980fade72..13738798eb 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -410,8 +410,6 @@ func (s *StateDB) GetOrNewStateObject(address common.Address) *StateObject { if !s.localStateObjects[address] { stateObject = stateObject.Copy(s.db, s.MarkStateObjectDirty) s.SetOwnedStateObject(address, stateObject) - //s.stateObjects[address] = stateObject - //s.localStateObjects[address] = true } return stateObject } @@ -421,8 +419,6 @@ func (s *StateDB) GetOrNewStateObject(address common.Address) *StateObject { stateObject.SetNonce(StartingNonce) s.SetOwnedStateObject(address, stateObject) - //s.stateObjects[address] = stateObject - //s.localStateObjects[address] = true } return stateObject } @@ -432,7 +428,6 @@ func (s *StateDB) GetStateObject(address common.Address) *StateObject { if account != nil { if s.stateObjects[address] == nil { s.SetStateObject(account) - //s.stateObjects[address] = account } return account } @@ -477,8 +472,8 @@ func (self *StateDB) CreateAccount(addr common.Address) vm.Account { } func (self *StateDB) Set(state *StateDB) { - self.lock.Lock() - defer self.lock.Unlock() + //self.lock.Lock() + //defer self.lock.Unlock() *self = *state /* @@ -641,7 +636,7 @@ func IntermediateRoot(state *StateDB) common.Hash { } } } - state.stateObjectsDirty = make(map[common.Address]struct{}) + //state.stateObjectsDirty = make(map[common.Address]struct{}) return state.trie.Hash() } diff --git a/core/state_transition.go b/core/state_transition.go index 7616df1986..e5ea774fa4 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -198,7 +198,9 @@ func (self *StateTransition) buyGas() error { } self.addGas(mgas) self.initialGas.Set(mgas) - sender.SubBalance(mgval) + + self.state.(*state.StateDB).SubBalance(sender.Address(), mgval) + // sender.SubBalance(mgval) return nil }