@@ -2,6 +2,7 @@ package worker
22
33import (
44 "encoding/json"
5+ "fmt"
56 "math/big"
67 "strconv"
78
@@ -10,7 +11,7 @@ import (
1011)
1112
1213func SerializeWorkerResults (chainId * big.Int , blocks []BatchFetchResult [RawBlock ], logs []BatchFetchResult [RawLogs ], traces []BatchFetchResult [RawTraces ]) []WorkerResult {
13- results := make ([]WorkerResult , len (blocks ))
14+ results := make ([]WorkerResult , 0 , len (blocks ))
1415
1516 rawLogsMap := make (map [string ]BatchFetchResult [RawLogs ])
1617 for _ , rawLogs := range logs {
@@ -22,14 +23,20 @@ func SerializeWorkerResults(chainId *big.Int, blocks []BatchFetchResult[RawBlock
2223 rawTracesMap [rawTraces .BlockNumber .String ()] = rawTraces
2324 }
2425
25- for i , rawBlock := range blocks {
26+ for _ , rawBlock := range blocks {
2627 result := WorkerResult {
2728 BlockNumber : rawBlock .BlockNumber ,
2829 }
30+ if rawBlock .Result == nil {
31+ log .Warn ().Msgf ("Received a nil block result for block %s." , rawBlock .BlockNumber .String ())
32+ result .Error = fmt .Errorf ("received a nil block result from RPC" )
33+ results = append (results , result )
34+ continue
35+ }
2936
3037 if rawBlock .Error != nil {
3138 result .Error = rawBlock .Error
32- results [ i ] = result
39+ results = append ( results , result )
3340 continue
3441 }
3542
@@ -55,7 +62,7 @@ func SerializeWorkerResults(chainId *big.Int, blocks []BatchFetchResult[RawBlock
5562 }
5663 }
5764
58- results [ i ] = result
65+ results = append ( results , result )
5966 }
6067
6168 return results
0 commit comments