diff --git a/nimbus/tracer.nim b/nimbus/tracer.nim index 29aae96c9..9f1fda735 100644 --- a/nimbus/tracer.nim +++ b/nimbus/tracer.nim @@ -121,6 +121,7 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader, after.captureAccount(stateDb, sender, senderName) after.captureAccount(stateDb, recipient, recipientName) after.captureAccount(stateDb, header.coinbase, minerName) + vmState.removeTracedAccounts(sender, recipient, header.coinbase) stateDiff["afterRoot"] = %($stateDb.rootHash) break @@ -176,11 +177,14 @@ proc dumpBlockState*(db: BaseChainDB, header: BlockHeader, body: BlockBody, dump let recipient = tx.getRecipient after.captureAccount(stateAfter, sender, senderName & $idx) after.captureAccount(stateAfter, recipient, recipientName & $idx) + vmState.removeTracedAccounts(sender, recipient) after.captureAccount(stateAfter, header.coinbase, minerName) + vmState.removeTracedAccounts(header.coinbase) for idx, uncle in body.uncles: after.captureAccount(stateAfter, uncle.coinbase, uncleName & $idx) + vmState.removeTracedAccounts(uncle.coinbase) # internal transactions: for idx, acc in tracedAccountsPairs(vmState): diff --git a/nimbus/vm/transaction_tracer.nim b/nimbus/vm/transaction_tracer.nim index 0a1f39645..201041528 100644 --- a/nimbus/vm/transaction_tracer.nim +++ b/nimbus/vm/transaction_tracer.nim @@ -1,5 +1,5 @@ import - json, strutils, + json, strutils, sets, chronicles, nimcrypto, eth_common, stint, ../vm_types, memory, stack, ../db/[db_chain, state_db], eth_trie/hexary, ./message, ranges/typedranges, @@ -18,7 +18,7 @@ proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) = tracer.trace["structLogs"] = newJArray() tracer.flags = flags - tracer.accounts = @[] + tracer.accounts = initSet[EthAddress]() proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op: Op) = if unlikely tracer.trace.isNil: @@ -53,10 +53,10 @@ proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op: case op of Call, CallCode, DelegateCall, StaticCall: assert(c.stack.values.len > 2) - tracer.accounts.add c.stack[^2, EthAddress] - of SelfDestruct: + tracer.accounts.incl c.stack[^2, EthAddress] + of ExtCodeCopy, ExtCodeSize, Balance, SelfDestruct: assert(c.stack.values.len > 1) - tracer.accounts.add c.stack[^1, EthAddress] + tracer.accounts.incl c.stack[^1, EthAddress] else: discard diff --git a/nimbus/vm_state.nim b/nimbus/vm_state.nim index aa05f909a..1638dc97e 100644 --- a/nimbus/vm_state.nim +++ b/nimbus/vm_state.nim @@ -6,7 +6,7 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - macros, strformat, tables, + macros, strformat, tables, sets, eth_common, eth_trie/db, ./constants, ./errors, ./transaction, ./db/[db_chain, state_db], ./utils/header, json, vm_types, vm/transaction_tracer @@ -150,5 +150,12 @@ iterator tracedAccounts*(vmState: BaseVMState): EthAddress = yield acc iterator tracedAccountsPairs*(vmState: BaseVMState): (int, EthAddress) = - for idx, acc in vmState.tracer.accounts: + var idx = 0 + for acc in vmState.tracer.accounts: yield (idx, acc) + inc idx + +proc removeTracedAccounts*(vmState: BaseVMState, accounts: varargs[EthAddress]) = + for acc in accounts: + vmState.tracer.accounts.excl acc + diff --git a/nimbus/vm_types.nim b/nimbus/vm_types.nim index cf0ad5c52..145910139 100644 --- a/nimbus/vm_types.nim +++ b/nimbus/vm_types.nim @@ -7,7 +7,7 @@ import tables, eth_common, options, - ./constants, json, + ./constants, json, sets, ./vm/[memory, stack, code_stream], ./vm/interpreter/[gas_costs, opcode_values, vm_forks], # TODO - will be hidden at a lower layer ./db/[db_chain, state_db] @@ -42,7 +42,7 @@ type trace*: JsonNode gasRemaining*: GasInt flags*: set[TracerFlags] - accounts*: seq[EthAddress] + accounts*: HashSet[EthAddress] OpcodeExecutor* = proc(computation: var BaseComputation)