Skip to content

Commit

Permalink
Fix error handling from USDC rate limiting call. (#1036)
Browse files Browse the repository at this point in the history
Fix bug where USDC rate limiter was checking the wrong error response.
  • Loading branch information
winder authored Jun 20, 2024
1 parent 050b3c0 commit 62b7b60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func NewUSDCTokenDataReaderWithHttpClient(
// attestation response. When called back to back, or multiple times
// concurrently, responses are delayed according how the request interval is
// configured.
func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2EVMOnRampCCIPSendRequestedWithMeta, tokenIndex int) (messageAndAttestation []byte, err error) {
func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2EVMOnRampCCIPSendRequestedWithMeta, tokenIndex int) ([]byte, error) {
if tokenIndex < 0 || tokenIndex >= len(msg.TokenAmounts) {
return nil, fmt.Errorf("token index out of bounds")
}
Expand All @@ -177,7 +177,7 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E
if s.rate != nil {
// Wait blocks until it the attestation API can be called or the
// context is Done.
if waitErr := s.rate.Wait(ctx); err != nil {
if waitErr := s.rate.Wait(ctx); waitErr != nil {
return nil, fmt.Errorf("usdc rate limiting error: %w", waitErr)
}
}
Expand All @@ -197,7 +197,7 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E
switch attestationResp.Status {
case attestationStatusSuccess:
// The USDC pool needs a combination of the message body and the attestation
messageAndAttestation, err = encodeMessageAndAttestation(messageBody, attestationResp.Attestation)
messageAndAttestation, err := encodeMessageAndAttestation(messageBody, attestationResp.Attestation)
if err != nil {
return nil, fmt.Errorf("failed to encode messageAndAttestation : %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions core/services/ocr2/plugins/ccip/tokendata/usdc/usdc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ func TestUSDCReader_rateLimiting(t *testing.T) {
rateConfig: 100 * time.Millisecond,
testDuration: 1 * time.Millisecond,
timeout: 1 * time.Millisecond,
err: "usdc rate limiting error: rate: Wait(n=1) would exceed context deadline",
err: "usdc rate limiting error:",
},
{
name: "timeout after second request",
requests: 5,
rateConfig: 100 * time.Millisecond,
testDuration: 100 * time.Millisecond,
timeout: 150 * time.Millisecond,
err: "usdc rate limiting error: rate: Wait(n=1) would exceed context deadline",
err: "usdc rate limiting error:",
},
}

Expand Down Expand Up @@ -405,14 +405,15 @@ func TestUSDCReader_rateLimiting(t *testing.T) {
// Collect errors
errorFound := false
for err := range errorChan {
if tc.err != "" && !strings.Contains(err.Error(), tc.err) {
if tc.err != "" && strings.Contains(err.Error(), tc.err) {
errorFound = true
} else if err != nil && !strings.Contains(err.Error(), "get usdc token 0 end offset") {
// Ignore that one error, it's expected because of how mocking is used.
// Anything else is unexpected.
require.Fail(t, "unexpected error", err)
}
}

if tc.err != "" {
assert.True(t, errorFound)
}
Expand Down

0 comments on commit 62b7b60

Please sign in to comment.