2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2020-2023 Status Research & Development GmbH
|
|
|
|
# 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 11:40:25 +00:00
|
|
|
import
|
2022-12-02 04:39:12 +00:00
|
|
|
std/[json, strutils, os],
|
|
|
|
downloader, stint,
|
2023-08-04 11:10:09 +00:00
|
|
|
../nimbus/tracer, prestate,
|
2020-07-21 06:15:06 +00:00
|
|
|
eth/common, premixcore
|
2019-01-09 11:40:25 +00:00
|
|
|
|
2022-04-08 04:54:11 +00:00
|
|
|
proc generateGethData(thisBlock: Block, blockNumber: UInt256, accounts: JsonNode): JsonNode =
|
2019-01-09 11:40:25 +00:00
|
|
|
let
|
|
|
|
receipts = toJson(thisBlock.receipts)
|
|
|
|
|
2019-01-14 11:49:18 +00:00
|
|
|
let geth = %{
|
2019-01-09 11:40:25 +00:00
|
|
|
"blockNumber": %blockNumber.toHex,
|
|
|
|
"txTraces": thisBlock.traces,
|
|
|
|
"receipts": receipts,
|
|
|
|
"block": thisBlock.jsonData,
|
|
|
|
"accounts": accounts
|
|
|
|
}
|
|
|
|
|
2019-01-14 11:49:18 +00:00
|
|
|
result = geth
|
2019-01-09 11:40:25 +00:00
|
|
|
|
2022-04-08 04:54:11 +00:00
|
|
|
proc printDebugInstruction(blockNumber: UInt256) =
|
2019-01-09 12:10:58 +00:00
|
|
|
var text = """
|
|
|
|
|
|
|
|
Successfully created debugging environment for block $1.
|
|
|
|
You can continue to find nimbus EVM bug by viewing premix report page `./index.html`.
|
|
|
|
After that you can try to debug that single block using `nim c -r debug block$1.json` command.
|
|
|
|
|
|
|
|
Happy bug hunting
|
|
|
|
""" % [$blockNumber]
|
|
|
|
|
|
|
|
echo text
|
|
|
|
|
2019-01-09 11:40:25 +00:00
|
|
|
proc main() =
|
2019-01-09 12:10:58 +00:00
|
|
|
if paramCount() == 0:
|
2019-01-10 08:23:18 +00:00
|
|
|
echo "usage: premix debugxxx.json"
|
2019-01-09 12:10:58 +00:00
|
|
|
quit(QuitFailure)
|
|
|
|
|
2019-01-15 08:55:39 +00:00
|
|
|
try:
|
2019-01-09 12:10:58 +00:00
|
|
|
let
|
|
|
|
nimbus = json.parseFile(paramStr(1))
|
2024-05-13 08:00:13 +00:00
|
|
|
chainId = nimbus["chainId"].getInt().ChainId
|
2019-01-09 12:10:58 +00:00
|
|
|
blockNumber = UInt256.fromHex(nimbus["blockNumber"].getStr())
|
2024-05-13 08:00:13 +00:00
|
|
|
thisBlock = requestBlock(
|
|
|
|
blockNumber, chainId, {DownloadReceipts, DownloadTxTrace})
|
|
|
|
accounts = requestPostState(thisBlock, chainId)
|
2019-01-14 11:49:18 +00:00
|
|
|
geth = generateGethData(thisBlock, blockNumber, accounts)
|
|
|
|
parentNumber = blockNumber - 1.u256
|
2024-05-13 08:00:13 +00:00
|
|
|
parentBlock = requestBlock(parentNumber, chainId)
|
2019-01-09 12:10:58 +00:00
|
|
|
|
2019-01-14 11:49:18 +00:00
|
|
|
processNimbusData(nimbus)
|
2019-01-12 05:19:02 +00:00
|
|
|
|
|
|
|
# premix data goes to report page
|
2019-01-14 11:49:18 +00:00
|
|
|
generatePremixData(nimbus, geth)
|
2019-01-12 05:19:02 +00:00
|
|
|
|
|
|
|
# prestate data goes to debug tool and contains data
|
|
|
|
# needed to execute single block
|
2019-01-14 11:49:18 +00:00
|
|
|
generatePrestate(nimbus, geth, blockNumber, parentBlock.header, thisBlock.header, thisBlock.body)
|
2019-01-12 05:19:02 +00:00
|
|
|
|
2019-01-09 12:10:58 +00:00
|
|
|
printDebugInstruction(blockNumber)
|
2023-08-04 11:10:09 +00:00
|
|
|
except CatchableError:
|
2019-01-15 08:55:39 +00:00
|
|
|
echo getCurrentExceptionMsg()
|
2019-01-09 11:40:25 +00:00
|
|
|
|
|
|
|
main()
|