From 817bce3555a7dc119289a91907ef9e250c038a02 Mon Sep 17 00:00:00 2001 From: andri lim Date: Sun, 3 Feb 2019 16:08:13 +0700 Subject: [PATCH] premix report page: modify header section to display block summary --- nimbus/p2p/chain.nim | 2 +- nimbus/tracer.nim | 12 ++++++++++-- premix/assets/js/index.js | 5 +++++ premix/debug.nim | 2 +- premix/dumper.nim | 2 +- premix/hunter.nim | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/nimbus/p2p/chain.nim b/nimbus/p2p/chain.nim index 7742e57fd..01e1fde8d 100644 --- a/nimbus/p2p/chain.nim +++ b/nimbus/p2p/chain.nim @@ -47,7 +47,7 @@ method persistBlocks*(c: Chain, headers: openarray[BlockHeader], bodies: openarr when not defined(release): if validationResult == ValidationResult.Error: - dumpDebuggingMetaData(c.db, headers[i], bodies[i], vmState.receipts) + dumpDebuggingMetaData(c.db, headers[i], bodies[i], vmState) raise newException(Exception, "Validation error. Debugging metadata dumped.") if validationResult != ValidationResult.OK: diff --git a/nimbus/tracer.nim b/nimbus/tracer.nim index c58d26305..62c1ebd0c 100644 --- a/nimbus/tracer.nim +++ b/nimbus/tracer.nim @@ -232,7 +232,7 @@ proc traceTransactions*(chainDB: BaseChainDB, header: BlockHeader, blockBody: Bl result.add traceTransaction(chainDB, header, blockBody, i, {DisableState}) proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader, - blockBody: BlockBody, receipts: seq[Receipt], launchDebugger = true) = + blockBody: BlockBody, vmState: BaseVMState, launchDebugger = true) = let blockNumber = header.blockNumber @@ -241,13 +241,21 @@ proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader, captureDB = newCaptureDB(chainDB.db, memoryDB) captureTrieDB = trieDB captureDB captureChainDB = newBaseChainDB(captureTrieDB, false) + bloom = createBloom(vmState.receipts) + + let blockSummary = %{ + "receiptsRoot": %("0x" & toHex(calcReceiptRoot(vmState.receipts).data)), + "stateRoot": %("0x" & toHex(vmState.accountDb.rootHash.data)), + "logsBloom": %("0x" & toHex(bloom)) + } var metaData = %{ "blockNumber": %blockNumber.toHex, "txTraces": traceTransactions(captureChainDB, header, blockBody), "stateDump": dumpBlockState(captureChainDB, header, blockBody), "blockTrace": traceBlock(captureChainDB, header, blockBody, {DisableState}), - "receipts": toJson(receipts) + "receipts": toJson(vmState.receipts), + "block": blockSummary } metaData.dumpMemoryDB(memoryDB) diff --git a/premix/assets/js/index.js b/premix/assets/js/index.js index fe7494d30..edeca4a1b 100644 --- a/premix/assets/js/index.js +++ b/premix/assets/js/index.js @@ -367,6 +367,11 @@ function headerRenderer(nimbus, geth) { let container = $('#headerContainer').empty(); $('#headerTitle').text('Block #' + parseInt(geth.block.number, 16)); + let body = premix.newTable(container); + const blockSummary = ['stateRoot', 'receiptsRoot', 'logsBloom']; + for(var idx of blockSummary) { + premix.renderRow(body, nimbus.block, geth.block, idx); + } } function generateNavigation(txs, nimbus, geth) { diff --git a/premix/debug.nim b/premix/debug.nim index 1540f9bec..c4a7d9333 100644 --- a/premix/debug.nim +++ b/premix/debug.nim @@ -28,7 +28,7 @@ proc executeBlock(blockEnv: JsonNode, memoryDB: TrieDatabaseRef, blockNumber: Ui else: info "block validation success", validationResult, blockNumber - dumpDebuggingMetaData(chainDB, header, body, vmState.receipts, false) + dumpDebuggingMetaData(chainDB, header, body, vmState, false) let fileName = "debug" & $blockNumber & ".json" nimbus = json.parseFile(fileName) diff --git a/premix/dumper.nim b/premix/dumper.nim index aa8b58081..41ae4e71a 100644 --- a/premix/dumper.nim +++ b/premix/dumper.nim @@ -26,7 +26,7 @@ proc dumpDebug(chainDB: BaseChainDB, blockNumber: Uint256) = captureChainDB.setHead(parent, true) let validationResult = processBlock(captureChainDB, parent, header, body, vmState) - dumpDebuggingMetaData(captureChainDB, header, body, vmState.receipts, false) + dumpDebuggingMetaData(captureChainDB, header, body, vmState, false) proc main() = let conf = getConfiguration() diff --git a/premix/hunter.nim b/premix/hunter.nim index ec42e8762..b80ee59de 100644 --- a/premix/hunter.nim +++ b/premix/hunter.nim @@ -75,7 +75,7 @@ proc huntProblematicBlock(blockNumber: Uint256): ValidationResult = if validationResult != ValidationResult.OK: transaction.dispose() - dumpDebuggingMetaData(chainDB, thisBlock.header, thisBlock.body, vmState.receipts, false) + dumpDebuggingMetaData(chainDB, thisBlock.header, thisBlock.body, vmState, false) result = validationResult