aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-16 19:39:30 +0800
committerobscuren <geffobscura@gmail.com>2014-10-16 19:39:30 +0800
commit86f789333a7c509058412c8a7253117af74488cd (patch)
treeaeb87bc8f5ef583c152b5992a5d64a5c8b9cdfb0
parentfebec5ca4a059a3e3a5cc2b5fe0d14ba02492b95 (diff)
downloadgo-tangerine-86f789333a7c509058412c8a7253117af74488cd.tar.gz
go-tangerine-86f789333a7c509058412c8a7253117af74488cd.tar.zst
go-tangerine-86f789333a7c509058412c8a7253117af74488cd.zip
Moved state reset to defered function
-rw-r--r--ethvm/execution.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/ethvm/execution.go b/ethvm/execution.go
index 0550a8bf3..ce90ade15 100644
--- a/ethvm/execution.go
+++ b/ethvm/execution.go
@@ -28,6 +28,11 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
env := self.vm.Env()
snapshot := env.State().Copy()
+ defer func() {
+ if err != nil {
+ env.State().Set(snapshot)
+ }
+ }()
msg := env.State().Manifest().AddMessage(&ethstate.Message{
To: self.address, From: caller.Address(),
@@ -49,7 +54,7 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
caller.Object().SubAmount(self.value)
stateObject.AddAmount(self.value)
- // Precompiled contracts (address.go) 1, 2 & 3.
+ // Pre-compiled contracts (address.go) 1, 2 & 3.
naddr := ethutil.BigD(codeAddr).Uint64()
if p := Precompiled[naddr]; p != nil {
if self.gas.Cmp(p.Gas) >= 0 {
@@ -74,9 +79,5 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
}
}
- if err != nil {
- env.State().Set(snapshot)
- }
-
return
}