2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-01-13 01:41:57 +00:00
|
|
|
# Copyright (c) 2019-2024 Status Research & Development GmbH
|
2023-11-01 03:32:09 +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.
|
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
{.push raises: [].}
|
2024-06-18 11:14:02 +00:00
|
|
|
|
2018-12-03 10:54:19 +00:00
|
|
|
import
|
2022-12-02 04:39:12 +00:00
|
|
|
std/[strutils, json],
|
2024-08-01 10:41:20 +00:00
|
|
|
nimcrypto/utils as ncrutils,
|
|
|
|
results,
|
|
|
|
web3/conversions,
|
|
|
|
./beacon/web3_eth_conv,
|
2022-12-02 04:39:12 +00:00
|
|
|
./common/common,
|
2024-08-01 10:41:20 +00:00
|
|
|
./constants,
|
|
|
|
./core/executor,
|
2023-12-12 19:12:56 +00:00
|
|
|
./db/[core_db, ledger],
|
2024-08-01 10:41:20 +00:00
|
|
|
./evm/[code_bytes, state, types],
|
2023-08-02 10:17:40 +00:00
|
|
|
./evm/tracer/legacy_tracer,
|
2024-08-01 10:41:20 +00:00
|
|
|
./launcher,
|
2024-06-17 07:56:39 +00:00
|
|
|
./transaction,
|
2024-08-01 10:41:20 +00:00
|
|
|
./utils/utils
|
2018-12-03 16:22:08 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
when not CoreDbEnableCaptJournal:
|
|
|
|
{.error: "Compiler flag missing for tracer, try -d:dbjapi_enabled".}
|
2018-12-03 16:22:08 +00:00
|
|
|
|
2024-03-22 17:31:56 +00:00
|
|
|
type
|
2024-08-01 10:41:20 +00:00
|
|
|
CaptCtxRef = ref object
|
|
|
|
db: CoreDbRef # not `nil`
|
|
|
|
root: common.Hash256
|
|
|
|
ctx: CoreDbCtxRef # not `nil`
|
|
|
|
cpt: CoreDbCaptRef # not `nil`
|
|
|
|
restore: CoreDbCtxRef # `nil` unless `ctx` activated
|
2024-03-22 17:31:56 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
const
|
|
|
|
senderName = "sender"
|
|
|
|
recipientName = "recipient"
|
|
|
|
minerName = "miner"
|
|
|
|
uncleName = "uncle"
|
|
|
|
internalTxName = "internalTx"
|
2024-03-21 10:45:57 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
proc dumpMemoryDB*(node: JsonNode, cpt: CoreDbCaptRef) {.gcsafe.}
|
|
|
|
proc toJson*(receipts: seq[Receipt]): JsonNode {.gcsafe.}
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template safeTracer(info: string; code: untyped) =
|
|
|
|
try:
|
|
|
|
code
|
|
|
|
except CatchableError as e:
|
|
|
|
raiseAssert info & " name=" & $e.name & " msg=" & e.msg
|
|
|
|
|
|
|
|
# -------------------
|
2024-08-16 06:22:51 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
proc init(
|
|
|
|
T: type CaptCtxRef;
|
|
|
|
com: CommonRef;
|
|
|
|
root: common.Hash256;
|
2024-09-10 05:24:45 +00:00
|
|
|
): T =
|
2024-08-01 10:41:20 +00:00
|
|
|
let ctx = block:
|
|
|
|
let rc = com.db.ctx.newCtxByKey(root)
|
|
|
|
if rc.isErr:
|
|
|
|
raiseAssert "newCptCtx: " & $$rc.error
|
|
|
|
rc.value
|
|
|
|
T(db: com.db, root: root, cpt: com.db.pushCapture(), ctx: ctx)
|
|
|
|
|
|
|
|
proc init(
|
|
|
|
T: type CaptCtxRef;
|
|
|
|
com: CommonRef;
|
|
|
|
topHeader: BlockHeader;
|
|
|
|
): T
|
|
|
|
{.raises: [CatchableError].} =
|
|
|
|
T.init(com, com.db.getBlockHeader(topHeader.parentHash).stateRoot)
|
|
|
|
|
|
|
|
proc activate(cc: CaptCtxRef): CaptCtxRef {.discardable.} =
|
|
|
|
## Install/activate new context `cc.ctx`, old one in `cc.restore`
|
|
|
|
doAssert not cc.isNil
|
|
|
|
doAssert cc.restore.isNil # otherwise activated, already
|
|
|
|
cc.restore = cc.ctx.swapCtx cc.db
|
|
|
|
cc
|
|
|
|
|
|
|
|
proc release(cc: CaptCtxRef) =
|
|
|
|
if not cc.restore.isNil: # switch to original context (if any)
|
|
|
|
let ctx = cc.restore.swapCtx(cc.db)
|
|
|
|
doAssert ctx == cc.ctx
|
|
|
|
cc.ctx.forget() # dispose
|
|
|
|
cc.cpt.pop() # discard top layer of actions tracer
|
|
|
|
|
|
|
|
# -------------------
|
2024-03-21 10:45:57 +00:00
|
|
|
|
2018-12-25 10:31:51 +00:00
|
|
|
proc `%`(x: openArray[byte]): JsonNode =
|
|
|
|
result = %toHex(x, false)
|
|
|
|
|
|
|
|
proc toJson(receipt: Receipt): JsonNode =
|
|
|
|
result = newJObject()
|
|
|
|
|
|
|
|
result["cumulativeGasUsed"] = %receipt.cumulativeGasUsed
|
2024-06-14 07:31:08 +00:00
|
|
|
result["bloom"] = %receipt.logsBloom
|
2018-12-25 10:31:51 +00:00
|
|
|
result["logs"] = %receipt.logs
|
|
|
|
|
|
|
|
if receipt.hasStateRoot:
|
|
|
|
result["root"] = %($receipt.stateRoot)
|
|
|
|
else:
|
|
|
|
result["status"] = %receipt.status
|
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
proc dumpReceiptsImpl(
|
|
|
|
chainDB: CoreDbRef;
|
|
|
|
header: BlockHeader;
|
|
|
|
): JsonNode
|
|
|
|
{.raises: [CatchableError].} =
|
2018-12-25 10:31:51 +00:00
|
|
|
result = newJArray()
|
2024-06-14 07:31:08 +00:00
|
|
|
for receipt in chainDB.getReceipts(header.receiptsRoot):
|
2018-12-25 10:31:51 +00:00
|
|
|
result.add receipt.toJson
|
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private functions
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-12-03 10:54:19 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
proc captureAccount(
|
|
|
|
n: JsonNode;
|
|
|
|
db: LedgerRef;
|
|
|
|
address: EthAddress;
|
|
|
|
name: string;
|
|
|
|
) =
|
2018-12-12 03:40:37 +00:00
|
|
|
var jaccount = newJObject()
|
|
|
|
jaccount["name"] = %name
|
2019-01-11 06:53:18 +00:00
|
|
|
jaccount["address"] = %("0x" & $address)
|
2020-06-01 06:45:32 +00:00
|
|
|
|
|
|
|
let nonce = db.getNonce(address)
|
|
|
|
let balance = db.getBalance(address)
|
|
|
|
let codeHash = db.getCodeHash(address)
|
|
|
|
let storageRoot = db.getStorageRoot(address)
|
|
|
|
|
2024-01-13 01:41:57 +00:00
|
|
|
jaccount["nonce"] = %(conversions.`$`(nonce.Web3Quantity))
|
2020-06-01 06:45:32 +00:00
|
|
|
jaccount["balance"] = %("0x" & balance.toHex)
|
2018-12-11 09:53:05 +00:00
|
|
|
|
|
|
|
let code = db.getCode(address)
|
2020-06-01 06:45:32 +00:00
|
|
|
jaccount["codeHash"] = %("0x" & ($codeHash).toLowerAscii)
|
2024-08-01 10:41:20 +00:00
|
|
|
jaccount["code"] = %("0x" & code.bytes.toHex(true))
|
2020-06-01 06:45:32 +00:00
|
|
|
jaccount["storageRoot"] = %("0x" & ($storageRoot).toLowerAscii)
|
2018-12-11 09:53:05 +00:00
|
|
|
|
|
|
|
var storage = newJObject()
|
|
|
|
for key, value in db.storage(address):
|
2019-01-11 06:53:18 +00:00
|
|
|
storage["0x" & key.dumpHex] = %("0x" & value.dumpHex)
|
2018-12-12 03:40:37 +00:00
|
|
|
jaccount["storage"] = storage
|
2018-12-11 09:53:05 +00:00
|
|
|
|
2018-12-12 03:40:37 +00:00
|
|
|
n.add jaccount
|
2018-12-11 09:53:05 +00:00
|
|
|
|
2018-12-12 15:18:46 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
proc traceTransactionImpl(
|
|
|
|
com: CommonRef;
|
|
|
|
header: BlockHeader;
|
|
|
|
transactions: openArray[Transaction];
|
|
|
|
txIndex: uint64;
|
|
|
|
tracerFlags: set[TracerFlags] = {};
|
|
|
|
): JsonNode
|
|
|
|
{.raises: [CatchableError].}=
|
|
|
|
if header.txRoot == EMPTY_ROOT_HASH:
|
|
|
|
return newJNull()
|
2024-03-07 19:24:05 +00:00
|
|
|
|
2018-12-03 16:22:08 +00:00
|
|
|
let
|
2023-08-02 10:17:40 +00:00
|
|
|
tracerInst = newLegacyTracer(tracerFlags)
|
2024-08-01 10:41:20 +00:00
|
|
|
cc = activate CaptCtxRef.init(com, header)
|
2024-08-16 06:22:51 +00:00
|
|
|
vmState = BaseVMState.new(header, com, storeSlotHash = true).valueOr: return newJNull()
|
2024-03-22 17:31:56 +00:00
|
|
|
stateDb = vmState.stateDB
|
2024-06-07 08:24:32 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
defer: cc.release()
|
2018-12-26 03:34:16 +00:00
|
|
|
|
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
|
|
|
doAssert(transactions.calcTxRoot == header.txRoot)
|
|
|
|
doAssert(transactions.len != 0)
|
2018-12-03 10:54:19 +00:00
|
|
|
|
2018-12-11 09:53:05 +00:00
|
|
|
var
|
|
|
|
gasUsed: GasInt
|
2018-12-12 09:41:18 +00:00
|
|
|
before = newJArray()
|
|
|
|
after = newJArray()
|
2018-12-11 09:53:05 +00:00
|
|
|
stateDiff = %{"before": before, "after": after}
|
2024-08-01 10:41:20 +00:00
|
|
|
stateCtx = CaptCtxRef(nil)
|
2018-12-11 09:53:05 +00:00
|
|
|
|
2020-06-22 00:48:23 +00:00
|
|
|
let
|
|
|
|
miner = vmState.coinbase()
|
2019-04-23 12:50:45 +00:00
|
|
|
|
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
|
|
|
for idx, tx in transactions:
|
2018-12-12 03:40:37 +00:00
|
|
|
let sender = tx.getSender
|
2021-05-04 06:27:18 +00:00
|
|
|
let recipient = tx.getRecipient(sender)
|
2018-12-11 09:53:05 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
if idx.uint64 == txIndex:
|
2023-08-02 10:17:40 +00:00
|
|
|
vmState.tracer = tracerInst # only enable tracer on target tx
|
2018-12-12 03:40:37 +00:00
|
|
|
before.captureAccount(stateDb, sender, senderName)
|
|
|
|
before.captureAccount(stateDb, recipient, recipientName)
|
2020-06-22 00:48:23 +00:00
|
|
|
before.captureAccount(stateDb, miner, minerName)
|
2020-06-01 06:45:32 +00:00
|
|
|
stateDb.persist()
|
2018-12-25 10:31:51 +00:00
|
|
|
stateDiff["beforeRoot"] = %($stateDb.rootHash)
|
2024-08-01 10:41:20 +00:00
|
|
|
discard com.db.ctx.getAccounts.state(updateOk=true) # lazy hashing!
|
|
|
|
stateCtx = CaptCtxRef.init(com, stateDb.rootHash)
|
2018-12-11 09:53:05 +00:00
|
|
|
|
2022-01-10 09:04:06 +00:00
|
|
|
let rc = vmState.processTransaction(tx, sender, header)
|
2022-04-08 04:54:11 +00:00
|
|
|
gasUsed = if rc.isOk: rc.value else: 0
|
2018-12-12 03:40:37 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
if idx.uint64 == txIndex:
|
2024-08-01 10:41:20 +00:00
|
|
|
discard com.db.ctx.getAccounts.state(updateOk=true) # lazy hashing!
|
2018-12-12 03:40:37 +00:00
|
|
|
after.captureAccount(stateDb, sender, senderName)
|
|
|
|
after.captureAccount(stateDb, recipient, recipientName)
|
2020-06-22 00:48:23 +00:00
|
|
|
after.captureAccount(stateDb, miner, minerName)
|
2023-08-02 10:17:40 +00:00
|
|
|
tracerInst.removeTracedAccounts(sender, recipient, miner)
|
2020-06-01 06:45:32 +00:00
|
|
|
stateDb.persist()
|
2018-12-25 10:31:51 +00:00
|
|
|
stateDiff["afterRoot"] = %($stateDb.rootHash)
|
2018-12-12 03:40:37 +00:00
|
|
|
break
|
2018-12-03 10:54:19 +00:00
|
|
|
|
2018-12-25 07:31:12 +00:00
|
|
|
# internal transactions:
|
2024-03-22 17:31:56 +00:00
|
|
|
let
|
2024-08-01 10:41:20 +00:00
|
|
|
cx = activate stateCtx
|
2024-08-16 06:22:51 +00:00
|
|
|
ldgBefore = LedgerRef.init(com.db, cx.root, storeSlotHash = true)
|
2024-08-01 10:41:20 +00:00
|
|
|
defer: cx.release()
|
2024-03-22 17:31:56 +00:00
|
|
|
|
2023-08-02 10:17:40 +00:00
|
|
|
for idx, acc in tracedAccountsPairs(tracerInst):
|
2024-08-01 10:41:20 +00:00
|
|
|
before.captureAccount(ldgBefore, acc, internalTxName & $idx)
|
2018-12-25 07:31:12 +00:00
|
|
|
|
2023-08-02 10:17:40 +00:00
|
|
|
for idx, acc in tracedAccountsPairs(tracerInst):
|
2018-12-25 07:31:12 +00:00
|
|
|
after.captureAccount(stateDb, acc, internalTxName & $idx)
|
|
|
|
|
2023-08-02 10:17:40 +00:00
|
|
|
result = tracerInst.getTracingResult()
|
2018-12-03 16:22:08 +00:00
|
|
|
result["gas"] = %gasUsed
|
2018-12-25 10:31:51 +00:00
|
|
|
|
|
|
|
if TracerFlags.DisableStateDiff notin tracerFlags:
|
|
|
|
result["stateDiff"] = stateDiff
|
2018-12-03 16:22:08 +00:00
|
|
|
|
2018-12-04 01:53:21 +00:00
|
|
|
# now we dump captured state db
|
2018-12-04 02:01:56 +00:00
|
|
|
if TracerFlags.DisableState notin tracerFlags:
|
2024-08-01 10:41:20 +00:00
|
|
|
result.dumpMemoryDB(cx.cpt)
|
2018-12-11 10:05:49 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
|
|
|
|
proc dumpBlockStateImpl(
|
|
|
|
com: CommonRef;
|
|
|
|
blk: EthBlock;
|
|
|
|
dumpState = false;
|
|
|
|
): JsonNode
|
|
|
|
{.raises: [CatchableError].} =
|
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
|
|
|
template header: BlockHeader = blk.header
|
2024-08-01 10:41:20 +00:00
|
|
|
|
2018-12-12 03:40:37 +00:00
|
|
|
let
|
2024-08-01 10:41:20 +00:00
|
|
|
cc = activate CaptCtxRef.init(com, header)
|
|
|
|
parent = com.db.getBlockHeader(header.parentHash)
|
|
|
|
|
|
|
|
# only need a stack dump when scanning for internal transaction address
|
2023-08-02 10:17:40 +00:00
|
|
|
captureFlags = {DisableMemory, DisableStorage, EnableAccount}
|
|
|
|
tracerInst = newLegacyTracer(captureFlags)
|
2024-08-16 06:22:51 +00:00
|
|
|
vmState = BaseVMState.new(header, com, tracerInst, storeSlotHash = true).valueOr:
|
2024-08-01 10:41:20 +00:00
|
|
|
return newJNull()
|
2020-06-22 00:48:23 +00:00
|
|
|
miner = vmState.coinbase()
|
2024-08-01 10:41:20 +00:00
|
|
|
|
|
|
|
defer: cc.release()
|
2018-12-12 03:40:37 +00:00
|
|
|
|
|
|
|
var
|
2018-12-12 09:41:18 +00:00
|
|
|
before = newJArray()
|
|
|
|
after = newJArray()
|
2024-08-16 06:22:51 +00:00
|
|
|
stateBefore = LedgerRef.init(com.db, parent.stateRoot, storeSlotHash = true)
|
2018-12-12 03:40:37 +00:00
|
|
|
|
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
|
|
|
for idx, tx in blk.transactions:
|
2018-12-12 03:40:37 +00:00
|
|
|
let sender = tx.getSender
|
2021-05-04 06:27:18 +00:00
|
|
|
let recipient = tx.getRecipient(sender)
|
2018-12-12 09:41:18 +00:00
|
|
|
before.captureAccount(stateBefore, sender, senderName & $idx)
|
|
|
|
before.captureAccount(stateBefore, recipient, recipientName & $idx)
|
2018-12-12 03:40:37 +00:00
|
|
|
|
2020-06-22 00:48:23 +00:00
|
|
|
before.captureAccount(stateBefore, miner, minerName)
|
2018-12-12 03:40:37 +00:00
|
|
|
|
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
|
|
|
for idx, uncle in blk.uncles:
|
2018-12-12 03:40:37 +00:00
|
|
|
before.captureAccount(stateBefore, uncle.coinbase, uncleName & $idx)
|
|
|
|
|
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
|
|
|
discard vmState.processBlock(blk)
|
2018-12-12 03:40:37 +00:00
|
|
|
|
2021-10-28 09:42:39 +00:00
|
|
|
var stateAfter = vmState.stateDB
|
2019-02-02 09:20:45 +00:00
|
|
|
|
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
|
|
|
for idx, tx in blk.transactions:
|
2018-12-12 03:40:37 +00:00
|
|
|
let sender = tx.getSender
|
2021-05-04 06:27:18 +00:00
|
|
|
let recipient = tx.getRecipient(sender)
|
2018-12-12 09:41:18 +00:00
|
|
|
after.captureAccount(stateAfter, sender, senderName & $idx)
|
|
|
|
after.captureAccount(stateAfter, recipient, recipientName & $idx)
|
2023-08-02 10:17:40 +00:00
|
|
|
tracerInst.removeTracedAccounts(sender, recipient)
|
2018-12-12 03:40:37 +00:00
|
|
|
|
2020-06-22 00:48:23 +00:00
|
|
|
after.captureAccount(stateAfter, miner, minerName)
|
2023-08-02 10:17:40 +00:00
|
|
|
tracerInst.removeTracedAccounts(miner)
|
2018-12-12 03:40:37 +00:00
|
|
|
|
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
|
|
|
for idx, uncle in blk.uncles:
|
2018-12-12 03:40:37 +00:00
|
|
|
after.captureAccount(stateAfter, uncle.coinbase, uncleName & $idx)
|
2023-08-02 10:17:40 +00:00
|
|
|
tracerInst.removeTracedAccounts(uncle.coinbase)
|
2018-12-12 03:40:37 +00:00
|
|
|
|
2018-12-25 07:31:12 +00:00
|
|
|
# internal transactions:
|
2023-08-02 10:17:40 +00:00
|
|
|
for idx, acc in tracedAccountsPairs(tracerInst):
|
2018-12-25 07:31:12 +00:00
|
|
|
before.captureAccount(stateBefore, acc, internalTxName & $idx)
|
|
|
|
|
2023-08-02 10:17:40 +00:00
|
|
|
for idx, acc in tracedAccountsPairs(tracerInst):
|
2018-12-25 07:31:12 +00:00
|
|
|
after.captureAccount(stateAfter, acc, internalTxName & $idx)
|
|
|
|
|
2018-12-12 03:40:37 +00:00
|
|
|
result = %{"before": before, "after": after}
|
2018-12-12 04:16:40 +00:00
|
|
|
|
2018-12-12 15:18:46 +00:00
|
|
|
if dumpState:
|
2024-08-01 10:41:20 +00:00
|
|
|
result.dumpMemoryDB(cc.cpt)
|
|
|
|
|
2018-12-12 15:18:46 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
proc traceBlockImpl(
|
|
|
|
com: CommonRef;
|
|
|
|
blk: EthBlock;
|
|
|
|
tracerFlags: set[TracerFlags] = {};
|
|
|
|
): JsonNode
|
|
|
|
{.raises: [CatchableError].} =
|
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
|
|
|
template header: BlockHeader = blk.header
|
2024-08-01 10:41:20 +00:00
|
|
|
|
2018-12-12 04:16:40 +00:00
|
|
|
let
|
2024-08-01 10:41:20 +00:00
|
|
|
cc = activate CaptCtxRef.init(com, header)
|
2023-08-02 10:17:40 +00:00
|
|
|
tracerInst = newLegacyTracer(tracerFlags)
|
2024-08-16 06:22:51 +00:00
|
|
|
# Tracer needs a database where the reverse slot hash table has been set up
|
|
|
|
vmState = BaseVMState.new(header, com, tracerInst, storeSlotHash = true).valueOr:
|
2024-08-01 10:41:20 +00:00
|
|
|
return newJNull()
|
2024-03-22 17:31:56 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
defer: cc.release()
|
2018-12-12 04:16:40 +00:00
|
|
|
|
2022-09-03 18:15:35 +00:00
|
|
|
if header.txRoot == EMPTY_ROOT_HASH: return newJNull()
|
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
|
|
|
doAssert(blk.transactions.calcTxRoot == header.txRoot)
|
|
|
|
doAssert(blk.transactions.len != 0)
|
2018-12-12 04:16:40 +00:00
|
|
|
|
|
|
|
var gasUsed = GasInt(0)
|
|
|
|
|
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
|
|
|
for tx in blk.transactions:
|
2022-01-10 09:04:06 +00:00
|
|
|
let
|
|
|
|
sender = tx.getSender
|
|
|
|
rc = vmState.processTransaction(tx, sender, header)
|
2022-04-08 04:54:11 +00:00
|
|
|
if rc.isOk:
|
2022-01-10 09:04:06 +00:00
|
|
|
gasUsed = gasUsed + rc.value
|
2018-12-12 04:16:40 +00:00
|
|
|
|
2023-08-02 10:17:40 +00:00
|
|
|
result = tracerInst.getTracingResult()
|
2018-12-12 04:31:53 +00:00
|
|
|
result["gas"] = %gasUsed
|
|
|
|
|
2018-12-12 15:18:46 +00:00
|
|
|
if TracerFlags.DisableState notin tracerFlags:
|
2024-08-01 10:41:20 +00:00
|
|
|
result.dumpMemoryDB(cc.cpt)
|
|
|
|
|
|
|
|
proc traceTransactionsImpl(
|
|
|
|
com: CommonRef;
|
|
|
|
header: BlockHeader;
|
|
|
|
transactions: openArray[Transaction];
|
|
|
|
): JsonNode
|
|
|
|
{.raises: [CatchableError].} =
|
2018-12-25 10:31:51 +00:00
|
|
|
result = newJArray()
|
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
|
|
|
for i in 0 ..< transactions.len:
|
2024-08-01 10:41:20 +00:00
|
|
|
result.add traceTransactionImpl(
|
|
|
|
com, header, transactions, i.uint64, {DisableState})
|
2018-12-25 10:31:51 +00:00
|
|
|
|
2024-03-21 10:45:57 +00:00
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
proc dumpDebuggingMetaDataImpl(
|
|
|
|
vmState: BaseVMState;
|
|
|
|
blk: EthBlock;
|
|
|
|
launchDebugger = true;
|
|
|
|
) {.raises: [CatchableError].} =
|
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
|
|
|
template header: BlockHeader = blk.header
|
2024-08-01 10:41:20 +00:00
|
|
|
|
2018-12-25 10:31:51 +00:00
|
|
|
let
|
2024-08-01 10:41:20 +00:00
|
|
|
cc = activate CaptCtxRef.init(vmState.com, header)
|
2024-06-14 07:31:08 +00:00
|
|
|
blockNumber = header.number
|
2019-02-03 09:08:13 +00:00
|
|
|
bloom = createBloom(vmState.receipts)
|
2024-08-01 10:41:20 +00:00
|
|
|
|
|
|
|
defer: cc.release()
|
2019-02-03 09:08:13 +00:00
|
|
|
|
|
|
|
let blockSummary = %{
|
2024-06-14 07:31:08 +00:00
|
|
|
"receiptsRoot": %("0x" & toHex(calcReceiptsRoot(vmState.receipts).data)),
|
2021-10-28 09:42:39 +00:00
|
|
|
"stateRoot": %("0x" & toHex(vmState.stateDB.rootHash.data)),
|
2019-02-03 09:08:13 +00:00
|
|
|
"logsBloom": %("0x" & toHex(bloom))
|
|
|
|
}
|
2018-12-25 10:31:51 +00:00
|
|
|
|
|
|
|
var metaData = %{
|
|
|
|
"blockNumber": %blockNumber.toHex,
|
2024-08-01 10:41:20 +00:00
|
|
|
"txTraces": traceTransactionsImpl(vmState.com, header, blk.transactions),
|
|
|
|
"stateDump": dumpBlockStateImpl(vmState.com, blk),
|
|
|
|
"blockTrace": traceBlockImpl(vmState.com, blk, {DisableState}),
|
2019-02-03 09:08:13 +00:00
|
|
|
"receipts": toJson(vmState.receipts),
|
|
|
|
"block": blockSummary
|
2018-12-25 10:31:51 +00:00
|
|
|
}
|
|
|
|
|
2024-08-01 10:41:20 +00:00
|
|
|
metaData.dumpMemoryDB(cc.cpt)
|
2019-01-12 12:48:28 +00:00
|
|
|
|
|
|
|
let jsonFileName = "debug" & $blockNumber & ".json"
|
|
|
|
if launchDebugger:
|
|
|
|
launchPremix(jsonFileName, metaData)
|
|
|
|
else:
|
|
|
|
writeFile(jsonFileName, metaData.pretty())
|
2024-08-01 10:41:20 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc traceBlock*(
|
|
|
|
com: CommonRef;
|
|
|
|
blk: EthBlock;
|
|
|
|
tracerFlags: set[TracerFlags] = {};
|
|
|
|
): JsonNode =
|
|
|
|
"traceBlock".safeTracer:
|
|
|
|
result = com.traceBlockImpl(blk, tracerFlags)
|
|
|
|
|
|
|
|
proc toJson*(receipts: seq[Receipt]): JsonNode =
|
|
|
|
result = newJArray()
|
|
|
|
for receipt in receipts:
|
|
|
|
result.add receipt.toJson
|
|
|
|
|
|
|
|
proc dumpMemoryDB*(node: JsonNode, cpt: CoreDbCaptRef) =
|
|
|
|
var n = newJObject()
|
|
|
|
for (k,v) in cpt.kvtLog:
|
|
|
|
n[k.toHex(false)] = %v
|
|
|
|
node["state"] = n
|
|
|
|
|
|
|
|
proc dumpReceipts*(chainDB: CoreDbRef, header: BlockHeader): JsonNode =
|
|
|
|
"dumpReceipts".safeTracer:
|
|
|
|
result = chainDB.dumpReceiptsImpl header
|
|
|
|
|
|
|
|
proc traceTransaction*(
|
|
|
|
com: CommonRef;
|
|
|
|
header: BlockHeader;
|
|
|
|
txs: openArray[Transaction];
|
|
|
|
txIndex: uint64;
|
|
|
|
tracerFlags: set[TracerFlags] = {};
|
|
|
|
): JsonNode =
|
|
|
|
"traceTransaction".safeTracer:
|
|
|
|
result = com.traceTransactionImpl(header, txs, txIndex,tracerFlags)
|
|
|
|
|
|
|
|
proc dumpBlockState*(
|
|
|
|
com: CommonRef;
|
|
|
|
blk: EthBlock;
|
|
|
|
dumpState = false;
|
|
|
|
): JsonNode =
|
|
|
|
"dumpBlockState".safeTracer:
|
|
|
|
result = com.dumpBlockStateImpl(blk, dumpState)
|
|
|
|
|
|
|
|
proc traceTransactions*(
|
|
|
|
com: CommonRef;
|
|
|
|
header: BlockHeader;
|
|
|
|
transactions: openArray[Transaction];
|
|
|
|
): JsonNode =
|
|
|
|
"traceTransactions".safeTracer:
|
|
|
|
result = com.traceTransactionsImpl(header, transactions)
|
|
|
|
|
|
|
|
proc dumpDebuggingMetaData*(
|
|
|
|
vmState: BaseVMState;
|
|
|
|
blk: EthBlock;
|
|
|
|
launchDebugger = true;
|
|
|
|
) =
|
|
|
|
"dumpDebuggingMetaData".safeTracer:
|
|
|
|
vmState.dumpDebuggingMetaDataImpl(blk, launchDebugger)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|