modify VMState to enable witness data collection

This commit is contained in:
jangko 2020-06-06 10:05:11 +07:00
parent 50816f2ebb
commit 7c026e1b48
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
4 changed files with 35 additions and 16 deletions

View File

@ -42,7 +42,8 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
debug "state clearing", account
db.deleteAccount(account)
#vmState.accountDb.updateOriginalRoot()
if vmState.generateWitness:
vmState.accountDb.collectWitnessData()
vmState.accountDb.persist()
type
@ -143,6 +144,8 @@ proc processBlock*(chainDB: BaseChainDB, header: BlockHeader, body: BlockBody, v
# Reward beneficiary
vmState.mutateStateDB:
db.addBalance(header.coinbase, mainReward)
if vmState.generateWitness:
db.collectWitnessData()
db.persist()
let stateDb = vmState.accountDb

View File

@ -322,19 +322,19 @@ proc refundSelfDestruct*(c: Computation) =
let cost = gasFees[c.fork][RefundSelfDestruct]
c.gasMeter.refundGas(cost * c.suicides.len)
proc tracingEnabled*(c: Computation): bool =
c.vmState.tracingEnabled
proc tracingEnabled*(c: Computation): bool {.inline.} =
EnableTracing in c.vmState.tracer.flags
proc traceOpCodeStarted*(c: Computation, op: Op): int =
proc traceOpCodeStarted*(c: Computation, op: Op): int {.inline.} =
c.vmState.tracer.traceOpCodeStarted(c, op)
proc traceOpCodeEnded*(c: Computation, op: Op, lastIndex: int) =
proc traceOpCodeEnded*(c: Computation, op: Op, lastIndex: int) {.inline.} =
c.vmState.tracer.traceOpCodeEnded(c, op, lastIndex)
proc traceError*(c: Computation) =
proc traceError*(c: Computation) {.inline.} =
c.vmState.tracer.traceError(c)
proc prepareTracer*(c: Computation) =
proc prepareTracer*(c: Computation) {.inline.} =
c.vmState.tracer.prepare(c.msg.depth)
include interpreter_dispatch

View File

@ -34,7 +34,6 @@ proc init*(self: BaseVMState, prevStateRoot: Hash256, header: BlockHeader,
self.blockHeader = header
self.chaindb = chainDB
self.tracer.initTracer(tracerFlags)
self.tracingEnabled = TracerFlags.EnableTracing in tracerFlags
self.logEntries = @[]
self.accountDb = AccountsCache.init(chainDB.db, prevStateRoot, chainDB.pruneTrie)
self.touchedAccounts = initHashSet[EthAddress]()
@ -103,19 +102,19 @@ template mutateStateDB*(vmState: BaseVMState, body: untyped) =
var db {.inject.} = vmState.accountDb
body
proc getTracingResult*(vmState: BaseVMState): JsonNode =
doAssert(vmState.tracingEnabled)
proc getTracingResult*(vmState: BaseVMState): JsonNode {.inline.} =
doAssert(EnableTracing in vmState.tracer.flags)
vmState.tracer.trace
proc getAndClearLogEntries*(vmState: BaseVMState): seq[Log] =
shallowCopy(result, vmState.logEntries)
vmState.logEntries = @[]
proc enableTracing*(vmState: BaseVMState) =
vmState.tracingEnabled = true
proc enableTracing*(vmState: BaseVMState) {.inline.} =
vmState.tracer.flags.incl EnableTracing
proc disableTracing*(vmState: BaseVMState) =
vmState.tracingEnabled = false
proc disableTracing*(vmState: BaseVMState) {.inline.} =
vmState.tracer.flags.excl EnableTracing
iterator tracedAccounts*(vmState: BaseVMState): EthAddress =
for acc in vmState.tracer.accounts:
@ -130,3 +129,17 @@ iterator tracedAccountsPairs*(vmState: BaseVMState): (int, EthAddress) =
proc removeTracedAccounts*(vmState: BaseVMState, accounts: varargs[EthAddress]) =
for acc in accounts:
vmState.tracer.accounts.excl acc
proc status*(vmState: BaseVMState): bool {.inline.} =
ExecutionOK in vmState.flags
proc `status=`*(vmState: BaseVMState, status: bool) =
if status: vmState.flags.incl ExecutionOK
else: vmState.flags.excl ExecutionOK
proc generateWitness*(vmState: BaseVMState): bool {.inline.} =
GenerateWitness in vmState.flags
proc `generateWitness=`*(vmState: BaseVMState, status: bool) =
if status: vmState.flags.incl GenerateWitness
else: vmState.flags.excl GenerateWitness

View File

@ -16,13 +16,17 @@ when defined(evmc_enabled):
import ./vm/evmc_api
type
VMFlag* = enum
ExecutionOK
GenerateWitness
BaseVMState* = ref object of RootObj
prevHeaders* : seq[BlockHeader]
chaindb* : BaseChainDB
accessLogs* : AccessLogs
blockHeader* : BlockHeader
name* : string
tracingEnabled*: bool
flags* : set[VMFlag]
tracer* : TransactionTracer
logEntries* : seq[Log]
receipts* : seq[Receipt]
@ -30,7 +34,6 @@ type
cumulativeGasUsed*: GasInt
touchedAccounts*: HashSet[EthAddress]
suicides* : HashSet[EthAddress]
status* : bool
txOrigin* : EthAddress
txGasPrice* : GasInt
gasCosts* : GasCosts