EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
# Nimbus - Trace EVMC host calls when EVM code is run for a transaction
|
2021-05-21 05:24:09 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
import
|
|
|
|
macros, strformat, strutils, stint, chronicles,
|
|
|
|
stew/byteutils, stew/ranges/ptr_arith,
|
|
|
|
./host_types
|
2021-05-21 05:24:09 +00:00
|
|
|
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
# Set `true` or `false` to control host call tracing.
|
|
|
|
const showTxCalls = false
|
|
|
|
const showTxNested = true
|
|
|
|
|
|
|
|
proc `$`(val: EvmcCallKind | EvmcStatusCode |
|
|
|
|
EvmcStorageStatus | EvmcAccessStatus): string =
|
|
|
|
result = val.repr
|
|
|
|
result.removePrefix("EVMC_")
|
|
|
|
|
|
|
|
proc `$`(address: HostAddress): string = toHex(address)
|
2021-05-21 05:24:09 +00:00
|
|
|
|
|
|
|
# Don't use both types in the overload, as Nim <= 1.2.x gives "ambiguous call".
|
|
|
|
#func `$`(n: HostKey | HostValue): string = toHex(n)
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
proc `$`(n: HostKey): string =
|
|
|
|
# Show small keys and values as decimal, and large ones as "0x"-prefix hex.
|
|
|
|
# These are often small numbers despite the 256-bit type, so low digits is
|
|
|
|
# helpful. But "key=d" looks odd. Hex must be used for large values as they
|
|
|
|
# are sometimes 256-bit hashes, and then decimal is unhelpful.
|
|
|
|
if n <= 65535.u256.HostKey:
|
|
|
|
$n.truncate(uint16)
|
|
|
|
else:
|
|
|
|
"0x" & n.toHex
|
2021-05-21 05:24:09 +00:00
|
|
|
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
proc depthPrefix(host: TransactionHost): string =
|
|
|
|
let depth = host.depth
|
|
|
|
if depth <= 20:
|
|
|
|
return spaces(depth * 2)
|
|
|
|
else:
|
|
|
|
let num = '(' & $depth & ')'
|
|
|
|
return num & spaces(42 - num.len)
|
2021-05-21 05:24:09 +00:00
|
|
|
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
proc showEvmcMessage(msg: EvmcMessage): string =
|
|
|
|
let kindStr =
|
|
|
|
if msg.flags == {}: $msg.kind
|
|
|
|
elif msg.flags == {EVMC_STATIC} and msg.kind == EVMC_CALL: "CALL_STATIC"
|
|
|
|
else: &"{$msg.kind} flags={$msg.flags}"
|
|
|
|
var inputStr = "(" & $msg.input_size & ")"
|
|
|
|
if msg.input_size > 0:
|
|
|
|
inputStr.add toHex(makeOpenArray(msg.input_data,
|
|
|
|
min(msg.input_size, 256).int))
|
|
|
|
if msg.input_size > 256:
|
|
|
|
inputStr.add "..."
|
|
|
|
result = &"kind={kindStr}" &
|
|
|
|
&" depth={$msg.depth}" &
|
|
|
|
&" gas={$msg.gas}" &
|
|
|
|
&" value={$msg.value.fromEvmc}" &
|
|
|
|
&" sender={$msg.sender.fromEvmc}" &
|
2022-09-26 12:23:54 +00:00
|
|
|
&" recipient={$msg.recipient.fromEvmc}" &
|
|
|
|
&" code_address={$msg.code_address.fromEvmc}" &
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
&" input_data={inputStr}"
|
|
|
|
if msg.kind == EVMC_CREATE2:
|
|
|
|
result.add &" create2_salt={$msg.create2_salt.fromEvmc}"
|
|
|
|
|
|
|
|
proc showEvmcResult(res: EvmcResult, withCreateAddress = true): string =
|
|
|
|
if res.status_code != EVMC_SUCCESS and res.status_code != EVMC_REVERT and
|
|
|
|
res.gas_left == 0 and res.output_size == 0:
|
|
|
|
return &"status={$res.status_code}"
|
|
|
|
|
|
|
|
var outputStr = "(" & $res.output_size & ")"
|
|
|
|
if res.output_size > 0:
|
|
|
|
outputStr.add toHex(makeOpenArray(res.output_data,
|
|
|
|
min(res.output_size, 256).int))
|
|
|
|
if res.output_size > 256:
|
|
|
|
outputStr.add "..."
|
|
|
|
|
|
|
|
result = &"status={$res.status_code}" &
|
|
|
|
&" gas_left={$res.gas_left}" &
|
|
|
|
&" output_data={outputStr}"
|
|
|
|
if withCreateAddress:
|
|
|
|
result.add &" create_address={$res.create_address.fromEvmc}"
|
|
|
|
|
|
|
|
proc showEvmcTxContext(txc: EvmcTxContext): string =
|
|
|
|
return &"tx_gas_price={$txc.tx_gas_price.fromEvmc}" &
|
|
|
|
&" tx_origin={$txc.tx_origin.fromEvmc}" &
|
|
|
|
&" block_coinbase={$txc.block_coinbase.fromEvmc}" &
|
|
|
|
&" block_number={$txc.block_number}" &
|
|
|
|
&" block_timestamp={$txc.block_timestamp}" &
|
|
|
|
&" block_gas_limit={$txc.block_gas_limit}" &
|
2022-09-26 12:23:54 +00:00
|
|
|
&" block_prev_randao={$txc.block_prev_randao.fromEvmc}" &
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
&" chain_id={$txc.chain_id.fromEvmc}" &
|
|
|
|
&" block_base_fee={$txc.block_base_fee.fromEvmc}"
|
|
|
|
|
|
|
|
proc showEvmcArgsExpr(fn: NimNode, callName: string): auto =
|
2021-05-21 05:24:09 +00:00
|
|
|
var args: seq[NimNode] = newSeq[NimNode]()
|
|
|
|
var types: seq[NimNode] = newSeq[NimNode]()
|
|
|
|
for i in 1 ..< fn.params.len:
|
|
|
|
let idents = fn.params[i]
|
|
|
|
for j in 0 ..< idents.len-2:
|
|
|
|
args.add idents[j]
|
|
|
|
types.add idents[^2]
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
let hostExpr = args[0]
|
2021-05-21 05:24:09 +00:00
|
|
|
var msgExpr = quote do:
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
`depthPrefix`(`hostExpr`) & "evmc." & `callName` & ":"
|
2021-05-21 05:24:09 +00:00
|
|
|
var skip = 0
|
|
|
|
for i in 1 ..< args.len:
|
|
|
|
if i == skip:
|
|
|
|
continue
|
|
|
|
var arg = args[i]
|
|
|
|
let argNameString = " " & $arg & "="
|
|
|
|
if (types[i].repr == "ptr byte" or types[i].repr == "ptr HostTopic") and
|
|
|
|
(i < args.len-1 and types[i+1].repr == "HostSize"):
|
|
|
|
skip = i+1
|
|
|
|
arg = newPar(args[i], args[i+1])
|
|
|
|
msgExpr = quote do:
|
|
|
|
`msgExpr` & `argNameString` & $(`arg`)
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
return (msgExpr, args)
|
|
|
|
|
|
|
|
macro show*(fn: untyped): auto =
|
|
|
|
if not showTxCalls:
|
|
|
|
return fn
|
2021-05-21 05:24:09 +00:00
|
|
|
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
let (msgExpr, args) = showEvmcArgsExpr(fn, $fn.name)
|
|
|
|
let hostExpr = args[0]
|
2021-05-21 05:24:09 +00:00
|
|
|
if fn.params[0].kind == nnkEmpty:
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
fn.body.insert 0, quote do:
|
|
|
|
if showTxNested or `hostExpr`.depth > 1:
|
|
|
|
echo `msgExpr`
|
2021-05-21 05:24:09 +00:00
|
|
|
else:
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
let innerFn = newProc(name = fn.name, body = fn.body)
|
|
|
|
innerFn.params = fn.params.copy
|
|
|
|
innerFn.addPragma(newIdentNode("inline"))
|
|
|
|
fn.body = newStmtList(innerFn)
|
|
|
|
let call = newCall(fn.name, args)
|
|
|
|
let msgVar = genSym(nskLet, "msg")
|
|
|
|
fn.body.add quote do:
|
|
|
|
if not (showTxNested or `hostExpr`.depth > 1):
|
|
|
|
return `call`
|
2021-05-21 05:24:09 +00:00
|
|
|
let `msgVar` = `msgExpr`
|
EVMC: Improve host call tracing and fix nested call C stack usage
This combines two things, a C stack usage change with EVM nested calls
via EVMC, and changes to host call tracing.
Feature-wise, the tracing is improved:
- Storage keys and values are make more sense.
- The message/result/context objects are shown with all relevant fields.
- `call` trace is split into entry/exit, so these can be shown around the
called contract's operations, instead of only showing the `call` parameters
after the nested call is finished.
- Nested calls are indented, which helps to highlight the flow.
- C stack usage considerably reduced in nested calls when more functionality
is enabled (either tracing here, or other things to come).
This will seem like a minor patch, but C stack usage was the real motivation,
after plenty of time in the debugger.
Nobody cares about stack when `showTxCalls` (you can just use a big stack when
debugging). But these subtle changes around the `call` path were found to be
necessary for passing all tests when the EVMC nested call code is completed,
and that's a prerequisite for many things: async EVM, dynamic EVM, Beam Sync,
and to fix https://github.com/status-im/nimbus-eth1/issues/345.
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-08-09 14:54:38 +00:00
|
|
|
result = `call`
|
|
|
|
if fn.params[0].repr == "EvmcTxContext":
|
|
|
|
fn.body.add quote do:
|
|
|
|
echo `msgVar` & " -> " & showEvmcTxContext(result)
|
|
|
|
else:
|
|
|
|
fn.body.add quote do:
|
|
|
|
echo `msgVar` & " -> result=" & $result
|
|
|
|
return fn
|
|
|
|
|
|
|
|
template showCallEntry*(host: TransactionHost, msg: EvmcMessage) =
|
|
|
|
if showTxCalls and (showTxNested or host.depth > 0):
|
|
|
|
echo depthPrefix(host) & "evmc.call: " &
|
|
|
|
showEvmcMessage(msg)
|
|
|
|
inc host.depth
|
|
|
|
|
|
|
|
template showCallReturn*(host: TransactionHost, res: EvmcResult,
|
|
|
|
forNestedCreate = false) =
|
|
|
|
if showTxCalls and (showTxNested or host.depth > 1):
|
|
|
|
echo depthPrefix(host) & "evmc.return -> " &
|
|
|
|
showEvmcResult(res, forNestedCreate)
|
|
|
|
dec host.depth
|