diff --git a/pkg/clients/ethereum/client.go b/pkg/clients/ethereum/client.go index 8ec149a1..96a4b509 100644 --- a/pkg/clients/ethereum/client.go +++ b/pkg/clients/ethereum/client.go @@ -347,6 +347,10 @@ func (c *Client) batchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCR } func (c *Client) chunkedNativeBatchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCResponse, error) { + if len(requests) == 0 { + c.Logger.Sugar().Warnw("No requests to batch call") + return make([]*RPCResponse, 0), nil + } batches := [][]*RPCRequest{} currentIndex := 0 @@ -414,6 +418,10 @@ type BatchedResponse struct { // // This function allows for better retry and error handling over the batch call method. func (c *Client) chunkedBatchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCResponse, error) { + if len(requests) == 0 { + c.Logger.Sugar().Warnw("No requests to batch call") + return make([]*RPCResponse, 0), nil + } batches := [][]*IndexedRpcRequestResponse{} // all requests in a flat list with their index stored @@ -497,6 +505,10 @@ func (c *Client) chunkedBatchCall(ctx context.Context, requests []*RPCRequest) ( } func (c *Client) BatchCall(ctx context.Context, requests []*RPCRequest) ([]*RPCResponse, error) { + if len(requests) == 0 { + c.Logger.Sugar().Warnw("No requests to batch call") + return make([]*RPCResponse, 0), nil + } if c.clientConfig.UseNativeBatchCall { return c.chunkedNativeBatchCall(ctx, requests) } diff --git a/pkg/fetcher/fetcher.go b/pkg/fetcher/fetcher.go index 3224da23..5e1dc99d 100644 --- a/pkg/fetcher/fetcher.go +++ b/pkg/fetcher/fetcher.go @@ -64,6 +64,11 @@ func (f *Fetcher) FetchReceiptsForBlock(ctx context.Context, block *ethereum.Eth zap.Int("count", len(txReceiptRequests)), zap.Uint64("blockNumber", blockNumber), ) + receipts := make(map[string]*ethereum.EthereumTransactionReceipt) + + if len(txReceiptRequests) == 0 { + return receipts, nil + } receiptResponses, err := f.EthClient.BatchCall(ctx, txReceiptRequests) if err != nil { @@ -80,7 +85,6 @@ func (f *Fetcher) FetchReceiptsForBlock(ctx context.Context, block *ethereum.Eth return nil, errors.New("failed to fetch all transaction receipts") } - receipts := make(map[string]*ethereum.EthereumTransactionReceipt) for _, response := range receiptResponses { r, err := ethereum.RPCMethod_getTransactionReceipt.ResponseParser(response.Result) if err != nil { @@ -137,6 +141,10 @@ func (f *Fetcher) FetchBlocks(ctx context.Context, startBlockInclusive uint64, e blockNumbers = append(blockNumbers, i) } + if len(blockNumbers) == 0 { + return []*FetchedBlock{}, nil + } + blockRequests := make([]*ethereum.RPCRequest, 0) for i, n := range blockNumbers { blockRequests = append(blockRequests, ethereum.GetBlockByNumberRequest(n, uint(i)))