mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 22:04:52 +00:00
800fd77333
* Rename `newKvt()` -> `ctx.getKvt()` why: Clean up legacy shortcut. Also, the `KVT` returned is not instantiated but refers to the shared `KVT` that resides in a context which is a generalisation of an in-memory database fork. The function `ctx` retrieves the default context. * Rename `newTransaction()` -> `ctx.newTransaction()` why: Clean up legacy shortcut. The transaction is applied to a context as a generalisation of an in-memory database fork. The function `ctx` retrieves the default context. * Rename `getColumn(CtGeneric)` -> `getGeneric()` why: No more a list of well known sub-tries needed, a single one is enough. In fact, `getColumn()` did only support a single sub-tree by now. * Reduce TODO list
47 lines
1.6 KiB
Nim
47 lines
1.6 KiB
Nim
# Nimbus
|
|
# Copyright (c) 2020-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/strutils,
|
|
json, stew/byteutils,
|
|
results,
|
|
../nimbus/db/[core_db, storage_types], eth/[rlp, common],
|
|
../nimbus/tracer
|
|
|
|
proc generatePrestate*(nimbus, geth: JsonNode, blockNumber: BlockNumber, parent: BlockHeader, blk: EthBlock) =
|
|
template header: BlockHeader = blk.header
|
|
let
|
|
state = nimbus["state"]
|
|
headerHash = rlpHash(header)
|
|
chainDB = newCoreDbRef(DefaultDbMemory)
|
|
kvt = chainDB.ctx.getKvt()
|
|
|
|
discard chainDB.setHead(parent, true)
|
|
chainDB.persistTransactions(blockNumber, header.txRoot, blk.transactions)
|
|
discard chainDB.persistUncles(blk.uncles)
|
|
|
|
kvt.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header)).isOkOr:
|
|
raiseAssert "generatePrestate(): put() failed " & $$error
|
|
chainDB.addBlockNumberToHashLookup(header.number, headerHash)
|
|
|
|
for k, v in state:
|
|
let key = hexToSeqByte(k)
|
|
let value = hexToSeqByte(v.getStr())
|
|
kvt.put(key, value).isOkOr:
|
|
raiseAssert "generatePrestate(): put() (loop) failed " & $$error
|
|
|
|
var metaData = %{
|
|
"blockNumber": %blockNumber.toHex,
|
|
"geth": geth
|
|
}
|
|
|
|
metaData.dumpMemoryDB(chainDB)
|
|
writeFile("block" & $blockNumber & ".json", metaData.pretty())
|