aboutsummaryrefslogtreecommitdiffstats
path: root/state
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-20 05:33:22 +0800
committerobscuren <geffobscura@gmail.com>2015-02-20 05:33:22 +0800
commitfa4cbad315609e41d88c59ecbce7c6c6169fc57a (patch)
tree5af4a3cfd497e682e41898059571b75f6f8e4cf9 /state
parentc14071df9da4ab3f5b372293e87184af9b91c09e (diff)
downloadgo-tangerine-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar
go-tangerine-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.gz
go-tangerine-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.bz2
go-tangerine-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.lz
go-tangerine-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.xz
go-tangerine-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.zst
go-tangerine-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.zip
Optimisations and fixed a couple of DDOS issues in the miner
Diffstat (limited to 'state')
-rw-r--r--state/state_object.go4
-rw-r--r--state/statedb.go45
2 files changed, 29 insertions, 20 deletions
diff --git a/state/state_object.go b/state/state_object.go
index eaa91c713..d50c9fd7a 100644
--- a/state/state_object.go
+++ b/state/state_object.go
@@ -53,6 +53,7 @@ type StateObject struct {
// When an object is marked for deletion it will be delete from the trie
// during the "update" phase of the state transition
remove bool
+ dirty bool
}
func (self *StateObject) Reset() {
@@ -211,6 +212,8 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
return GasLimitError(self.gasPool, gas)
}
+ self.gasPool.Sub(self.gasPool, gas)
+
rGas := new(big.Int).Set(gas)
rGas.Mul(rGas, price)
@@ -241,6 +244,7 @@ func (self *StateObject) Copy() *StateObject {
stateObject.storage = self.storage.Copy()
stateObject.gasPool.Set(self.gasPool)
stateObject.remove = self.remove
+ stateObject.dirty = self.dirty
return stateObject
}
diff --git a/state/statedb.go b/state/statedb.go
index c83d59ed7..8c8a21db9 100644
--- a/state/statedb.go
+++ b/state/statedb.go
@@ -78,43 +78,45 @@ func (self *StateDB) GetNonce(addr []byte) uint64 {
return 0
}
-func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
+func (self *StateDB) GetCode(addr []byte) []byte {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
- stateObject.Nonce = nonce
+ return stateObject.Code
}
+
+ return nil
}
-func (self *StateDB) GetCode(addr []byte) []byte {
- stateObject := self.GetStateObject(addr)
+func (self *StateDB) GetState(a, b []byte) []byte {
+ stateObject := self.GetStateObject(a)
if stateObject != nil {
- return stateObject.Code
+ return stateObject.GetState(b).Bytes()
}
return nil
}
-func (self *StateDB) SetCode(addr, code []byte) {
+func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
- stateObject.SetCode(code)
+ stateObject.Nonce = nonce
+ stateObject.dirty = true
}
}
-// TODO vars
-func (self *StateDB) GetState(a, b []byte) []byte {
- stateObject := self.GetStateObject(a)
+func (self *StateDB) SetCode(addr, code []byte) {
+ stateObject := self.GetStateObject(addr)
if stateObject != nil {
- return stateObject.GetState(b).Bytes()
+ stateObject.SetCode(code)
+ stateObject.dirty = true
}
-
- return nil
}
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
stateObject.SetState(key, ethutil.NewValue(value))
+ stateObject.dirty = true
}
}
@@ -122,6 +124,7 @@ func (self *StateDB) Delete(addr []byte) bool {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
stateObject.MarkForDeletion()
+ stateObject.dirty = true
return true
}
@@ -282,16 +285,18 @@ func (self *StateDB) Refunds() map[string]*big.Int {
}
func (self *StateDB) Update(gasUsed *big.Int) {
-
self.refund = make(map[string]*big.Int)
for _, stateObject := range self.stateObjects {
- if stateObject.remove {
- self.DeleteStateObject(stateObject)
- } else {
- stateObject.Sync()
-
- self.UpdateStateObject(stateObject)
+ if stateObject.dirty {
+ if stateObject.remove {
+ self.DeleteStateObject(stateObject)
+ } else {
+ stateObject.Sync()
+
+ self.UpdateStateObject(stateObject)
+ }
+ stateObject.dirty = false
}
}
}