mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-25 10:25:32 +00:00
get rid of computation child after execution
This commit is contained in:
parent
ed62d1e217
commit
d30f434f03
@ -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
|
||||||
if not c.msg.isCreate:
|
c.vmState.touchedAccounts.incl c.touchedAccounts
|
||||||
if condition:
|
else:
|
||||||
|
if not c.msg.isCreate:
|
||||||
# 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
|
||||||
|
@ -35,7 +35,7 @@ proc init*(self: BaseVMState, prevStateRoot: Hash256, header: BlockHeader,
|
|||||||
self.tracingEnabled = TracerFlags.EnableTracing in tracerFlags
|
self.tracingEnabled = TracerFlags.EnableTracing in tracerFlags
|
||||||
self.logEntries = @[]
|
self.logEntries = @[]
|
||||||
self.accountDb = newAccountStateDB(chainDB.db, prevStateRoot, chainDB.pruneTrie)
|
self.accountDb = newAccountStateDB(chainDB.db, prevStateRoot, chainDB.pruneTrie)
|
||||||
self.touchedAccounts = initHashSet[EthAddress]()
|
self.touchedAccounts = initHashSet[EthAddress]()
|
||||||
|
|
||||||
proc newBaseVMState*(prevStateRoot: Hash256, header: BlockHeader,
|
proc newBaseVMState*(prevStateRoot: Hash256, header: BlockHeader,
|
||||||
chainDB: BaseChainDB, tracerFlags: set[TracerFlags] = {}): BaseVMState =
|
chainDB: BaseChainDB, tracerFlags: set[TracerFlags] = {}): BaseVMState =
|
||||||
|
@ -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:
|
||||||
|
@ -59,11 +59,10 @@ 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
|
||||||
touchedAccounts*: HashSet[EthAddress]
|
touchedAccounts*: HashSet[EthAddress]
|
||||||
suicides*: HashSet[EthAddress]
|
suicides*: HashSet[EthAddress]
|
||||||
gasCosts*: GasCosts # TODO - will be hidden at a lower layer
|
gasCosts*: GasCosts # TODO - will be hidden at a lower layer
|
||||||
forkOverride*: Option[Fork]
|
forkOverride*: Option[Fork]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user