diff options
author | obscuren <geffobscura@gmail.com> | 2014-07-03 22:07:21 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-07-03 22:07:21 +0800 |
commit | 8baa0f84e70aafa3882ec477d3b3d401d462958b (patch) | |
tree | 954a7a8dc9dac2e8235db5f17dc533ddcfc58974 | |
parent | 5d6713920625b82df2b55728b2cbb9f7f3df2025 (diff) | |
download | go-tangerine-8baa0f84e70aafa3882ec477d3b3d401d462958b.tar.gz go-tangerine-8baa0f84e70aafa3882ec477d3b3d401d462958b.tar.zst go-tangerine-8baa0f84e70aafa3882ec477d3b3d401d462958b.zip |
Fixed reverting error
-rw-r--r-- | ethchain/state.go | 8 | ||||
-rw-r--r-- | ethchain/state_object.go | 5 | ||||
-rw-r--r-- | ethchain/state_transition.go | 41 | ||||
-rw-r--r-- | ethchain/vm.go | 13 |
4 files changed, 29 insertions, 38 deletions
diff --git a/ethchain/state.go b/ethchain/state.go index 7ddf7916f..20af94fe8 100644 --- a/ethchain/state.go +++ b/ethchain/state.go @@ -157,9 +157,11 @@ func (self *State) Copy() *State { } func (self *State) Set(state *State) { - //s.trie = snapshot.trie - //s.stateObjects = snapshot.stateObjects - self = state + if state == nil { + panic("Tried setting 'state' to nil through 'Set'") + } + + *self = *state } func (s *State) Put(key, object []byte) { diff --git a/ethchain/state_object.go b/ethchain/state_object.go index cc9a801f9..b9d994321 100644 --- a/ethchain/state_object.go +++ b/ethchain/state_object.go @@ -191,13 +191,12 @@ func (self *StateObject) Copy() *StateObject { } stateObject.script = ethutil.CopyBytes(self.script) stateObject.initScript = ethutil.CopyBytes(self.initScript) - //stateObject.gasPool.Set(self.gasPool) - return self + return stateObject } func (self *StateObject) Set(stateObject *StateObject) { - self = stateObject + *self = *stateObject } // diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go index 31196d2d7..16e1f124b 100644 --- a/ethchain/state_transition.go +++ b/ethchain/state_transition.go @@ -192,6 +192,8 @@ func (self *StateTransition) TransitionState() (err error) { return } + //snapshot := self.state.Copy() + // Process the init code and create 'valid' contract if IsContractAddr(self.receiver) { // Evaluate the initialization script @@ -199,22 +201,25 @@ func (self *StateTransition) TransitionState() (err error) { // script section for the state object. self.data = nil - code, err, deepErr := self.Eval(receiver.Init(), receiver) - if err != nil || deepErr { + statelogger.Debugln("~> init") + code, err := self.Eval(receiver.Init(), receiver) + if err != nil { + //self.state.Set(snapshot) self.state.ResetStateObject(receiver) - return fmt.Errorf("Error during init script run %v (deepErr = %v)", err, deepErr) + return fmt.Errorf("Error during init execution %v", err) } receiver.script = code } else { if len(receiver.Script()) > 0 { - var deepErr bool - _, err, deepErr = self.Eval(receiver.Script(), receiver) + statelogger.Debugln("~> code") + _, err = self.Eval(receiver.Script(), receiver) if err != nil { + //self.state.Set(snapshot) self.state.ResetStateObject(receiver) - return fmt.Errorf("Error during code execution %v (deepErr = %v)", err, deepErr) + return fmt.Errorf("Error during code execution %v", err) } } } @@ -235,7 +240,7 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error return nil } -func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []byte, err error, deepErr bool) { +func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []byte, err error) { var ( block = self.block initiator = self.Sender() @@ -255,14 +260,13 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by }) vm.Verbose = true - ret, err, deepErr = Call(vm, closure, self.data) + ret, err = Call(vm, closure, self.data) return } -func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr bool) { +func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error) { ret, _, err = closure.Call(vm, data) - deepErr = vm.err != nil if ethutil.Config.Paranoia { var ( @@ -274,21 +278,8 @@ func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr if !valid { // TODO FIXME ASAP context.state.trie = t2 - /* - statelogger.Debugf("(o): %x\n", trie.Root) - trie.NewIterator().Each(func(key string, v *ethutil.Value) { - v.Decode() - statelogger.Debugf("%x : %x\n", key, v.Str()) - }) - - statelogger.Debugf("(c): %x\n", trie2.Root) - trie2.NewIterator().Each(func(key string, v *ethutil.Value) { - v.Decode() - statelogger.Debugf("%x : %x\n", key, v.Str()) - }) - */ - - //return nil, fmt.Errorf("PARANOIA: Different state object roots during copy"), false + + statelogger.Debugln("Warn: PARANOIA: Different state object roots during copy") } } diff --git a/ethchain/vm.go b/ethchain/vm.go index 35443a6ba..97379f8ea 100644 --- a/ethchain/vm.go +++ b/ethchain/vm.go @@ -82,7 +82,7 @@ func (self *Vm) Printf(format string, v ...interface{}) *Vm { func (self *Vm) Endl() *Vm { if self.Verbose { - vmlogger.Infoln(self.logStr) + vmlogger.Debugln(self.logStr) self.logStr = "" } @@ -652,7 +652,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) { c := NewClosure(closure, contract, contract.initScript, vm.state, gas, closure.Price) // Call the closure and set the return value as // main script. - contract.script, err, _ = Call(vm, c, nil) + contract.script, err = Call(vm, c, nil) } else { err = fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", value, closure.object.Amount) } @@ -690,25 +690,24 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) { stack.Push(ethutil.BigFalse) } else { - snapshot := vm.state.Copy() + //snapshot := vm.state.Copy() stateObject := vm.state.GetOrNewStateObject(addr.Bytes()) closure.object.SubAmount(value) - // Add the value to the state object stateObject.AddAmount(value) // Create a new callable closure closure := NewClosure(closure, stateObject, stateObject.script, vm.state, gas, closure.Price) // Executer the closure and get the return value (if any) - ret, err, _ := Call(vm, closure, args) + ret, err := Call(vm, closure, args) if err != nil { stack.Push(ethutil.BigFalse) vmlogger.Debugf("Closure execution failed. %v\n", err) - vm.err = err - vm.state.Set(snapshot) + //vm.state.Set(snapshot) + vm.state.ResetStateObject(stateObject) } else { stack.Push(ethutil.BigTrue) |