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)
|
2021-10-28 09:42:39 +00:00
|
|
|
lastBlockHash: Hash256
|
2019-02-27 11:28:40 +00:00
|
|
|
|
|
|
|
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)
|
2021-07-30 14:06:51 +00:00
|
|
|
validationResult = vmState.processBlockNotPoA(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()
|