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))
|
|
|
|
blockNumber = UInt256.fromHex(nimbus["blockNumber"].getStr())
|
2019-01-15 05:06:46 +00:00
|
|
|
thisBlock = requestBlock(blockNumber, {DownloadReceipts, DownloadTxTrace})
|
2019-01-10 17:44:53 +00:00
|
|
|
accounts = requestPostState(thisBlock)
|
2019-01-14 11:49:18 +00:00
|
|
|
geth = generateGethData(thisBlock, blockNumber, accounts)
|
|
|
|
parentNumber = blockNumber - 1.u256
|
|
|
|
parentBlock = requestBlock(parentNumber)
|
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()
|