mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 22:04:52 +00:00
f68a5d419f
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.
50 lines
1.7 KiB
Nim
50 lines
1.7 KiB
Nim
# Nimbus
|
|
# Copyright (c) 2018-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, os, tables, strutils],
|
|
unittest2,
|
|
stew/byteutils,
|
|
./test_helpers,
|
|
../nimbus/core/chain,
|
|
../nimbus/common/common
|
|
|
|
# use tracerTestGen.nim to generate additional test data
|
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
|
|
var
|
|
blockNumber = UInt256.fromHex(node["blockNumber"].getStr())
|
|
memoryDB = newCoreDbRef DefaultDbMemory
|
|
config = chainConfigForNetwork(MainNet)
|
|
com = CommonRef.new(memoryDB, nil, config)
|
|
state = node["state"]
|
|
|
|
for k, v in state:
|
|
let key = hexToSeqByte(k)
|
|
let value = hexToSeqByte(v.getStr())
|
|
memoryDB.kvt.put(key, value)
|
|
|
|
let
|
|
parentNumber = blockNumber - 1
|
|
parent = com.db.getBlockHeader(parentNumber)
|
|
blk = com.db.getEthBlock(blockNumber)
|
|
chain = newChain(com)
|
|
|
|
# it's ok if setHead fails here because of missing ancestors
|
|
discard com.db.setHead(parent, true)
|
|
let validationResult = chain.persistBlocks([blk])
|
|
check validationResult.isOk()
|
|
|
|
proc persistBlockJsonMain*() =
|
|
suite "persist block json tests":
|
|
jsonTest("PersistBlockTests", testFixture)
|
|
#var testStatusIMPL: TestStatus
|
|
#let n = json.parseFile("tests" / "fixtures" / "PersistBlockTests" / "block420301.json")
|
|
#testFixture(n, testStatusIMPL)
|
|
|
|
when isMainModule:
|
|
persistBlockJsonMain()
|