2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-05-20 10:17:51 +00:00
|
|
|
# Copyright (c) 2020-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.
|
|
|
|
|
2019-01-09 08:46:19 +00:00
|
|
|
import
|
2023-08-04 11:10:09 +00:00
|
|
|
json, stint, stew/byteutils,
|
|
|
|
../nimbus/db/[core_db, storage_types], eth/[rlp, common],
|
2020-07-21 06:15:06 +00:00
|
|
|
../nimbus/tracer
|
2019-01-09 08:46:19 +00:00
|
|
|
|
2022-04-08 04:54:11 +00:00
|
|
|
proc generatePrestate*(nimbus, geth: JsonNode, blockNumber: UInt256, parent, header: BlockHeader, body: BlockBody) =
|
2019-01-09 08:46:19 +00:00
|
|
|
let
|
2019-01-14 11:49:18 +00:00
|
|
|
state = nimbus["state"]
|
|
|
|
headerHash = rlpHash(header)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
|
|
|
var
|
2024-05-20 10:17:51 +00:00
|
|
|
chainDB = newCoreDbRef(DefaultDbMemory)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
2022-07-04 05:35:56 +00:00
|
|
|
discard chainDB.setHead(parent, true)
|
2020-07-29 05:42:32 +00:00
|
|
|
discard chainDB.persistTransactions(blockNumber, body.transactions)
|
2019-01-14 11:49:18 +00:00
|
|
|
discard chainDB.persistUncles(body.uncles)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
chainDB.kvt.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))
|
2019-01-14 11:49:18 +00:00
|
|
|
chainDB.addBlockNumberToHashLookup(header)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
|
|
|
for k, v in state:
|
|
|
|
let key = hexToSeqByte(k)
|
|
|
|
let value = hexToSeqByte(v.getStr())
|
2023-08-04 11:10:09 +00:00
|
|
|
chainDB.kvt.put(key, value)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
|
|
|
var metaData = %{
|
2019-01-14 11:49:18 +00:00
|
|
|
"blockNumber": %blockNumber.toHex,
|
|
|
|
"geth": geth
|
2019-01-09 08:46:19 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
metaData.dumpMemoryDB(chainDB)
|
2019-01-09 08:46:19 +00:00
|
|
|
writeFile("block" & $blockNumber & ".json", metaData.pretty())
|