2021-04-08 14:52:10 +00:00
|
|
|
# Nimbus
|
2024-01-09 15:15:19 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2021-04-08 14:52:10 +00:00
|
|
|
# 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.
|
|
|
|
|
2023-02-14 20:27:17 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2021-04-08 14:52:10 +00:00
|
|
|
import
|
2023-11-20 20:22:27 +00:00
|
|
|
std/[options, sets, strformat],
|
Consolidate block type for block processing (#2325)
This PR consolidates the split header-body sequences into a single EthBlock
sequence and cleans up the fallout from that which significantly reduces
block processing overhead during import thanks to less garbage collection
and fewer copies of things all around.
Notably, since the number of headers must always match the number of bodies,
we also get rid of a pointless degree of freedom that in the future could
introduce unnecessary bugs.
* only read header and body from era file
* avoid several unnecessary copies along the block processing way
* simplify signatures, cleaning up unused arguemnts and returns
* use `stew/assign2` in a few strategic places where the generated
nim assignent is slow and add a few `move` to work around poor
analysis in nim 1.6 (will need to be revisited for 2.0)
```
stats-20240607_2223-a814aa0b.csv vs stats-20240608_0714-21c1d0a9.csv
bps_x bps_y tps_x tps_y bpsd tpsd timed
block_number
(498305, 713245] 1,540.52 1,809.73 2,361.58 2775.340189 17.63% 17.63% -14.92%
(713245, 928185] 730.36 865.26 1,715.90 2028.973852 18.01% 18.01% -15.21%
(928185, 1143126] 663.03 789.10 2,529.26 3032.490771 19.79% 19.79% -16.28%
(1143126, 1358066] 393.46 508.05 2,152.50 2777.578119 29.13% 29.13% -22.50%
(1358066, 1573007] 370.88 440.72 2,351.31 2791.896052 18.81% 18.81% -15.80%
(1573007, 1787947] 283.65 335.11 2,068.93 2441.373402 17.60% 17.60% -14.91%
(1787947, 2002888] 287.29 342.11 2,078.39 2474.179448 18.99% 18.99% -15.91%
(2002888, 2217828] 293.38 343.16 2,208.83 2584.77457 17.16% 17.16% -14.61%
(2217828, 2432769] 140.09 167.86 1,081.87 1296.336926 18.82% 18.82% -15.80%
blocks: 1934464, baseline: 3h13m1s, contender: 2h43m47s
bpsd (mean): 19.55%
tpsd (mean): 19.55%
Time (total): -29m13s, -15.14%
```
2024-06-09 14:32:20 +00:00
|
|
|
stew/assign2,
|
2024-01-22 09:11:37 +00:00
|
|
|
eth/keys,
|
2023-12-12 19:12:56 +00:00
|
|
|
../db/ledger,
|
2022-12-02 04:35:41 +00:00
|
|
|
../common/[common, evmforks],
|
2023-08-27 06:13:37 +00:00
|
|
|
./interpreter/[op_codes, gas_costs],
|
2024-06-07 08:24:32 +00:00
|
|
|
./types,
|
|
|
|
./evm_errors
|
2021-07-27 11:28:05 +00:00
|
|
|
|
2024-07-04 13:48:36 +00:00
|
|
|
func forkDeterminationInfoForVMState(vmState: BaseVMState): ForkDeterminationInfo =
|
|
|
|
forkDeterminationInfo(vmState.parent.number + 1, vmState.blockCtx.timestamp)
|
|
|
|
|
|
|
|
func determineFork(vmState: BaseVMState): EVMFork =
|
|
|
|
vmState.com.toEVMFork(vmState.forkDeterminationInfoForVMState)
|
|
|
|
|
2022-01-18 16:19:32 +00:00
|
|
|
proc init(
|
2023-04-12 12:39:11 +00:00
|
|
|
self: BaseVMState;
|
2023-12-12 19:12:56 +00:00
|
|
|
ac: LedgerRef,
|
2023-04-12 12:39:11 +00:00
|
|
|
parent: BlockHeader;
|
2023-09-24 15:25:41 +00:00
|
|
|
blockCtx: BlockContext;
|
2023-04-12 12:39:11 +00:00
|
|
|
com: CommonRef;
|
2023-08-02 10:17:40 +00:00
|
|
|
tracer: TracerRef,
|
2024-05-30 09:03:54 +00:00
|
|
|
flags: set[VMFlag] = self.flags) =
|
2022-01-18 16:19:32 +00:00
|
|
|
## Initialisation helper
|
Consolidate block type for block processing (#2325)
This PR consolidates the split header-body sequences into a single EthBlock
sequence and cleans up the fallout from that which significantly reduces
block processing overhead during import thanks to less garbage collection
and fewer copies of things all around.
Notably, since the number of headers must always match the number of bodies,
we also get rid of a pointless degree of freedom that in the future could
introduce unnecessary bugs.
* only read header and body from era file
* avoid several unnecessary copies along the block processing way
* simplify signatures, cleaning up unused arguemnts and returns
* use `stew/assign2` in a few strategic places where the generated
nim assignent is slow and add a few `move` to work around poor
analysis in nim 1.6 (will need to be revisited for 2.0)
```
stats-20240607_2223-a814aa0b.csv vs stats-20240608_0714-21c1d0a9.csv
bps_x bps_y tps_x tps_y bpsd tpsd timed
block_number
(498305, 713245] 1,540.52 1,809.73 2,361.58 2775.340189 17.63% 17.63% -14.92%
(713245, 928185] 730.36 865.26 1,715.90 2028.973852 18.01% 18.01% -15.21%
(928185, 1143126] 663.03 789.10 2,529.26 3032.490771 19.79% 19.79% -16.28%
(1143126, 1358066] 393.46 508.05 2,152.50 2777.578119 29.13% 29.13% -22.50%
(1358066, 1573007] 370.88 440.72 2,351.31 2791.896052 18.81% 18.81% -15.80%
(1573007, 1787947] 283.65 335.11 2,068.93 2441.373402 17.60% 17.60% -14.91%
(1787947, 2002888] 287.29 342.11 2,078.39 2474.179448 18.99% 18.99% -15.91%
(2002888, 2217828] 293.38 343.16 2,208.83 2584.77457 17.16% 17.16% -14.61%
(2217828, 2432769] 140.09 167.86 1,081.87 1296.336926 18.82% 18.82% -15.80%
blocks: 1934464, baseline: 3h13m1s, contender: 2h43m47s
bpsd (mean): 19.55%
tpsd (mean): 19.55%
Time (total): -29m13s, -15.14%
```
2024-06-09 14:32:20 +00:00
|
|
|
assign(self.parent, parent)
|
2023-09-24 15:25:41 +00:00
|
|
|
self.blockCtx = blockCtx
|
|
|
|
self.gasPool = blockCtx.gasLimit
|
2022-12-02 04:35:41 +00:00
|
|
|
self.com = com
|
2022-01-18 16:19:32 +00:00
|
|
|
self.tracer = tracer
|
2021-10-28 09:42:39 +00:00
|
|
|
self.stateDB = ac
|
2024-01-09 15:15:19 +00:00
|
|
|
self.flags = flags
|
2024-06-24 05:56:24 +00:00
|
|
|
self.blobGasUsed = 0'u64
|
2024-07-04 13:48:36 +00:00
|
|
|
self.fork = self.determineFork
|
|
|
|
self.gasCosts = self.fork.forkToSchedule
|
2022-01-18 16:19:32 +00:00
|
|
|
|
2023-09-24 15:25:41 +00:00
|
|
|
func blockCtx(com: CommonRef, header: BlockHeader):
|
2024-05-30 09:03:54 +00:00
|
|
|
BlockContext =
|
2023-09-24 15:25:41 +00:00
|
|
|
BlockContext(
|
|
|
|
timestamp : header.timestamp,
|
|
|
|
gasLimit : header.gasLimit,
|
2024-06-14 07:31:08 +00:00
|
|
|
baseFeePerGas: header.baseFeePerGas,
|
2023-09-24 15:25:41 +00:00
|
|
|
prevRandao : header.prevRandao,
|
|
|
|
difficulty : header.difficulty,
|
2024-07-17 10:05:53 +00:00
|
|
|
coinbase : header.coinbase,
|
2023-09-24 15:25:41 +00:00
|
|
|
excessBlobGas: header.excessBlobGas.get(0'u64),
|
|
|
|
)
|
|
|
|
|
2022-01-18 16:19:32 +00:00
|
|
|
# --------------
|
|
|
|
|
|
|
|
proc `$`*(vmState: BaseVMState): string
|
2024-06-19 01:27:54 +00:00
|
|
|
{.gcsafe, raises: [].} =
|
2022-01-18 16:19:32 +00:00
|
|
|
if vmState.isNil:
|
|
|
|
result = "nil"
|
|
|
|
else:
|
2022-12-02 04:35:41 +00:00
|
|
|
result = &"VMState:"&
|
2024-06-14 07:31:08 +00:00
|
|
|
&"\n blockNumber: {vmState.parent.number + 1}"
|
2022-01-18 16:19:32 +00:00
|
|
|
|
|
|
|
proc new*(
|
2023-09-24 15:25:41 +00:00
|
|
|
T: type BaseVMState;
|
|
|
|
parent: BlockHeader; ## parent header, account sync position
|
|
|
|
blockCtx: BlockContext;
|
|
|
|
com: CommonRef; ## block chain config
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer: TracerRef = nil,
|
|
|
|
storeSlotHash = false): T =
|
2022-01-18 16:19:32 +00:00
|
|
|
## Create a new `BaseVMState` descriptor from a parent block header. This
|
|
|
|
## function internally constructs a new account state cache rooted at
|
|
|
|
## `parent.stateRoot`
|
|
|
|
##
|
|
|
|
## This `new()` constructor and its variants (see below) provide a save
|
|
|
|
## `BaseVMState` environment where the account state cache is synchronised
|
|
|
|
## with the `parent` block header.
|
|
|
|
new result
|
|
|
|
result.init(
|
2024-08-16 06:22:51 +00:00
|
|
|
ac = LedgerRef.init(com.db, parent.stateRoot, storeSlotHash),
|
2023-09-24 15:25:41 +00:00
|
|
|
parent = parent,
|
|
|
|
blockCtx = blockCtx,
|
|
|
|
com = com,
|
|
|
|
tracer = tracer)
|
|
|
|
|
|
|
|
proc reinit*(self: BaseVMState; ## Object descriptor
|
|
|
|
parent: BlockHeader; ## parent header, account sync pos.
|
2024-06-14 13:56:56 +00:00
|
|
|
blockCtx: BlockContext;
|
|
|
|
linear: bool
|
2024-05-30 09:03:54 +00:00
|
|
|
): bool =
|
2023-12-12 19:12:56 +00:00
|
|
|
## Re-initialise state descriptor. The `LedgerRef` database is
|
2022-01-18 16:19:32 +00:00
|
|
|
## re-initilaise only if its `rootHash` doe not point to `parent.stateRoot`,
|
2024-06-14 13:56:56 +00:00
|
|
|
## already. Accumulated state data are reset. When linear, we assume that
|
|
|
|
## the state recently processed the parent block.
|
2022-01-18 16:19:32 +00:00
|
|
|
##
|
2023-12-12 19:12:56 +00:00
|
|
|
## This function returns `true` unless the `LedgerRef` database could be
|
2022-01-18 16:19:32 +00:00
|
|
|
## queries about its `rootHash`, i.e. `isTopLevelClean` evaluated `true`. If
|
|
|
|
## this function returns `false`, the function argument `self` is left
|
|
|
|
## untouched.
|
|
|
|
if self.stateDB.isTopLevelClean:
|
|
|
|
let
|
|
|
|
tracer = self.tracer
|
2022-12-02 04:35:41 +00:00
|
|
|
com = self.com
|
|
|
|
db = com.db
|
2024-06-14 13:56:56 +00:00
|
|
|
ac = if linear or self.stateDB.rootHash == parent.stateRoot: self.stateDB
|
2024-08-16 06:22:51 +00:00
|
|
|
else: LedgerRef.init(db, parent.stateRoot, self.stateDB.ac.storeSlotHash)
|
2024-01-09 15:15:19 +00:00
|
|
|
flags = self.flags
|
2022-01-18 16:19:32 +00:00
|
|
|
self[].reset
|
|
|
|
self.init(
|
2023-09-24 15:25:41 +00:00
|
|
|
ac = ac,
|
|
|
|
parent = parent,
|
|
|
|
blockCtx = blockCtx,
|
|
|
|
com = com,
|
2024-01-09 15:15:19 +00:00
|
|
|
tracer = tracer,
|
|
|
|
flags = flags)
|
2022-01-18 16:19:32 +00:00
|
|
|
return true
|
|
|
|
# else: false
|
|
|
|
|
2023-09-24 15:25:41 +00:00
|
|
|
proc reinit*(self: BaseVMState; ## Object descriptor
|
|
|
|
parent: BlockHeader; ## parent header, account sync pos.
|
|
|
|
header: BlockHeader; ## header with tx environment data fields
|
2024-06-14 13:56:56 +00:00
|
|
|
linear: bool
|
2024-05-30 09:03:54 +00:00
|
|
|
): bool =
|
2022-01-18 16:19:32 +00:00
|
|
|
## Variant of `reinit()`. The `parent` argument is used to sync the accounts
|
|
|
|
## cache and the `header` is used as a container to pass the `timestamp`,
|
|
|
|
## `gasLimit`, and `fee` values.
|
|
|
|
##
|
|
|
|
## It requires the `header` argument properly initalised so that for PoA
|
|
|
|
## networks, the miner address is retrievable via `ecRecover()`.
|
2024-06-14 13:56:56 +00:00
|
|
|
self.reinit(
|
2023-09-24 15:25:41 +00:00
|
|
|
parent = parent,
|
|
|
|
blockCtx = self.com.blockCtx(header),
|
2024-06-14 13:56:56 +00:00
|
|
|
linear = linear
|
2023-09-24 15:25:41 +00:00
|
|
|
)
|
2022-01-18 16:19:32 +00:00
|
|
|
|
|
|
|
proc reinit*(self: BaseVMState; ## Object descriptor
|
|
|
|
header: BlockHeader; ## header with tx environment data fields
|
2024-05-30 09:03:54 +00:00
|
|
|
): bool =
|
2022-01-18 16:19:32 +00:00
|
|
|
## This is a variant of the `reinit()` function above where the field
|
|
|
|
## `header.parentHash`, is used to fetch the `parent` BlockHeader to be
|
|
|
|
## used in the `update()` variant, above.
|
2022-07-21 12:14:41 +00:00
|
|
|
var parent: BlockHeader
|
2024-06-14 13:56:56 +00:00
|
|
|
self.com.db.getBlockHeader(header.parentHash, parent) and
|
|
|
|
self.reinit(
|
2022-07-21 12:14:41 +00:00
|
|
|
parent = parent,
|
2024-06-14 13:56:56 +00:00
|
|
|
header = header,
|
|
|
|
linear = false)
|
2022-01-18 16:19:32 +00:00
|
|
|
|
|
|
|
proc init*(
|
2023-08-02 10:17:40 +00:00
|
|
|
self: BaseVMState; ## Object descriptor
|
|
|
|
parent: BlockHeader; ## parent header, account sync position
|
|
|
|
header: BlockHeader; ## header with tx environment data fields
|
|
|
|
com: CommonRef; ## block chain config
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer: TracerRef = nil,
|
|
|
|
storeSlotHash = false) =
|
2022-01-18 16:19:32 +00:00
|
|
|
## Variant of `new()` constructor above for in-place initalisation. The
|
|
|
|
## `parent` argument is used to sync the accounts cache and the `header`
|
|
|
|
## is used as a container to pass the `timestamp`, `gasLimit`, and `fee`
|
|
|
|
## values.
|
|
|
|
##
|
|
|
|
## It requires the `header` argument properly initalised so that for PoA
|
|
|
|
## networks, the miner address is retrievable via `ecRecover()`.
|
2022-03-15 17:21:41 +00:00
|
|
|
self.init(
|
2024-08-16 06:22:51 +00:00
|
|
|
ac = LedgerRef.init(com.db, parent.stateRoot, storeSlotHash),
|
2023-09-24 15:25:41 +00:00
|
|
|
parent = parent,
|
|
|
|
blockCtx = com.blockCtx(header),
|
|
|
|
com = com,
|
|
|
|
tracer = tracer)
|
2022-01-18 16:19:32 +00:00
|
|
|
|
|
|
|
proc new*(
|
2023-08-02 10:17:40 +00:00
|
|
|
T: type BaseVMState;
|
|
|
|
parent: BlockHeader; ## parent header, account sync position
|
|
|
|
header: BlockHeader; ## header with tx environment data fields
|
|
|
|
com: CommonRef; ## block chain config
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer: TracerRef = nil,
|
|
|
|
storeSlotHash = false): T =
|
2022-01-18 16:19:32 +00:00
|
|
|
## This is a variant of the `new()` constructor above where the `parent`
|
|
|
|
## argument is used to sync the accounts cache and the `header` is used
|
|
|
|
## as a container to pass the `timestamp`, `gasLimit`, and `fee` values.
|
|
|
|
##
|
|
|
|
## It requires the `header` argument properly initalised so that for PoA
|
|
|
|
## networks, the miner address is retrievable via `ecRecover()`.
|
2021-04-08 14:52:10 +00:00
|
|
|
new result
|
2022-01-18 16:19:32 +00:00
|
|
|
result.init(
|
2023-08-02 10:17:40 +00:00
|
|
|
parent = parent,
|
|
|
|
header = header,
|
|
|
|
com = com,
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer = tracer,
|
|
|
|
storeSlotHash = storeSlotHash)
|
2022-01-18 16:19:32 +00:00
|
|
|
|
|
|
|
proc new*(
|
2023-08-02 10:17:40 +00:00
|
|
|
T: type BaseVMState;
|
|
|
|
header: BlockHeader; ## header with tx environment data fields
|
|
|
|
com: CommonRef; ## block chain config
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer: TracerRef = nil,
|
|
|
|
storeSlotHash = false): EvmResult[T] =
|
2022-01-18 16:19:32 +00:00
|
|
|
## This is a variant of the `new()` constructor above where the field
|
|
|
|
## `header.parentHash`, is used to fetch the `parent` BlockHeader to be
|
|
|
|
## used in the `new()` variant, above.
|
2024-06-07 08:24:32 +00:00
|
|
|
var parent: BlockHeader
|
|
|
|
if com.db.getBlockHeader(header.parentHash, parent):
|
|
|
|
ok(BaseVMState.new(
|
|
|
|
parent = parent,
|
|
|
|
header = header,
|
|
|
|
com = com,
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer = tracer,
|
|
|
|
storeSlotHash = storeSlotHash))
|
2024-06-07 08:24:32 +00:00
|
|
|
else:
|
|
|
|
err(evmErr(EvmHeaderNotFound))
|
2022-01-18 16:19:32 +00:00
|
|
|
|
2022-07-21 12:14:41 +00:00
|
|
|
proc init*(
|
2023-08-02 10:17:40 +00:00
|
|
|
vmState: BaseVMState;
|
|
|
|
header: BlockHeader; ## header with tx environment data fields
|
|
|
|
com: CommonRef; ## block chain config
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer: TracerRef = nil,
|
|
|
|
storeSlotHash = false): bool =
|
2022-07-21 12:14:41 +00:00
|
|
|
## Variant of `new()` which does not throw an exception on a dangling
|
|
|
|
## `BlockHeader` parent hash reference.
|
|
|
|
var parent: BlockHeader
|
2022-12-02 04:35:41 +00:00
|
|
|
if com.db.getBlockHeader(header.parentHash, parent):
|
2022-07-21 12:14:41 +00:00
|
|
|
vmState.init(
|
2023-08-02 10:17:40 +00:00
|
|
|
parent = parent,
|
|
|
|
header = header,
|
|
|
|
com = com,
|
2024-08-16 06:22:51 +00:00
|
|
|
tracer = tracer,
|
|
|
|
storeSlotHash = storeSlotHash)
|
2022-07-21 12:14:41 +00:00
|
|
|
return true
|
|
|
|
|
2024-07-17 10:05:53 +00:00
|
|
|
func coinbase*(vmState: BaseVMState): EthAddress =
|
2023-09-24 15:25:41 +00:00
|
|
|
vmState.blockCtx.coinbase
|
2021-04-08 14:52:10 +00:00
|
|
|
|
2024-07-17 10:05:53 +00:00
|
|
|
func blockNumber*(vmState: BaseVMState): BlockNumber =
|
2021-04-08 14:52:10 +00:00
|
|
|
# it should return current block number
|
2024-06-14 07:31:08 +00:00
|
|
|
# and not head.number
|
|
|
|
vmState.parent.number + 1
|
2021-04-08 14:52:10 +00:00
|
|
|
|
2024-07-17 10:05:53 +00:00
|
|
|
func difficultyOrPrevRandao*(vmState: BaseVMState): UInt256 =
|
2022-12-02 04:35:41 +00:00
|
|
|
if vmState.com.consensus == ConsensusType.POS:
|
2022-02-05 09:15:50 +00:00
|
|
|
# EIP-4399/EIP-3675
|
2023-09-24 15:25:41 +00:00
|
|
|
UInt256.fromBytesBE(vmState.blockCtx.prevRandao.data)
|
2022-02-05 09:15:50 +00:00
|
|
|
else:
|
2023-09-24 15:25:41 +00:00
|
|
|
vmState.blockCtx.difficulty
|
2021-04-08 14:52:10 +00:00
|
|
|
|
2024-07-17 10:05:53 +00:00
|
|
|
func baseFeePerGas*(vmState: BaseVMState): UInt256 =
|
2024-06-14 07:31:08 +00:00
|
|
|
vmState.blockCtx.baseFeePerGas.get(0.u256)
|
2021-06-27 13:19:22 +00:00
|
|
|
|
2023-01-31 12:38:08 +00:00
|
|
|
method getAncestorHash*(
|
2024-06-19 01:27:54 +00:00
|
|
|
vmState: BaseVMState, blockNumber: BlockNumber): Hash256 {.gcsafe, base.} =
|
2022-12-02 04:35:41 +00:00
|
|
|
let db = vmState.com.db
|
2024-06-07 08:24:32 +00:00
|
|
|
try:
|
|
|
|
var blockHash: Hash256
|
|
|
|
if db.getBlockHash(blockNumber, blockHash):
|
|
|
|
blockHash
|
|
|
|
else:
|
2024-09-26 11:24:36 +00:00
|
|
|
default(Hash256)
|
2024-06-07 08:24:32 +00:00
|
|
|
except RlpError:
|
2024-09-26 11:24:36 +00:00
|
|
|
default(Hash256)
|
2022-12-02 04:35:41 +00:00
|
|
|
|
2021-04-08 14:52:10 +00:00
|
|
|
proc readOnlyStateDB*(vmState: BaseVMState): ReadOnlyStateDB {.inline.} =
|
2021-10-28 09:42:39 +00:00
|
|
|
ReadOnlyStateDB(vmState.stateDB)
|
2021-04-08 14:52:10 +00:00
|
|
|
|
|
|
|
template mutateStateDB*(vmState: BaseVMState, body: untyped) =
|
|
|
|
block:
|
2021-10-28 09:42:39 +00:00
|
|
|
var db {.inject.} = vmState.stateDB
|
2021-04-08 14:52:10 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
proc getAndClearLogEntries*(vmState: BaseVMState): seq[Log] =
|
2023-03-20 11:51:09 +00:00
|
|
|
vmState.stateDB.getAndClearLogEntries()
|
2021-04-08 14:52:10 +00:00
|
|
|
|
2022-01-18 16:19:32 +00:00
|
|
|
proc status*(vmState: BaseVMState): bool =
|
2021-04-08 14:52:10 +00:00
|
|
|
ExecutionOK in vmState.flags
|
|
|
|
|
|
|
|
proc `status=`*(vmState: BaseVMState, status: bool) =
|
|
|
|
if status: vmState.flags.incl ExecutionOK
|
|
|
|
else: vmState.flags.excl ExecutionOK
|
|
|
|
|
2024-06-08 08:05:00 +00:00
|
|
|
proc collectWitnessData*(vmState: BaseVMState): bool =
|
|
|
|
CollectWitnessData in vmState.flags
|
2021-04-08 14:52:10 +00:00
|
|
|
|
2024-06-08 08:05:00 +00:00
|
|
|
proc `collectWitnessData=`*(vmState: BaseVMState, status: bool) =
|
|
|
|
if status: vmState.flags.incl CollectWitnessData
|
|
|
|
else: vmState.flags.excl CollectWitnessData
|
2024-01-22 09:11:37 +00:00
|
|
|
|
2023-08-02 10:17:40 +00:00
|
|
|
func tracingEnabled*(vmState: BaseVMState): bool =
|
|
|
|
vmState.tracer.isNil.not
|
|
|
|
|
|
|
|
proc captureTxStart*(vmState: BaseVMState, gasLimit: GasInt) =
|
|
|
|
if vmState.tracingEnabled:
|
|
|
|
vmState.tracer.captureTxStart(gasLimit)
|
|
|
|
|
|
|
|
proc captureTxEnd*(vmState: BaseVMState, restGas: GasInt) =
|
|
|
|
if vmState.tracingEnabled:
|
|
|
|
vmState.tracer.captureTxEnd(restGas)
|
|
|
|
|
2023-08-25 09:07:20 +00:00
|
|
|
proc captureStart*(vmState: BaseVMState, comp: Computation,
|
2023-08-02 10:17:40 +00:00
|
|
|
sender: EthAddress, to: EthAddress,
|
|
|
|
create: bool, input: openArray[byte],
|
2023-08-25 09:07:20 +00:00
|
|
|
gasLimit: GasInt, value: UInt256) =
|
2023-08-02 10:17:40 +00:00
|
|
|
if vmState.tracingEnabled:
|
2023-08-25 09:07:20 +00:00
|
|
|
vmState.tracer.captureStart(comp, sender, to, create, input, gasLimit, value)
|
2023-08-02 10:17:40 +00:00
|
|
|
|
2023-08-25 09:07:20 +00:00
|
|
|
proc captureEnd*(vmState: BaseVMState, comp: Computation, output: openArray[byte],
|
2024-06-07 21:39:58 +00:00
|
|
|
gasUsed: GasInt, error: Opt[string]) =
|
2023-08-02 10:17:40 +00:00
|
|
|
if vmState.tracingEnabled:
|
2023-08-25 09:07:20 +00:00
|
|
|
vmState.tracer.captureEnd(comp, output, gasUsed, error)
|
2023-08-02 10:17:40 +00:00
|
|
|
|
2023-08-25 09:07:20 +00:00
|
|
|
proc captureEnter*(vmState: BaseVMState, comp: Computation, op: Op,
|
2023-08-02 10:17:40 +00:00
|
|
|
sender: EthAddress, to: EthAddress,
|
2023-08-25 09:07:20 +00:00
|
|
|
input: openArray[byte], gasLimit: GasInt,
|
2023-08-02 10:17:40 +00:00
|
|
|
value: UInt256) =
|
|
|
|
if vmState.tracingEnabled:
|
2023-08-25 09:07:20 +00:00
|
|
|
vmState.tracer.captureEnter(comp, op, sender, to, input, gasLimit, value)
|
2023-08-02 10:17:40 +00:00
|
|
|
|
2023-08-25 09:07:20 +00:00
|
|
|
proc captureExit*(vmState: BaseVMState, comp: Computation, output: openArray[byte],
|
2024-06-07 21:39:58 +00:00
|
|
|
gasUsed: GasInt, error: Opt[string]) =
|
2023-08-02 10:17:40 +00:00
|
|
|
if vmState.tracingEnabled:
|
2023-08-25 09:07:20 +00:00
|
|
|
vmState.tracer.captureExit(comp, output, gasUsed, error)
|
2023-08-02 10:17:40 +00:00
|
|
|
|
2023-08-25 09:07:20 +00:00
|
|
|
proc captureOpStart*(vmState: BaseVMState, comp: Computation, pc: int,
|
2023-08-02 10:17:40 +00:00
|
|
|
op: Op, gas: GasInt,
|
|
|
|
depth: int): int =
|
|
|
|
if vmState.tracingEnabled:
|
2023-08-27 06:13:37 +00:00
|
|
|
let fixed = vmState.gasCosts[op].kind == GckFixed
|
|
|
|
result = vmState.tracer.captureOpStart(comp, fixed, pc, op, gas, depth)
|
2023-08-02 10:17:40 +00:00
|
|
|
|
2023-08-27 06:13:37 +00:00
|
|
|
proc captureGasCost*(vmState: BaseVMState,
|
2023-08-25 09:07:20 +00:00
|
|
|
comp: Computation,
|
2023-08-27 06:13:37 +00:00
|
|
|
op: Op, gasCost: GasInt, gasRemaining: GasInt,
|
2023-08-23 09:29:33 +00:00
|
|
|
depth: int) =
|
2024-07-13 18:42:49 +00:00
|
|
|
let fixed = vmState.gasCosts[op].kind == GckFixed
|
|
|
|
vmState.tracer.captureGasCost(comp, fixed, op, gasCost, gasRemaining, depth)
|
2023-08-25 09:07:20 +00:00
|
|
|
|
|
|
|
proc captureOpEnd*(vmState: BaseVMState, comp: Computation, pc: int,
|
2024-07-07 06:52:11 +00:00
|
|
|
op: Op, gas: GasInt, refund: int64,
|
2023-08-02 10:17:40 +00:00
|
|
|
rData: openArray[byte],
|
|
|
|
depth: int, opIndex: int) =
|
|
|
|
if vmState.tracingEnabled:
|
2023-08-27 06:13:37 +00:00
|
|
|
let fixed = vmState.gasCosts[op].kind == GckFixed
|
|
|
|
vmState.tracer.captureOpEnd(comp, fixed, pc, op, gas, refund, rData, depth, opIndex)
|
2023-08-02 10:17:40 +00:00
|
|
|
|
2023-08-25 09:07:20 +00:00
|
|
|
proc captureFault*(vmState: BaseVMState, comp: Computation, pc: int,
|
2024-07-07 06:52:11 +00:00
|
|
|
op: Op, gas: GasInt, refund: int64,
|
2023-08-02 10:17:40 +00:00
|
|
|
rData: openArray[byte],
|
2024-06-07 21:39:58 +00:00
|
|
|
depth: int, error: Opt[string]) =
|
2023-08-02 10:17:40 +00:00
|
|
|
if vmState.tracingEnabled:
|
2023-08-27 06:13:37 +00:00
|
|
|
let fixed = vmState.gasCosts[op].kind == GckFixed
|
|
|
|
vmState.tracer.captureFault(comp, fixed, pc, op, gas, refund, rData, depth, error)
|
2023-08-02 10:17:40 +00:00
|
|
|
|
2023-08-25 09:07:20 +00:00
|
|
|
proc capturePrepare*(vmState: BaseVMState, comp: Computation, depth: int) =
|
2023-08-02 10:17:40 +00:00
|
|
|
if vmState.tracingEnabled:
|
2023-08-25 09:07:20 +00:00
|
|
|
vmState.tracer.capturePrepare(comp, depth)
|