mirror of https://github.com/status-im/op-geth.git
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) {
|
||||
//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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue