@@ -126,15 +126,48 @@ func GetBlock(ctx context.Context, odr OdrBackend, hash common.Hash, number uint
126126// GetBlockReceipts retrieves the receipts generated by the transactions included
127127// in a block given by its hash.
128128func GetBlockReceipts (ctx context.Context , odr OdrBackend , hash common.Hash , number uint64 ) (types.Receipts , error ) {
129+ // Retrieve the potentially incomplete receipts from disk or network
129130 receipts := core .GetBlockReceipts (odr .Database (), hash , number )
130- if receipts != nil {
131- return receipts , nil
131+ if receipts == nil {
132+ r := & ReceiptsRequest {Hash : hash , Number : number }
133+ if err := odr .Retrieve (ctx , r ); err != nil {
134+ return nil , err
135+ }
136+ receipts = r .Receipts
132137 }
133- r := & ReceiptsRequest {Hash : hash , Number : number }
134- if err := odr .Retrieve (ctx , r ); err != nil {
135- return nil , err
138+ // If the receipts are incomplete, fill the derived fields
139+ if len (receipts ) > 0 && receipts [0 ].TxHash == (common.Hash {}) {
140+ block , err := GetBlock (ctx , odr , hash , number )
141+ if err != nil {
142+ return nil , err
143+ }
144+ genesis := core .GetCanonicalHash (odr .Database (), 0 )
145+ config , _ := core .GetChainConfig (odr .Database (), genesis )
146+
147+ core .SetReceiptsData (config , block , receipts )
148+ core .WriteBlockReceipts (odr .Database (), hash , number , receipts )
149+ }
150+ return receipts , nil
151+ }
152+
153+ // GetBlockLogs retrieves the logs generated by the transactions included in a
154+ // block given by its hash.
155+ func GetBlockLogs (ctx context.Context , odr OdrBackend , hash common.Hash , number uint64 ) ([][]* types.Log , error ) {
156+ // Retrieve the potentially incomplete receipts from disk or network
157+ receipts := core .GetBlockReceipts (odr .Database (), hash , number )
158+ if receipts == nil {
159+ r := & ReceiptsRequest {Hash : hash , Number : number }
160+ if err := odr .Retrieve (ctx , r ); err != nil {
161+ return nil , err
162+ }
163+ receipts = r .Receipts
164+ }
165+ // Return the logs without deriving any computed fields on the receipts
166+ logs := make ([][]* types.Log , len (receipts ))
167+ for i , receipt := range receipts {
168+ logs [i ] = receipt .Logs
136169 }
137- return r . Receipts , nil
170+ return logs , nil
138171}
139172
140173// GetBloomBits retrieves a batch of compressed bloomBits vectors belonging to the given bit index and section indexes
0 commit comments