aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-19 05:38:51 +0800
committerobscuren <geffobscura@gmail.com>2014-12-19 05:38:51 +0800
commit332568379454dce6b1fb3c3e023a53d0c52cded0 (patch)
treecf7ba0c6cdc922d102ff2ffd08c6dc20e1af06ab
parentf7287c626e31e980d5b164935ae913db3855eb81 (diff)
downloaddexon-332568379454dce6b1fb3c3e023a53d0c52cded0.tar.gz
dexon-332568379454dce6b1fb3c3e023a53d0c52cded0.tar.zst
dexon-332568379454dce6b1fb3c3e023a53d0c52cded0.zip
Fixed refund model
-rw-r--r--core/state_transition.go10
-rw-r--r--state/state.go17
-rw-r--r--tests/vm/gh_test.go8
3 files changed, 18 insertions, 17 deletions
diff --git a/core/state_transition.go b/core/state_transition.go
index 34d8cca74..9e81ddf28 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -213,12 +213,10 @@ func MakeContract(msg Message, state *state.StateDB) *state.StateObject {
func (self *StateTransition) RefundGas() {
coinbaseSub := new(big.Int).Set(self.gas)
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
- for addr, refs := range self.state.Refunds() {
- for _, ref := range refs {
- coinbaseSub.Add(self.gas, ref)
- refund := ethutil.BigMin(uhalf, ref)
- self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice()))
- }
+ for addr, ref := range self.state.Refunds() {
+ refund := ethutil.BigMin(uhalf, ref)
+ coinbaseSub.Add(self.gas, refund)
+ self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice()))
}
coinbase, sender := self.Coinbase(), self.From()
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 {
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index 42dcc0ae1..ca63b90d3 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -77,11 +77,11 @@ func RunVmTest(p string, t *testing.T) {
tests := make(map[string]VmTest)
helper.CreateFileTests(t, p, &tests)
- helper.Logger.SetLogLevel(5)
+ //helper.Logger.SetLogLevel(5)
for name, test := range tests {
- if name != "ABAcalls1" {
- continue
- }
+ // if name != "refund50_1" {
+ // continue
+ // }
statedb := state.New(helper.NewTrie())
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)