add 'DownloadAndValidate' flag to premix downloader

This commit is contained in:
andri lim 2019-03-13 09:07:05 +07:00 committed by zah
parent 62082fb5f1
commit 72cebff516
1 changed files with 19 additions and 17 deletions

View File

@ -16,6 +16,7 @@ type
DownloadFlags* = enum DownloadFlags* = enum
DownloadReceipts DownloadReceipts
DownloadTxTrace DownloadTxTrace
DownloadAndValidate
proc request*(methodName: string, params: JsonNode): JsonNode = proc request*(methodName: string, params: JsonNode): JsonNode =
var client = newRpcHttpClient() var client = newRpcHttpClient()
@ -87,14 +88,6 @@ proc requestBlock*(blockNumber: BlockNumber, flags: set[DownloadFlags] = {}): Bl
if DownloadTxTrace in flags: if DownloadTxTrace in flags:
result.traces = requestTxTraces(header) result.traces = requestTxTraces(header)
let
txRoot = calcTxRoot(result.body.transactions).prefixHex
txRootOK = result.header.txRoot.prefixHex
ommersHash = rlpHash(result.body.uncles).prefixHex
ommersHashOK = result.header.ommersHash.prefixHex
headerHash = rlpHash(result.header).prefixHex
headerHashOK = header["hash"].getStr().toLowerAscii
if DownloadReceipts in flags: if DownloadReceipts in flags:
result.receipts = requestReceipts(header) result.receipts = requestReceipts(header)
let let
@ -104,6 +97,15 @@ proc requestBlock*(blockNumber: BlockNumber, flags: set[DownloadFlags] = {}): Bl
debug "wrong receipt root", receiptRoot, receiptRootOK, blockNumber debug "wrong receipt root", receiptRoot, receiptRootOK, blockNumber
raise newException(ValueError, "Error when validating receipt root") raise newException(ValueError, "Error when validating receipt root")
if DownloadAndValidate in flags:
let
txRoot = calcTxRoot(result.body.transactions).prefixHex
txRootOK = result.header.txRoot.prefixHex
ommersHash = rlpHash(result.body.uncles).prefixHex
ommersHashOK = result.header.ommersHash.prefixHex
headerHash = rlpHash(result.header).prefixHex
headerHashOK = header["hash"].getStr().toLowerAscii
if txRoot != txRootOK: if txRoot != txRootOK:
debug "wrong tx root", txRoot, txRootOK, blockNumber debug "wrong tx root", txRoot, txRootOK, blockNumber
raise newException(ValueError, "Error when validating tx root") raise newException(ValueError, "Error when validating tx root")