eth/protocols: skip unavailable receipts

This commit is contained in:
healthykim 2026-04-16 22:26:13 +02:00
parent f63e9f3a80
commit 765a37f426
2 changed files with 15 additions and 4 deletions

View file

@ -589,6 +589,11 @@ func testGetBlockReceipts(t *testing.T, protocol uint) {
receipts rlp.RawList[*ReceiptList] receipts rlp.RawList[*ReceiptList]
) )
for i := uint64(0); i <= backend.chain.CurrentBlock().Number.Uint64(); i++ { for i := uint64(0); i <= backend.chain.CurrentBlock().Number.Uint64(); i++ {
if i == 1 {
// Insert a missing block hash to verify the server returns a nil placeholder
hashes = append(hashes, common.HexToHash("0xdeadbeef"))
receipts.Append(nil)
}
block := backend.chain.GetBlockByNumber(i) block := backend.chain.GetBlockByNumber(i)
hashes = append(hashes, block.Hash()) hashes = append(hashes, block.Hash())
br := backend.chain.GetReceiptsByHash(block.Hash()) br := backend.chain.GetReceiptsByHash(block.Hash())

View file

@ -281,15 +281,18 @@ func ServiceGetReceiptsQuery69(chain *core.BlockChain, query GetReceiptsRequest)
// Retrieve the requested block's receipts // Retrieve the requested block's receipts
results := chain.GetReceiptsRLP(hash) results := chain.GetReceiptsRLP(hash)
if results == nil { if results == nil {
continue // Can't retrieve the receipts, so we just skip this block. receipts.Append(nil)
continue
} }
body := chain.GetBodyRLP(hash) body := chain.GetBodyRLP(hash)
if body == nil { if body == nil {
continue // The block body is missing, we also have to skip. receipts.Append(nil)
continue
} }
results, _, err := blockReceiptsToNetwork(results, body, receiptQueryParams{}) results, _, err := blockReceiptsToNetwork(results, body, receiptQueryParams{})
if err != nil { if err != nil {
log.Error("Error in block receipts conversion", "hash", hash, "err", err) log.Error("Error in block receipts conversion", "hash", hash, "err", err)
receipts.Append(nil)
continue continue
} }
receipts.AppendRaw(results) receipts.AppendRaw(results)
@ -313,11 +316,13 @@ func serviceGetReceiptsQuery70(chain *core.BlockChain, query GetReceiptsRequest,
} }
results := chain.GetReceiptsRLP(hash) results := chain.GetReceiptsRLP(hash)
if results == nil { if results == nil {
continue // Can't retrieve the receipts, so we just skip this block. receipts.Append(nil)
continue
} }
body := chain.GetBodyRLP(hash) body := chain.GetBodyRLP(hash)
if body == nil { if body == nil {
continue // The block body is missing, we also have to skip. receipts.Append(nil)
continue
} }
q := receiptQueryParams{sizeLimit: uint64(maxPacketSize - bytes)} q := receiptQueryParams{sizeLimit: uint64(maxPacketSize - bytes)}
if i == 0 { if i == 0 {
@ -326,6 +331,7 @@ func serviceGetReceiptsQuery70(chain *core.BlockChain, query GetReceiptsRequest,
results, incomplete, err := blockReceiptsToNetwork(results, body, q) results, incomplete, err := blockReceiptsToNetwork(results, body, q)
if err != nil { if err != nil {
log.Error("Error in block receipts conversion", "hash", hash, "err", err) log.Error("Error in block receipts conversion", "hash", hash, "err", err)
receipts.Append(nil)
continue continue
} }
if results == nil { if results == nil {