chore: add sanity check for receipts and transaction length

This commit is contained in:
10gic 2025-09-25 10:50:40 +08:00
parent 148d074a36
commit 9e3c25a676

View file

@ -569,6 +569,11 @@ func filterReceipts(txHashes []common.Hash, ev core.ChainEvent) []*ReceiptWithTx
receipts := ev.Receipts receipts := ev.Receipts
txs := ev.Transactions txs := ev.Transactions
if len(receipts) != len(txs) {
log.Warn("Receipts and transactions length mismatch", "receipts", len(receipts), "transactions", len(txs))
return ret
}
if len(txHashes) == 0 { if len(txHashes) == 0 {
// No filter, send all receipts with their transactions. // No filter, send all receipts with their transactions.
ret = make([]*ReceiptWithTx, len(receipts)) ret = make([]*ReceiptWithTx, len(receipts))
@ -582,7 +587,7 @@ func filterReceipts(txHashes []common.Hash, ev core.ChainEvent) []*ReceiptWithTx
// Filter by single transaction hash. // Filter by single transaction hash.
// This is a common case, so we distinguish it from filtering by multiple tx hashes and made a small optimization. // This is a common case, so we distinguish it from filtering by multiple tx hashes and made a small optimization.
for i, receipt := range receipts { for i, receipt := range receipts {
if receipt.TxHash == (txHashes)[0] { if receipt.TxHash == txHashes[0] {
ret = append(ret, &ReceiptWithTx{ ret = append(ret, &ReceiptWithTx{
Receipt: receipt, Receipt: receipt,
Transaction: txs[i], Transaction: txs[i],