Skip to content

Commit

Permalink
feat: check for 429 in infinite retry
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Jul 4, 2024
1 parent 30b909c commit 19991bb
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions oracle/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,12 @@ func (i *infiniteRetryL1Client) BlockNumber(ctx context.Context) (uint64, error)
if err == nil {
break
}
i.logger.Error("failed to get block number, retrying...", "error", err)
if httpErr, ok := err.(interface{ StatusCode() int }); ok && httpErr.StatusCode() == 429 {
i.logger.Error("received 429 Too Many Requests, retrying...", "error", err)
} else {
i.logger.Error("failed to get block number", "error", err)
return 0, err
}
time.Sleep(1 * time.Second)
}
return blkNum, nil
Expand All @@ -433,7 +438,12 @@ func (i *infiniteRetryL1Client) HeaderByNumber(ctx context.Context, number *big.
if err == nil {
break
}
i.logger.Error("failed to get header by number, retrying...", "error", err)
if httpErr, ok := err.(interface{ StatusCode() int }); ok && httpErr.StatusCode() == 429 {
i.logger.Error("received 429 Too Many Requests, retrying...", "error", err)
} else {
i.logger.Error("failed to get header by number", "error", err)
return nil, err
}
time.Sleep(1 * time.Second)
}
return hdr, nil
Expand All @@ -447,7 +457,12 @@ func (i *infiniteRetryL1Client) BlockByNumber(ctx context.Context, number *big.I
if err == nil {
break
}
i.logger.Error("failed to get block by number, retrying...", "error", err)
if httpErr, ok := err.(interface{ StatusCode() int }); ok && httpErr.StatusCode() == 429 {
i.logger.Error("received 429 Too Many Requests, retrying...", "error", err)
} else {
i.logger.Error("failed to get block by number", "error", err)
return nil, err
}
time.Sleep(1 * time.Second)
}
return blk, nil
Expand Down

0 comments on commit 19991bb

Please sign in to comment.