nimbus-eth1/premix/premix.nim

61 lines
1.7 KiB
Nim
Raw Normal View History

2019-01-09 18:40:25 +07:00
import
2019-01-09 19:10:58 +07:00
json, downloader, stint, strutils, os,
2019-01-11 00:44:53 +07:00
../nimbus/tracer, chronicles, prestate,
2020-07-21 13:15:06 +07:00
eth/common, premixcore
2019-01-09 18:40:25 +07:00
2022-04-08 11:54:11 +07:00
proc generateGethData(thisBlock: Block, blockNumber: UInt256, accounts: JsonNode): JsonNode =
2019-01-09 18:40:25 +07:00
let
receipts = toJson(thisBlock.receipts)
let geth = %{
2019-01-09 18:40:25 +07:00
"blockNumber": %blockNumber.toHex,
"txTraces": thisBlock.traces,
"receipts": receipts,
"block": thisBlock.jsonData,
"accounts": accounts
}
result = geth
2019-01-09 18:40:25 +07:00
2022-04-08 11:54:11 +07:00
proc printDebugInstruction(blockNumber: UInt256) =
2019-01-09 19:10:58 +07: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 18:40:25 +07:00
proc main() =
2019-01-09 19:10:58 +07:00
if paramCount() == 0:
2019-01-10 15:23:18 +07:00
echo "usage: premix debugxxx.json"
2019-01-09 19:10:58 +07:00
quit(QuitFailure)
2019-01-15 15:55:39 +07:00
try:
2019-01-09 19:10:58 +07:00
let
nimbus = json.parseFile(paramStr(1))
blockNumber = UInt256.fromHex(nimbus["blockNumber"].getStr())
2019-01-15 12:06:46 +07:00
thisBlock = requestBlock(blockNumber, {DownloadReceipts, DownloadTxTrace})
2019-01-11 00:44:53 +07:00
accounts = requestPostState(thisBlock)
geth = generateGethData(thisBlock, blockNumber, accounts)
parentNumber = blockNumber - 1.u256
parentBlock = requestBlock(parentNumber)
2019-01-09 19:10:58 +07:00
processNimbusData(nimbus)
2019-01-12 12:19:02 +07:00
# premix data goes to report page
generatePremixData(nimbus, geth)
2019-01-12 12:19:02 +07:00
# prestate data goes to debug tool and contains data
# needed to execute single block
generatePrestate(nimbus, geth, blockNumber, parentBlock.header, thisBlock.header, thisBlock.body)
2019-01-12 12:19:02 +07:00
2019-01-09 19:10:58 +07:00
printDebugInstruction(blockNumber)
2019-01-15 15:55:39 +07:00
except:
echo getCurrentExceptionMsg()
2019-01-09 18:40:25 +07:00
main()