@@ -669,15 +669,20 @@ func deriveLogFields(receipts []*receiptLogs, hash common.Hash, number uint64, t
669
669
// ReadLogs retrieves the logs for all transactions in a block. The log fields
670
670
// are populated with metadata. In case the receipts or the block body
671
671
// are not found, a nil is returned.
672
- func ReadLogs (db ethdb.Reader , hash common.Hash , number uint64 ) [][]* types.Log {
672
+ func ReadLogs (db ethdb.Reader , hash common.Hash , number uint64 , config * params. ChainConfig ) [][]* types.Log {
673
673
// Retrieve the flattened receipt slice
674
674
data := ReadReceiptsRLP (db , hash , number )
675
675
if len (data ) == 0 {
676
676
return nil
677
677
}
678
678
receipts := []* receiptLogs {}
679
679
if err := rlp .DecodeBytes (data , & receipts ); err != nil {
680
- log .Error ("Invalid receipt array RLP" , "hash" , hash , "err" , err )
680
+ // Receipts might be in the legacy format, try decoding that.
681
+ // TODO: to be removed after users migrated
682
+ if logs := readLegacyLogs (db , hash , number , config ); logs != nil {
683
+ return logs
684
+ }
685
+ log .Error ("Invalid receipt array RLP" , "hash" , "err" , err )
681
686
return nil
682
687
}
683
688
@@ -697,6 +702,21 @@ func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log {
697
702
return logs
698
703
}
699
704
705
+ // readLegacyLogs is a temporary workaround for when trying to read logs
706
+ // from a block which has its receipt stored in the legacy format. It'll
707
+ // be removed after users have migrated their freezer databases.
708
+ func readLegacyLogs (db ethdb.Reader , hash common.Hash , number uint64 , config * params.ChainConfig ) [][]* types.Log {
709
+ receipts := ReadReceipts (db , hash , number , config )
710
+ if receipts == nil {
711
+ return nil
712
+ }
713
+ logs := make ([][]* types.Log , len (receipts ))
714
+ for i , receipt := range receipts {
715
+ logs [i ] = receipt .Logs
716
+ }
717
+ return logs
718
+ }
719
+
700
720
// ReadBlock retrieves an entire block corresponding to the hash, assembling it
701
721
// back from the stored header and body. If either the header or body could not
702
722
// be retrieved nil is returned.
0 commit comments