From 1fb84d3c5f486ef0d42a21f3cd8416d6ef211604 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 10 Dec 2014 10:57:19 +0100 Subject: Fixed tests --- state/state_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'state') diff --git a/state/state_test.go b/state/state_test.go index 825d21fcc..28e4fc5da 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -9,7 +9,7 @@ import ( ) type StateSuite struct { - state *State + state *StateDB } var _ = checker.Suite(&StateSuite{}) -- cgit v1.2.3 From 198cc69357a0f25ae486a041786e1239c6f5ab0f Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 21:58:26 +0100 Subject: Gas corrections and vm fixes --- state/state.go | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'state') diff --git a/state/state.go b/state/state.go index ca3f2af9c..682e233c1 100644 --- a/state/state.go +++ b/state/state.go @@ -23,14 +23,14 @@ type StateDB struct { manifest *Manifest - refund map[string][]refund + refund map[string][]*big.Int logs Logs } // Create a new state from a given trie func New(trie *trie.Trie) *StateDB { - return &StateDB{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]refund)} + return &StateDB{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]*big.Int)} } func (self *StateDB) EmptyLogs() { @@ -55,12 +55,8 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int { return ethutil.Big0 } -type refund struct { - gas, price *big.Int -} - -func (self *StateDB) Refund(addr []byte, gas, price *big.Int) { - self.refund[string(addr)] = append(self.refund[string(addr)], refund{gas, price}) +func (self *StateDB) Refund(addr []byte, gas *big.Int) { + self.refund[string(addr)] = append(self.refund[string(addr)], gas) } func (self *StateDB) AddBalance(addr []byte, amount *big.Int) { @@ -273,23 +269,17 @@ func (s *StateDB) Sync() { func (self *StateDB) Empty() { self.stateObjects = make(map[string]*StateObject) - self.refund = make(map[string][]refund) + self.refund = make(map[string][]*big.Int) +} + +func (self *StateDB) Refunds() map[string][]*big.Int { + return self.refund } func (self *StateDB) Update(gasUsed *big.Int) { var deleted bool - // Refund any gas that's left - // XXX THIS WILL CHANGE IN POC8 - uhalf := new(big.Int).Div(gasUsed, ethutil.Big2) - for addr, refs := range self.refund { - for _, ref := range refs { - refund := ethutil.BigMin(uhalf, ref.gas) - - self.GetStateObject([]byte(addr)).AddBalance(refund.Mul(refund, ref.price)) - } - } - self.refund = make(map[string][]refund) + self.refund = make(map[string][]*big.Int) for _, stateObject := range self.stateObjects { if stateObject.remove { -- cgit v1.2.3 From 332568379454dce6b1fb3c3e023a53d0c52cded0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 22:38:51 +0100 Subject: Fixed refund model --- state/state.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'state') diff --git a/state/state.go b/state/state.go index 682e233c1..a8d611668 100644 --- a/state/state.go +++ b/state/state.go @@ -23,14 +23,14 @@ type StateDB struct { manifest *Manifest - refund map[string][]*big.Int + refund map[string]*big.Int logs Logs } // Create a new state from a given trie func New(trie *trie.Trie) *StateDB { - return &StateDB{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]*big.Int)} + return &StateDB{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string]*big.Int)} } func (self *StateDB) EmptyLogs() { @@ -56,7 +56,10 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int { } func (self *StateDB) Refund(addr []byte, gas *big.Int) { - self.refund[string(addr)] = append(self.refund[string(addr)], gas) + if self.refund[string(addr)] == nil { + self.refund[string(addr)] = new(big.Int) + } + self.refund[string(addr)].Add(self.refund[string(addr)], gas) } func (self *StateDB) AddBalance(addr []byte, amount *big.Int) { @@ -207,7 +210,7 @@ func (self *StateDB) Copy() *StateDB { } for addr, refund := range self.refund { - state.refund[addr] = refund + state.refund[addr] = new(big.Int).Set(refund) } logs := make(Logs, len(self.logs)) @@ -269,17 +272,17 @@ func (s *StateDB) Sync() { func (self *StateDB) Empty() { self.stateObjects = make(map[string]*StateObject) - self.refund = make(map[string][]*big.Int) + self.refund = make(map[string]*big.Int) } -func (self *StateDB) Refunds() map[string][]*big.Int { +func (self *StateDB) Refunds() map[string]*big.Int { return self.refund } func (self *StateDB) Update(gasUsed *big.Int) { var deleted bool - self.refund = make(map[string][]*big.Int) + self.refund = make(map[string]*big.Int) for _, stateObject := range self.stateObjects { if stateObject.remove { -- cgit v1.2.3 From 1508a23a6fe3cc50f718bfd6c62caae056534c09 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 20 Dec 2014 02:21:13 +0100 Subject: Minor updates on gas and removed/refactored old code. --- state/state.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'state') diff --git a/state/state.go b/state/state.go index a8d611668..f77da72f0 100644 --- a/state/state.go +++ b/state/state.go @@ -94,6 +94,13 @@ func (self *StateDB) GetCode(addr []byte) []byte { return nil } +func (self *StateDB) SetCode(addr, code []byte) { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + stateObject.SetCode(code) + } +} + func (self *StateDB) GetState(a, b []byte) []byte { stateObject := self.GetStateObject(a) if stateObject != nil { -- cgit v1.2.3