2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-03-20 07:35:38 +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-02-27 11:28:40 +00:00
|
|
|
import
|
2023-08-04 11:10:09 +00:00
|
|
|
chronicles,
|
2022-01-18 16:19:32 +00:00
|
|
|
../nimbus/[vm_state, vm_types],
|
2022-12-02 04:39:12 +00:00
|
|
|
../nimbus/core/executor,
|
2023-08-04 11:10:09 +00:00
|
|
|
../nimbus/common/common,
|
|
|
|
../nimbus/db/core_db/persistent,
|
|
|
|
configuration # must be late (compilation annoyance)
|
2019-02-27 11:28:40 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
numBlocks = 256
|
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
proc validateBlock(com: CommonRef, blockNumber: BlockNumber): BlockNumber =
|
2019-02-27 11:28:40 +00:00
|
|
|
var
|
|
|
|
parentNumber = blockNumber - 1
|
2022-12-02 04:39:12 +00:00
|
|
|
parent = com.db.getBlockHeader(parentNumber)
|
2019-02-27 11:28:40 +00:00
|
|
|
headers = newSeq[BlockHeader](numBlocks)
|
|
|
|
bodies = newSeq[BlockBody](numBlocks)
|
|
|
|
|
|
|
|
for i in 0 ..< numBlocks:
|
2022-12-02 04:39:12 +00:00
|
|
|
headers[i] = com.db.getBlockHeader(blockNumber + i.u256)
|
|
|
|
bodies[i] = com.db.getBlockBody(headers[i].blockHash)
|
2019-02-27 11:28:40 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
let transaction = com.db.beginTransaction()
|
2019-02-27 11:28:40 +00:00
|
|
|
defer: transaction.dispose()
|
|
|
|
|
|
|
|
for i in 0 ..< numBlocks:
|
|
|
|
stdout.write blockNumber + i.u256
|
|
|
|
stdout.write "\r"
|
|
|
|
|
|
|
|
let
|
2022-12-02 04:39:12 +00:00
|
|
|
vmState = BaseVMState.new(parent, headers[i], com)
|
2023-10-05 03:04:12 +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()
|
2023-08-04 11:10:09 +00:00
|
|
|
com = CommonRef.new(newCoreDbRef(LegacyDbPersistent, conf.dataDir), false)
|
2019-02-27 11:28:40 +00:00
|
|
|
|
|
|
|
# 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:
|
2022-12-02 04:39:12 +00:00
|
|
|
blockNumber = com.validateBlock(blockNumber)
|
2019-02-27 11:28:40 +00:00
|
|
|
|
|
|
|
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()
|