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 431cf2a1e4
commit 34998d4410

View file

@ -62,6 +62,8 @@ type Contract struct {
Args []byte Args []byte
DelegateCall bool 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. // 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.CodeHash = hash
self.CodeAddr = addr 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()
}
}