From af2deee7c96df93999ebd433293c76a85957cb92 Mon Sep 17 00:00:00 2001 From: Mateusz Sekara Date: Mon, 6 Nov 2023 18:17:57 +0100 Subject: [PATCH] CCIP-1261 Don't cache DB values on the USDC Reader level (#251) --- core/chains/evm/logpoller/observability.go | 2 +- .../ocr2/plugins/ccip/tokendata/usdc/usdc.go | 21 +++---------------- .../plugins/ccip/tokendata/usdc/usdc_test.go | 6 ------ 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/core/chains/evm/logpoller/observability.go b/core/chains/evm/logpoller/observability.go index 4e0ebe7418..c102bc42db 100644 --- a/core/chains/evm/logpoller/observability.go +++ b/core/chains/evm/logpoller/observability.go @@ -186,7 +186,7 @@ func (o *ObservedORM) SelectLogs(start, end int64, address common.Address, event }) } -func (o *ObservedORM) IndexedLogsByTxHash(eventSig common.Hash, txHash common.Hash, qopts ...pg.QOpt) ([]Log, error) { +func (o *ObservedORM) SelectIndexedLogsByTxHash(eventSig common.Hash, txHash common.Hash, qopts ...pg.QOpt) ([]Log, error) { return withObservedQueryAndResults(o, "IndexedLogsByTxHash", func() ([]Log, error) { return o.ORM.SelectIndexedLogsByTxHash(eventSig, txHash, qopts...) }) diff --git a/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go b/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go index 684df2bf4d..8f36886c4c 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go +++ b/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc.go @@ -9,7 +9,6 @@ import ( "net/http" "net/url" "strings" - "sync" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" @@ -67,9 +66,6 @@ type TokenDataReader struct { lggr logger.Logger usdcReader ccipdata.USDCReader attestationApi *url.URL - // Cache of sequence number -> usdc message body - usdcMessageHashCache map[uint64][]byte - usdcMessageHashCacheMutex sync.Mutex } type attestationResponse struct { @@ -81,10 +77,9 @@ var _ tokendata.Reader = &TokenDataReader{} func NewUSDCTokenDataReader(lggr logger.Logger, usdcReader ccipdata.USDCReader, usdcAttestationApi *url.URL) *TokenDataReader { return &TokenDataReader{ - lggr: lggr, - usdcReader: usdcReader, - attestationApi: usdcAttestationApi, - usdcMessageHashCache: make(map[uint64][]byte), + lggr: lggr, + usdcReader: usdcReader, + attestationApi: usdcAttestationApi, } } @@ -130,21 +125,11 @@ func encodeMessageAndAttestation(messageBody []byte, attestation string) ([]byte } func (s *TokenDataReader) getUSDCMessageBody(ctx context.Context, msg internal.EVM2EVMOnRampCCIPSendRequestedWithMeta) ([]byte, error) { - s.usdcMessageHashCacheMutex.Lock() - defer s.usdcMessageHashCacheMutex.Unlock() - - if body, ok := s.usdcMessageHashCache[msg.SequenceNumber]; ok { - return body, nil - } - parsedMsgBody, err := s.usdcReader.GetLastUSDCMessagePriorToLogIndexInTx(ctx, int64(msg.LogIndex), msg.TxHash) if err != nil { return []byte{}, err } s.lggr.Infow("Got USDC message body", "messageBody", hexutil.Encode(parsedMsgBody), "messageID", hexutil.Encode(msg.MessageId[:])) - - // Save the attempt in the cache in case the external call fails - s.usdcMessageHashCache[msg.SequenceNumber] = parsedMsgBody return parsedMsgBody, nil } diff --git a/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc_test.go b/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc_test.go index 4f7b8fa05f..91c647871c 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc_test.go +++ b/core/services/ocr2/plugins/ccip/tokendata/usdc/usdc_test.go @@ -106,10 +106,4 @@ func TestGetUSDCMessageBody(t *testing.T) { require.Equal(t, body, expectedBody) usdcReader.AssertNumberOfCalls(t, "GetLastUSDCMessagePriorToLogIndexInTx", 1) - - // Make another call and assert that the cache is used - body, err = usdcService.getUSDCMessageBody(context.Background(), internal.EVM2EVMOnRampCCIPSendRequestedWithMeta{}) - require.NoError(t, err) - require.Equal(t, body, expectedBody) - usdcReader.AssertNumberOfCalls(t, "GetLastUSDCMessagePriorToLogIndexInTx", 1) }