execComputation and applyMessage unification
This commit is contained in:
parent
be79bc8740
commit
b6587bddfd
|
@ -162,9 +162,9 @@ proc transferBalance(computation: var BaseComputation, opCode: static[Op]): bool
|
||||||
|
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc executeOpcodes*(computation: var BaseComputation)
|
proc executeOpcodes*(computation: var BaseComputation) {.gcsafe.}
|
||||||
|
|
||||||
proc applyMessage(fork: Fork, computation: var BaseComputation, opCode: static[Op]) =
|
proc applyMessage*(computation: var BaseComputation, opCode: static[Op]): bool =
|
||||||
var snapshot = computation.snapshot()
|
var snapshot = computation.snapshot()
|
||||||
defer: snapshot.dispose()
|
defer: snapshot.dispose()
|
||||||
|
|
||||||
|
@ -177,26 +177,31 @@ proc applyMessage(fork: Fork, computation: var BaseComputation, opCode: static[O
|
||||||
snapshot.commit()
|
snapshot.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
var success = true
|
|
||||||
try:
|
try:
|
||||||
executeOpcodes(computation)
|
executeOpcodes(computation)
|
||||||
success = not computation.isError
|
result = not computation.isError
|
||||||
except VMError:
|
except VMError:
|
||||||
success = false
|
result = false
|
||||||
debug "applyMessage failed",
|
debug "applyMessage VM Error",
|
||||||
|
msg = getCurrentExceptionMsg(),
|
||||||
|
depth = computation.msg.depth
|
||||||
|
except ValueError:
|
||||||
|
result = false
|
||||||
|
debug "applyMessage Value Error",
|
||||||
msg = getCurrentExceptionMsg(),
|
msg = getCurrentExceptionMsg(),
|
||||||
depth = computation.msg.depth
|
depth = computation.msg.depth
|
||||||
|
|
||||||
if success and computation.msg.isCreate:
|
if result and computation.msg.isCreate:
|
||||||
|
var fork = computation.getFork
|
||||||
let contractFailed = not computation.writeContract(fork)
|
let contractFailed = not computation.writeContract(fork)
|
||||||
success = not(contractFailed and fork == FkHomestead)
|
result = not(contractFailed and fork == FkHomestead)
|
||||||
|
|
||||||
if success:
|
if result:
|
||||||
snapshot.commit()
|
snapshot.commit()
|
||||||
else:
|
else:
|
||||||
snapshot.revert(true)
|
snapshot.revert(true)
|
||||||
|
|
||||||
proc addChildComputation(fork: Fork, computation: var BaseComputation, child: BaseComputation) =
|
proc addChildComputation(computation: var BaseComputation, child: BaseComputation) =
|
||||||
if child.isError:
|
if child.isError:
|
||||||
if child.msg.isCreate:
|
if child.msg.isCreate:
|
||||||
computation.returnData = child.output
|
computation.returnData = child.output
|
||||||
|
@ -216,9 +221,8 @@ proc addChildComputation(fork: Fork, computation: var BaseComputation, child: Ba
|
||||||
|
|
||||||
proc applyChildComputation*(parentComp, childComp: var BaseComputation, opCode: static[Op]) =
|
proc applyChildComputation*(parentComp, childComp: var BaseComputation, opCode: static[Op]) =
|
||||||
## Apply the vm message childMsg as a child computation.
|
## Apply the vm message childMsg as a child computation.
|
||||||
var fork = parentComp.getFork
|
discard childComp.applyMessage(opCode)
|
||||||
fork.applyMessage(childComp, opCode)
|
parentComp.addChildComputation(childComp)
|
||||||
fork.addChildComputation(parentComp, childComp)
|
|
||||||
|
|
||||||
proc registerAccountForDeletion*(c: var BaseComputation, beneficiary: EthAddress) =
|
proc registerAccountForDeletion*(c: var BaseComputation, beneficiary: EthAddress) =
|
||||||
if c.msg.storageAddress in c.accountsToDelete:
|
if c.msg.storageAddress in c.accountsToDelete:
|
||||||
|
|
|
@ -64,36 +64,18 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient:
|
||||||
doAssert result.isOriginComputation
|
doAssert result.isOriginComputation
|
||||||
|
|
||||||
proc execComputation*(computation: var BaseComputation): bool =
|
proc execComputation*(computation: var BaseComputation): bool =
|
||||||
var snapshot = computation.snapshot()
|
if computation.msg.isCreate:
|
||||||
defer: snapshot.dispose()
|
result = computation.applyMessage(Create)
|
||||||
|
else:
|
||||||
|
result = computation.applyMessage(Call)
|
||||||
|
|
||||||
computation.vmState.mutateStateDB:
|
|
||||||
db.subBalance(computation.msg.origin, computation.msg.value)
|
|
||||||
db.addBalance(computation.msg.storageAddress, computation.msg.value)
|
|
||||||
|
|
||||||
try:
|
|
||||||
computation.executeOpcodes()
|
|
||||||
computation.vmState.mutateStateDB:
|
computation.vmState.mutateStateDB:
|
||||||
for deletedAccount in computation.getAccountsForDeletion:
|
for deletedAccount in computation.getAccountsForDeletion:
|
||||||
db.deleteAccount deletedAccount
|
db.deleteAccount deletedAccount
|
||||||
result = not computation.isError
|
|
||||||
except VMError:
|
|
||||||
result = false
|
|
||||||
debug "execComputation() VM Error", error = getCurrentExceptionMsg()
|
|
||||||
except ValueError:
|
|
||||||
result = false
|
|
||||||
debug "execComputation() Value Error", msg = getCurrentExceptionMsg()
|
|
||||||
|
|
||||||
if result and computation.msg.isCreate:
|
|
||||||
let fork = computation.getFork
|
|
||||||
let contractFailed = not computation.writeContract(fork)
|
|
||||||
result = not(contractFailed and fork == FkHomestead)
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
snapshot.commit()
|
|
||||||
computation.vmState.addLogs(computation.logEntries)
|
computation.vmState.addLogs(computation.logEntries)
|
||||||
else:
|
else:
|
||||||
snapshot.revert()
|
|
||||||
if computation.tracingEnabled: computation.traceError()
|
if computation.tracingEnabled: computation.traceError()
|
||||||
|
|
||||||
proc refundGas*(computation: BaseComputation, tx: Transaction, sender: EthAddress): GasInt =
|
proc refundGas*(computation: BaseComputation, tx: Transaction, sender: EthAddress): GasInt =
|
||||||
|
|
Loading…
Reference in New Issue