get rid of computation child after execution

This commit is contained in:
andri lim 2020-01-09 17:40:39 +07:00 committed by zah
parent ed62d1e217
commit d30f434f03
4 changed files with 17 additions and 23 deletions

View File

@ -24,7 +24,6 @@ proc newBaseComputation*(vmState: BaseVMState, blockNumber: BlockNumber, message
result.memory = Memory() result.memory = Memory()
result.stack = newStack() result.stack = newStack()
result.gasMeter.init(message.gas) result.gasMeter.init(message.gas)
result.children = @[]
result.touchedAccounts = initHashSet[EthAddress]() result.touchedAccounts = initHashSet[EthAddress]()
result.suicides = initHashSet[EthAddress]() result.suicides = initHashSet[EthAddress]()
result.code = newCodeStream(message.code) result.code = newCodeStream(message.code)
@ -200,6 +199,11 @@ proc applyMessage*(computation: BaseComputation, opCode: static[Op]) =
executeOpcodes(computation) executeOpcodes(computation)
proc addChildComputation*(computation: BaseComputation, child: BaseComputation) = proc addChildComputation*(computation: BaseComputation, child: BaseComputation) =
if child.isError or computation.getFork == FKIstanbul:
if not child.msg.isCreate:
if child.msg.contractAddress == ripemdAddr:
child.vmState.touchedAccounts.incl child.msg.contractAddress
if child.isError: if child.isError:
if child.shouldBurnGas: if child.shouldBurnGas:
computation.returnData = @[] computation.returnData = @[]
@ -218,9 +222,9 @@ proc addChildComputation*(computation: BaseComputation, child: BaseComputation)
if not child.shouldBurnGas: if not child.shouldBurnGas:
computation.gasMeter.returnGas(child.gasMeter.gasRemaining) computation.gasMeter.returnGas(child.gasMeter.gasRemaining)
computation.children.add(child)
proc registerAccountForDeletion*(c: BaseComputation, beneficiary: EthAddress) = proc registerAccountForDeletion*(c: BaseComputation, beneficiary: EthAddress) =
c.touchedAccounts.incl beneficiary
c.touchedAccounts.incl beneficiary c.touchedAccounts.incl beneficiary
c.suicides.incl(c.msg.contractAddress) c.suicides.incl(c.msg.contractAddress)
@ -248,26 +252,21 @@ proc getGasRemaining*(c: BaseComputation): GasInt =
else: else:
result = c.gasMeter.gasRemaining result = c.gasMeter.gasRemaining
# TODO: collecting touched accounts should be done in account state db proc collectTouchedAccounts*(c: BaseComputation) =
proc collectTouchedAccounts*(c: BaseComputation, output: var HashSet[EthAddress], ancestorHadError: bool = false) =
## Collect all of the accounts that *may* need to be deleted based on EIP161: ## Collect all of the accounts that *may* need to be deleted based on EIP161:
## https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md ## https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md
## also see: https://github.com/ethereum/EIPs/issues/716 ## also see: https://github.com/ethereum/EIPs/issues/716
let isIstanbul = c.getFork >= FkIstanbul if c.isSuccess:
let condition = c.isError or ancestorHadError if not c.msg.isCreate:
c.touchedAccounts.incl c.msg.contractAddress
c.vmState.touchedAccounts.incl c.touchedAccounts
else:
if not c.msg.isCreate: if not c.msg.isCreate:
if condition:
# Special case to account for geth+parity bug # Special case to account for geth+parity bug
# https://github.com/ethereum/EIPs/issues/716 # https://github.com/ethereum/EIPs/issues/716
if c.msg.contractAddress == ripemdAddr: if c.msg.contractAddress == ripemdAddr:
output.incl c.msg.contractAddress c.vmState.touchedAccounts.incl c.msg.contractAddress
if c.isSuccess or isIstanbul:
# recurse into nested computations (even errored ones, since looking for RIPEMD160)
for child in c.children:
child.collectTouchedAccounts(output, c.isError or ancestorHadError)
proc tracingEnabled*(c: BaseComputation): bool = proc tracingEnabled*(c: BaseComputation): bool =
c.vmState.tracingEnabled c.vmState.tracingEnabled

View File

@ -78,11 +78,7 @@ proc execComputation*(computation: var BaseComputation) =
computation.gasMeter.refundGas(RefundSelfDestruct * suicidedCount) computation.gasMeter.refundGas(RefundSelfDestruct * suicidedCount)
if computation.getFork >= FkSpurious: if computation.getFork >= FkSpurious:
computation.collectTouchedAccounts(computation.vmState.touchedAccounts) computation.collectTouchedAccounts()
if computation.isSuccess:
if not computation.msg.isCreate:
computation.touchedAccounts.incl computation.msg.contractAddress
computation.vmState.touchedAccounts.incl computation.touchedAccounts
computation.vmstate.status = computation.isSuccess computation.vmstate.status = computation.isSuccess
if computation.isSuccess: if computation.isSuccess:

View File

@ -59,7 +59,6 @@ type
stack*: Stack stack*: Stack
gasMeter*: GasMeter gasMeter*: GasMeter
code*: CodeStream code*: CodeStream
children*: seq[BaseComputation]
rawOutput*: seq[byte] rawOutput*: seq[byte]
returnData*: seq[byte] returnData*: seq[byte]
error*: Error error*: Error