@@ -669,15 +669,20 @@ func deriveLogFields(receipts []*receiptLogs, hash common.Hash, number uint64, t
669669// ReadLogs retrieves the logs for all transactions in a block. The log fields
670670// are populated with metadata. In case the receipts or the block body
671671// 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 {
673673 // Retrieve the flattened receipt slice
674674 data := ReadReceiptsRLP (db , hash , number )
675675 if len (data ) == 0 {
676676 return nil
677677 }
678678 receipts := []* receiptLogs {}
679679 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 )
681686 return nil
682687 }
683688
@@ -697,6 +702,21 @@ func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log {
697702 return logs
698703}
699704
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+
700720// ReadBlock retrieves an entire block corresponding to the hash, assembling it
701721// back from the stored header and body. If either the header or body could not
702722// be retrieved nil is returned.
0 commit comments