Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle edgecase where indexer hangs when a block has 0 transactions #247

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/clients/ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)))
Expand Down
Loading