Fix ReceiptType in premix + Apply validate flag for receipts (#2012)

This commit is contained in:
Kim De Mey 2024-02-08 11:50:35 +01:00 committed by GitHub
parent beb13b2c40
commit 7b2dc8f8e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 8 deletions

View File

@ -120,12 +120,13 @@ proc requestBlock*(
if DownloadReceipts in flags:
result.receipts = requestReceipts(header, client)
let
receiptRoot = calcReceiptRoot(result.receipts).prefixHex
receiptRootOK = result.header.receiptRoot.prefixHex
if receiptRoot != receiptRootOK:
debug "wrong receipt root", receiptRoot, receiptRootOK, blockNumber
raise newException(ValueError, "Error when validating receipt root")
if DownloadAndValidate in flags:
let
receiptRoot = calcReceiptRoot(result.receipts).prefixHex
receiptRootOK = result.header.receiptRoot.prefixHex
if receiptRoot != receiptRootOK:
debug "wrong receipt root", receiptRoot, receiptRootOK, blockNumber
raise newException(ValueError, "Error when validating receipt root")
if DownloadAndValidate in flags:
let

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2020-2023 Status Research & Development GmbH
# Copyright (c) 2020-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -15,6 +15,8 @@ import
import ../nimbus/transaction, ../nimbus/utils/ec_recover
from stew/objects import checkedEnumAssign
template stripLeadingZeros(value: string): string =
var cidx = 0
# ignore the last character so we retain '0' on zero value
@ -225,7 +227,15 @@ proc parseLogs(n: JsonNode): seq[Log] =
result = @[]
proc parseReceipt*(n: JsonNode): Receipt =
var rec = Receipt(receiptType: LegacyReceipt)
var recType: byte
n.fromJson "type", recType
var txVal: ReceiptType
var rec =
if checkedEnumAssign(txVal, recType):
Receipt(receiptType: txVal)
else:
raise newException(ValueError, "Unknown receipt type")
if n.hasKey("root"):
var hash: Hash256
n.fromJson "root", hash