nimbus-eth1/premix/regress.nim

81 lines
1.9 KiB
Nim
Raw Normal View History

2019-02-27 11:28:40 +00:00
import
2020-07-21 06:15:06 +00:00
eth/[common, rlp], stint,
chronicles, configuration,
eth/trie/[hexary, db]
2019-02-27 11:28:40 +00:00
import
2020-07-21 06:15:06 +00:00
../nimbus/db/[db_chain, select_backend],
../nimbus/vm_state,
2019-02-27 11:28:40 +00:00
../nimbus/p2p/executor
const
numBlocks = 256
proc validateBlock(chainDB: BaseChainDB, blockNumber: BlockNumber): BlockNumber =
var
parentNumber = blockNumber - 1
parent = chainDB.getBlockHeader(parentNumber)
headers = newSeq[BlockHeader](numBlocks)
bodies = newSeq[BlockBody](numBlocks)
for i in 0 ..< numBlocks:
headers[i] = chainDB.getBlockHeader(blockNumber + i.u256)
bodies[i] = chainDB.getBlockBody(headers[i].blockHash)
let transaction = chainDB.db.beginTransaction()
defer: transaction.dispose()
for i in 0 ..< numBlocks:
stdout.write blockNumber + i.u256
stdout.write "\r"
let
vmState = newBaseVMState(parent.stateRoot, headers[i], chainDB)
Feature/goerli replay clique poa (#743) * extract unused clique/mining support into separate file why: mining is currently unsupported by nimbus * Replay first 51840 transactions from Goerli block chain why: Currently Goerli is loaded but the block headers are not verified. Replaying allows real data PoA development. details: Simple stupid gzipped dump/undump layer for debugging based on the zlib module (no nim-faststream support.) This is a replay running against p2p/chain.persistBlocks() where the data were captured from. * prepare stubs for PoA engine * split executor source into sup-modules why: make room for updates, clique integration should go into executor/update_poastate.nim * Simplify p2p/executor.processBlock() function prototype why: vmState argument always wraps basicChainDB * split processBlock() into sub-functions why: isolate the part where it will support clique/poa * provided additional processTransaction() function prototype without _fork_ argument why: with the exception of some tests, the _fork_ argument is always derived from the other prototype argument _vmState_ details: similar situation with makeReceipt() * provide new processBlock() version explicitly supporting PoA details: The new processBlock() version supporting PoA is the general one also supporting non-PoA networks, it needs an additional _Clique_ descriptor function argument for PoA state (if any.) The old processBlock() function without the _Clique_ descriptor argument retorns an error on PoA networgs (e.g. Goerli.) * re-implemented Clique descriptor as _ref object_ why: gives more flexibility when moving around the descriptor object details: also cleaned up a bit the clique sources * comments for clarifying handling of Clique/PoA state descriptor
2021-07-06 13:14:45 +00:00
validationResult = vmState.processBlock(headers[i], bodies[i])
2019-02-27 11:28:40 +00:00
if validationResult != ValidationResult.OK:
error "block validation error", validationResult, blockNumber = blockNumber + i.u256
parent = headers[i]
transaction.rollback()
result = blockNumber + numBlocks.u256
2020-07-21 06:15:06 +00:00
proc main() {.used.} =
2019-02-27 11:28:40 +00:00
let
conf = getConfiguration()
db = newChainDb(conf.dataDir)
trieDB = trieDB db
chainDB = newBaseChainDB(trieDB, false)
# move head to block number ...
if conf.head == 0.u256:
raise newException(ValueError, "please set block number with --head: blockNumber")
var counter = 0
var blockNumber = conf.head
while true:
blockNumber = chainDB.validateBlock(blockNumber)
inc counter
if conf.maxBlocks != 0 and counter >= conf.maxBlocks:
break
when isMainModule:
var message: string
## Processing command line arguments
if processArguments(message) != Success:
echo message
quit(QuitFailure)
else:
if len(message) > 0:
echo message
quit(QuitSuccess)
try:
main()
except:
echo getCurrentExceptionMsg()