nimbus-eth1/tests/tracerTestGen.nim
Jacek Sieka 3d58393b4c
Offload signature checking to taskpools (#2927)
In block processing, depending on the complexity of a transaction and
hotness of caches etc, signature checking can actually make up the
majority of time needed to process a transaction (60% observed in some
randomly sampled block ranges).

Fortunately, this is a task that trivially can be offloaded to a task
pool similar to how nimbus-eth2 does it.

This PR introduces taskpools in the most simple way possible, by
performing signature checking concurrently with other TX processing,
assigning a taskpool task per TX effectively.

With this little trick, we're in gigagas land 🎉 on my laptop!

```
INF 2024-12-10 21:05:35.170+01:00 Imported blocks
blockNumber=3874817 b... mgps=1222.707 ...
```

Tests don't use the taskpool for now because it needs manual cleanup and
we don't have a good mechanism in place. Future PR:s should address this
by creating a common shutdown sequence that also closes and cleans up
other resources like the DB.

Co-authored-by: andri lim <jangko128@gmail.com>
2024-12-13 11:53:41 +07:00

75 lines
2.1 KiB
Nim

# Nimbus
# Copyright (c) 2019-2024 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.
import
std/[json, strutils],
results,
../nimbus/common/common, # must be early (compilation annoyance)
../nimbus/db/opts,
../nimbus/db/core_db/persistent,
../nimbus/[config, tracer, evm/types]
proc dumpTest(com: CommonRef, blockNumber: BlockNumber) =
var
capture = com.db.newCapture.value
captureCom = com.clone(capture.recorder)
let
blk = captureCom.db.getEthBlock(blockNumber)
txTrace = traceTransactions(captureCom, blk.header, blk.transactions)
stateDump = dumpBlockState(captureCom, blk)
blockTrace = traceBlock(captureCom, blk, {DisableState})
receipts = dumpReceipts(captureCom.db, blk.header)
var metaData = %{
"blockNumber": %blockNumber.toHex,
"txTraces": txTrace,
"stateDump": stateDump,
"blockTrace": blockTrace,
"receipts": receipts
}
metaData.dumpMemoryDB(capture)
writeFile("block" & $blockNumber & ".json", metaData.pretty())
proc main() {.used.} =
# 97 block with uncles
# 46147 block with first transaction
# 46400 block with transaction
# 46402 block with first contract: failed
# 47205 block with first success contract
# 48712 block with 5 transactions
# 48915 block with contract
# 49018 first problematic block
# 52029 first block with receipts logs
# 66407 failed transaction
# nimbus --rpc-api: eth, debug --prune: archive
var conf = makeConfig()
let db = newCoreDbRef(
DefaultDbPersistent, string conf.dataDir, DbOptions.init())
let com = CommonRef.new(db, nil)
com.dumpTest(97)
com.dumpTest(46147)
com.dumpTest(46400)
com.dumpTest(46402)
com.dumpTest(47205)
com.dumpTest(48712)
com.dumpTest(48915)
com.dumpTest(49018)
when isMainModule:
try:
main()
except:
echo getCurrentExceptionMsg()