core/vm: add a reverted flag in vm contract

which is used to indicate whether state revert happen during
state transition.

if child's revert flag been set, it will also affect its parent
recursively
This commit is contained in:
rjl493456442 2017-06-15 21:49:12 +08:00
parent d14dceb396
commit 19c8193876

View file

@ -62,6 +62,8 @@ type Contract struct {
Args []byte
DelegateCall bool
Reverted bool // use to represent whether transaction is reverted during state transition
// child's reverted field changed will also affect parent.
}
// NewContract returns a new contract environment for the execution of EVM.
@ -151,3 +153,12 @@ func (self *Contract) SetCallCode(addr *common.Address, hash common.Hash, code [
self.CodeHash = hash
self.CodeAddr = addr
}
// MarkReverted mark current transaction's execution has meet revert.
func (self *Contract) MarkReverted() {
self.Reverted = true
// affect parent recursively
if parent, ok := self.caller.(*Contract); ok {
parent.MarkReverted()
}
}