aboutsummaryrefslogtreecommitdiffstats
path: root/state
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-11-29 04:44:34 +0800
committerobscuren <geffobscura@gmail.com>2014-11-29 04:44:34 +0800
commit1bce02eff70db43b98d68fcd094fd2e15745b021 (patch)
treea69acb327b4f71d59b297ca778450c128dce85f8 /state
parent8cf9ed0ea588e97f2baf0f834248727e8fbca18f (diff)
parenta3559c5e1b469890bb8d71e9992175febaae31c7 (diff)
downloadgo-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar
go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar.gz
go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar.bz2
go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar.lz
go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar.xz
go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar.zst
go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.zip
Fixed merge
Diffstat (limited to 'state')
-rw-r--r--state/state.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/state/state.go b/state/state.go
index 3abf1545b..0a7f717fe 100644
--- a/state/state.go
+++ b/state/state.go
@@ -23,14 +23,14 @@ type State struct {
manifest *Manifest
- refund map[string]*big.Int
+ refund map[string][]refund
logs Logs
}
// Create a new state from a given trie
func New(trie *trie.Trie) *State {
- return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string]*big.Int)}
+ return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]refund)}
}
func (self *State) EmptyLogs() {
@@ -55,14 +55,12 @@ func (self *State) GetBalance(addr []byte) *big.Int {
return ethutil.Big0
}
-func (self *State) Refund(addr []byte, gas, price *big.Int) {
- amount := new(big.Int).Mul(gas, price)
-
- if self.refund[string(addr)] == nil {
- self.refund[string(addr)] = new(big.Int)
- }
+type refund struct {
+ gas, price *big.Int
+}
- self.refund[string(addr)].Add(self.refund[string(addr)], amount)
+func (self *State) Refund(addr []byte, gas, price *big.Int) {
+ self.refund[string(addr)] = append(self.refund[string(addr)], refund{gas, price})
}
func (self *State) AddBalance(addr []byte, amount *big.Int) {
@@ -276,15 +274,20 @@ func (s *State) Sync() {
func (self *State) Empty() {
self.stateObjects = make(map[string]*StateObject)
- self.refund = make(map[string]*big.Int)
+ self.refund = make(map[string][]refund)
}
-func (self *State) Update() {
+func (self *State) Update(gasUsed *big.Int) {
var deleted bool
// Refund any gas that's left
- for addr, amount := range self.refund {
- self.GetStateObject([]byte(addr)).AddBalance(amount)
+ 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))
+ }
}
for _, stateObject := range self.stateObjects {