forked from cerc-io/plugeth
Fixed reverting error
This commit is contained in:
parent
5d67139206
commit
8baa0f84e7
@ -157,9 +157,11 @@ func (self *State) Copy() *State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Set(state *State) {
|
func (self *State) Set(state *State) {
|
||||||
//s.trie = snapshot.trie
|
if state == nil {
|
||||||
//s.stateObjects = snapshot.stateObjects
|
panic("Tried setting 'state' to nil through 'Set'")
|
||||||
self = state
|
}
|
||||||
|
|
||||||
|
*self = *state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) Put(key, object []byte) {
|
func (s *State) Put(key, object []byte) {
|
||||||
|
@ -191,13 +191,12 @@ func (self *StateObject) Copy() *StateObject {
|
|||||||
}
|
}
|
||||||
stateObject.script = ethutil.CopyBytes(self.script)
|
stateObject.script = ethutil.CopyBytes(self.script)
|
||||||
stateObject.initScript = ethutil.CopyBytes(self.initScript)
|
stateObject.initScript = ethutil.CopyBytes(self.initScript)
|
||||||
//stateObject.gasPool.Set(self.gasPool)
|
|
||||||
|
|
||||||
return self
|
return stateObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateObject) Set(stateObject *StateObject) {
|
func (self *StateObject) Set(stateObject *StateObject) {
|
||||||
self = stateObject
|
*self = *stateObject
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -192,6 +192,8 @@ func (self *StateTransition) TransitionState() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//snapshot := self.state.Copy()
|
||||||
|
|
||||||
// Process the init code and create 'valid' contract
|
// Process the init code and create 'valid' contract
|
||||||
if IsContractAddr(self.receiver) {
|
if IsContractAddr(self.receiver) {
|
||||||
// Evaluate the initialization script
|
// Evaluate the initialization script
|
||||||
@ -199,22 +201,25 @@ func (self *StateTransition) TransitionState() (err error) {
|
|||||||
// script section for the state object.
|
// script section for the state object.
|
||||||
self.data = nil
|
self.data = nil
|
||||||
|
|
||||||
code, err, deepErr := self.Eval(receiver.Init(), receiver)
|
statelogger.Debugln("~> init")
|
||||||
if err != nil || deepErr {
|
code, err := self.Eval(receiver.Init(), receiver)
|
||||||
|
if err != nil {
|
||||||
|
//self.state.Set(snapshot)
|
||||||
self.state.ResetStateObject(receiver)
|
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
|
receiver.script = code
|
||||||
} else {
|
} else {
|
||||||
if len(receiver.Script()) > 0 {
|
if len(receiver.Script()) > 0 {
|
||||||
var deepErr bool
|
statelogger.Debugln("~> code")
|
||||||
_, err, deepErr = self.Eval(receiver.Script(), receiver)
|
_, err = self.Eval(receiver.Script(), receiver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
//self.state.Set(snapshot)
|
||||||
self.state.ResetStateObject(receiver)
|
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
|
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 (
|
var (
|
||||||
block = self.block
|
block = self.block
|
||||||
initiator = self.Sender()
|
initiator = self.Sender()
|
||||||
@ -255,14 +260,13 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
|
|||||||
})
|
})
|
||||||
vm.Verbose = true
|
vm.Verbose = true
|
||||||
|
|
||||||
ret, err, deepErr = Call(vm, closure, self.data)
|
ret, err = Call(vm, closure, self.data)
|
||||||
|
|
||||||
return
|
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)
|
ret, _, err = closure.Call(vm, data)
|
||||||
deepErr = vm.err != nil
|
|
||||||
|
|
||||||
if ethutil.Config.Paranoia {
|
if ethutil.Config.Paranoia {
|
||||||
var (
|
var (
|
||||||
@ -274,21 +278,8 @@ func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr
|
|||||||
if !valid {
|
if !valid {
|
||||||
// TODO FIXME ASAP
|
// TODO FIXME ASAP
|
||||||
context.state.trie = t2
|
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)
|
statelogger.Debugln("Warn: PARANOIA: Different state object roots during copy")
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ func (self *Vm) Printf(format string, v ...interface{}) *Vm {
|
|||||||
|
|
||||||
func (self *Vm) Endl() *Vm {
|
func (self *Vm) Endl() *Vm {
|
||||||
if self.Verbose {
|
if self.Verbose {
|
||||||
vmlogger.Infoln(self.logStr)
|
vmlogger.Debugln(self.logStr)
|
||||||
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)
|
c := NewClosure(closure, contract, contract.initScript, vm.state, gas, closure.Price)
|
||||||
// Call the closure and set the return value as
|
// Call the closure and set the return value as
|
||||||
// main script.
|
// main script.
|
||||||
contract.script, err, _ = Call(vm, c, nil)
|
contract.script, err = Call(vm, c, nil)
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", value, closure.object.Amount)
|
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)
|
stack.Push(ethutil.BigFalse)
|
||||||
} else {
|
} else {
|
||||||
snapshot := vm.state.Copy()
|
//snapshot := vm.state.Copy()
|
||||||
|
|
||||||
stateObject := vm.state.GetOrNewStateObject(addr.Bytes())
|
stateObject := vm.state.GetOrNewStateObject(addr.Bytes())
|
||||||
|
|
||||||
closure.object.SubAmount(value)
|
closure.object.SubAmount(value)
|
||||||
// Add the value to the state object
|
|
||||||
stateObject.AddAmount(value)
|
stateObject.AddAmount(value)
|
||||||
|
|
||||||
// Create a new callable closure
|
// Create a new callable closure
|
||||||
closure := NewClosure(closure, stateObject, stateObject.script, vm.state, gas, closure.Price)
|
closure := NewClosure(closure, stateObject, stateObject.script, vm.state, gas, closure.Price)
|
||||||
// Executer the closure and get the return value (if any)
|
// 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 {
|
if err != nil {
|
||||||
stack.Push(ethutil.BigFalse)
|
stack.Push(ethutil.BigFalse)
|
||||||
|
|
||||||
vmlogger.Debugf("Closure execution failed. %v\n", err)
|
vmlogger.Debugf("Closure execution failed. %v\n", err)
|
||||||
|
|
||||||
vm.err = err
|
//vm.state.Set(snapshot)
|
||||||
vm.state.Set(snapshot)
|
vm.state.ResetStateObject(stateObject)
|
||||||
} else {
|
} else {
|
||||||
stack.Push(ethutil.BigTrue)
|
stack.Push(ethutil.BigTrue)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user