From b7709d7bda10d52d8aedd7d125502875309df3ec Mon Sep 17 00:00:00 2001 From: Will Winder Date: Mon, 1 Apr 2024 17:48:59 -0400 Subject: [PATCH] Fix error --- .../plugins/ccip/tokendata/observability/usdc_client_test.go | 2 +- core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/tokendata/observability/usdc_client_test.go b/core/services/ocr2/plugins/ccip/tokendata/observability/usdc_client_test.go index cf88e42bb67..a9453cf0d89 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/observability/usdc_client_test.go +++ b/core/services/ocr2/plugins/ccip/tokendata/observability/usdc_client_test.go @@ -90,7 +90,7 @@ func testMonitoring(t *testing.T, name string, server *httptest.Server, requests usdcTokenAddr := utils.RandomAddress() observedHttpClient := http2.NewObservedIHttpClientWithMetric(&http2.HttpClient{}, histogram) tokenDataReaderDefault := usdc.NewUSDCTokenDataReader(log, usdcReader, attestationURI, 0, usdcTokenAddr, 0) - tokenDataReader := usdc.NewUSDCTokenDataReaderWithHttpClient(*tokenDataReaderDefault, observedHttpClient, usdcTokenAddr) + tokenDataReader := usdc.NewUSDCTokenDataReaderWithHttpClient(*tokenDataReaderDefault, observedHttpClient, usdcTokenAddr, 0) require.NotNil(t, tokenDataReader) for i := 0; i < requests; i++ { diff --git a/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go b/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go index 905bd6b1279..59a4c3db915 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go +++ b/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go @@ -131,6 +131,7 @@ func NewUSDCTokenDataReaderWithHttpClient( origin TokenDataReader, httpClient http.IHttpClient, usdcTokenAddress common.Address, + requestInterval time.Duration, ) *TokenDataReader { return &TokenDataReader{ lggr: origin.lggr, @@ -140,6 +141,7 @@ func NewUSDCTokenDataReaderWithHttpClient( attestationApiTimeout: origin.attestationApiTimeout, coolDownMu: origin.coolDownMu, usdcTokenAddress: usdcTokenAddress, + rate: rate.NewLimiter(rate.Every(requestInterval), 1), } } @@ -154,7 +156,7 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E } // Using 'Allow' instead of 'Wait' to avoid blocking the current goroutine. - if !s.rate.Allow() { + if s.rate != nil && !s.rate.Allow() { // self rate limiting to avoid hitting the rate limit. return nil, tokendata.ErrSelfRateLimit }