nimbus-eth1/premix/premix.nim

62 lines
1.7 KiB
Nim
Raw Normal View History

2019-01-09 11:40:25 +00:00
import
2019-01-09 12:10:58 +00:00
json, downloader, stint, strutils, os,
2019-01-10 17:44:53 +00:00
../nimbus/tracer, chronicles, prestate,
2019-07-07 10:12:01 +00:00
js_tracer, eth/common, stew/byteutils, parser,
nimcrypto, premixcore
2019-01-09 11:40:25 +00:00
proc generateGethData(thisBlock: Block, blockNumber: Uint256, accounts: JsonNode): JsonNode =
2019-01-09 11:40:25 +00:00
let
receipts = toJson(thisBlock.receipts)
let geth = %{
2019-01-09 11:40:25 +00:00
"blockNumber": %blockNumber.toHex,
"txTraces": thisBlock.traces,
"receipts": receipts,
"block": thisBlock.jsonData,
"accounts": accounts
}
result = geth
2019-01-09 11:40:25 +00:00
2019-01-09 12:10:58 +00:00
proc printDebugInstruction(blockNumber: Uint256) =
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)
geth = generateGethData(thisBlock, blockNumber, accounts)
parentNumber = blockNumber - 1.u256
parentBlock = requestBlock(parentNumber)
2019-01-09 12:10:58 +00:00
processNimbusData(nimbus)
2019-01-12 05:19:02 +00:00
# premix data goes to report page
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
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)
2019-01-15 08:55:39 +00:00
except:
echo getCurrentExceptionMsg()
2019-01-09 11:40:25 +00:00
main()