nimbus-eth1/tests/persistBlockTestGen.nim

81 lines
2.4 KiB
Nim
Raw Normal View History

2018-12-25 12:10:04 +00:00
import
json, os, eth_common, stint, chronicles, byteutils, nimcrypto, rlp,
eth_trie/[db], ../nimbus/db/[db_chain, capturedb, storage_types],
../nimbus/[tracer, vm_types, config],
../nimbus/p2p/chain
const nimbus_db_backend {.strdefine.} = "rocksdb"
when nimbus_db_backend == "sqlite":
import ../nimbus/db/backends/sqlite_backend
elif nimbus_db_backend == "rocksdb":
import ../nimbus/db/backends/rocksdb_backend
else:
import ../nimbus/db/backends/lmdb_backend
proc putCanonicalHead(chainDB: BaseChainDB, header: BlockHeader) =
var headerHash = rlpHash(header)
chainDB.db.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))
chainDB.addBlockNumberToHashLookup(header)
chainDB.db.put(canonicalHeadHashKey().toOpenArray, rlp.encode(headerHash))
proc dumpTest(chainDB: BaseChainDB, blockNumber: int) =
let
blockNumber = blockNumber.u256
parentNumber = blockNumber - 1
var
memoryDB = newMemoryDB()
captureDB = newCaptureDB(chainDB.db, memoryDB)
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false)
let
parent = captureChainDB.getBlockHeader(parentNumber)
header = captureChainDB.getBlockHeader(blockNumber)
headerHash = header.blockHash
blockBody = captureChainDB.getBlockBody(headerHash)
chain = newChain(captureChainDB)
headers = @[header]
bodies = @[blockBody]
captureChainDB.putCanonicalHead(parent)
discard chain.persistBlocks(headers, bodies)
var metaData = %{
"blockNumber": %blockNumber.toHex
}
metaData.dumpMemoryDB(memoryDB)
writeFile("block" & $blockNumber & ".json", metaData.pretty())
proc main() =
# 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 --rpcapi: eth, debug --prune: archive
var conf = getConfiguration()
let db = newChainDb(conf.dataDir)
let trieDB = trieDB db
let chainDB = newBaseChainDB(trieDB, false)
chainDB.dumpTest(97)
chainDB.dumpTest(98) # not uncles and no tx
chainDB.dumpTest(46147)
chainDB.dumpTest(46400)
chainDB.dumpTest(46402)
chainDB.dumpTest(47205)
chainDB.dumpTest(48712)
chainDB.dumpTest(48915)
main()