diff --git a/execute/tokendata/usdc/attestation.go b/execute/tokendata/usdc/attestation.go index 3450c0a0..21cce663 100644 --- a/execute/tokendata/usdc/attestation.go +++ b/execute/tokendata/usdc/attestation.go @@ -88,22 +88,22 @@ func NewSequentialAttestationClient( func (s *sequentialAttestationClient) Attestations( ctx context.Context, - msgs map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.Bytes, + messagesByChain map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.Bytes, ) (map[cciptypes.ChainSelector]map[reader.MessageTokenID]AttestationStatus, error) { outcome := make(map[cciptypes.ChainSelector]map[reader.MessageTokenID]AttestationStatus) - for chainSelector, hashes := range msgs { + for chainSelector, messagesByTokenID := range messagesByChain { outcome[chainSelector] = make(map[reader.MessageTokenID]AttestationStatus) - for tokenID, messageHash := range hashes { + for tokenID, message := range messagesByTokenID { s.lggr.Debugw( "Fetching attestation from the API", "chainSelector", chainSelector, - "messageHash", messageHash, + "message", message, "messageTokenID", tokenID, ) // TODO sequential processing - outcome[chainSelector][tokenID] = s.fetchSingleMessage(ctx, messageHash) + outcome[chainSelector][tokenID] = s.fetchSingleMessage(ctx, message) } } return outcome, nil @@ -111,14 +111,14 @@ func (s *sequentialAttestationClient) Attestations( func (s *sequentialAttestationClient) fetchSingleMessage( ctx context.Context, - messageHash cciptypes.Bytes, + message cciptypes.Bytes, ) AttestationStatus { - response, _, err := s.client.Get(ctx, s.hasher.Hash(messageHash)) + response, _, err := s.client.Get(ctx, s.hasher.Hash(message)) if err != nil { return ErrorAttestationStatus(err) } - return SuccessAttestationStatus(messageHash, response) + return SuccessAttestationStatus(message, response) } type FakeAttestationClient struct { @@ -127,15 +127,15 @@ type FakeAttestationClient struct { func (f FakeAttestationClient) Attestations( _ context.Context, - msgs map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.Bytes, + messagesByChain map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.Bytes, ) (map[cciptypes.ChainSelector]map[reader.MessageTokenID]AttestationStatus, error) { outcome := make(map[cciptypes.ChainSelector]map[reader.MessageTokenID]AttestationStatus) - for chainSelector, hashes := range msgs { + for chainSelector, messagesByTokenID := range messagesByChain { outcome[chainSelector] = make(map[reader.MessageTokenID]AttestationStatus) - for tokenID, messageHash := range hashes { - outcome[chainSelector][tokenID] = f.Data[string(messageHash)] + for tokenID, message := range messagesByTokenID { + outcome[chainSelector][tokenID] = f.Data[string(message)] } } return outcome, nil diff --git a/execute/tokendata/usdc/usdc.go b/execute/tokendata/usdc/usdc.go index 156df20a..c60a3d92 100644 --- a/execute/tokendata/usdc/usdc.go +++ b/execute/tokendata/usdc/usdc.go @@ -60,14 +60,14 @@ func (u *TokenDataObserver) Observe( // 1. Pick only messages that contain USDC tokens usdcMessages := u.pickOnlyUSDCMessages(messages) - // 2. Fetch USDC messages hashes based on the `MessageSent (bytes message)` event - usdcMessageHashes, err := u.fetchUSDCMessageHashes(ctx, usdcMessages) + // 2. Fetch USDC messages by token id based on the `MessageSent (bytes message)` event + usdcMessagesByTokenID, err := u.fetchUSDCEventMessages(ctx, usdcMessages) if err != nil { return nil, err } // 3. Fetch attestations for USDC messages - attestations, err := u.fetchAttestations(ctx, usdcMessageHashes) + attestations, err := u.fetchAttestations(ctx, usdcMessagesByTokenID) if err != nil { return nil, err } @@ -116,7 +116,7 @@ func (u *TokenDataObserver) pickOnlyUSDCMessages( return usdcMessages } -func (u *TokenDataObserver) fetchUSDCMessageHashes( +func (u *TokenDataObserver) fetchUSDCEventMessages( ctx context.Context, usdcMessages map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.RampTokenAmount, ) (map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.Bytes, error) { @@ -128,7 +128,7 @@ func (u *TokenDataObserver) fetchUSDCMessageHashes( } // TODO Sequential reading USDC messages from the source chain - usdcHashes, err := u.usdcMessageReader.MessageHashes(ctx, chainSelector, u.destChainSelector, messages) + msgByTokenID, err := u.usdcMessageReader.MessagesByTokenID(ctx, chainSelector, u.destChainSelector, messages) if err != nil { u.lggr.Errorw( "Failed fetching USDC events from the source chain", @@ -139,7 +139,7 @@ func (u *TokenDataObserver) fetchUSDCMessageHashes( ) return nil, err } - output[chainSelector] = usdcHashes + output[chainSelector] = msgByTokenID } return output, nil } diff --git a/pkg/reader/usdc_reader.go b/pkg/reader/usdc_reader.go index b2600a5c..e811811b 100644 --- a/pkg/reader/usdc_reader.go +++ b/pkg/reader/usdc_reader.go @@ -21,7 +21,7 @@ import ( ) type USDCMessageReader interface { - MessageHashes(ctx context.Context, + MessagesByTokenID(ctx context.Context, source, dest cciptypes.ChainSelector, tokens map[MessageTokenID]cciptypes.RampTokenAmount, ) (map[MessageTokenID]cciptypes.Bytes, error) @@ -133,7 +133,7 @@ func AllAvailableDomains() map[uint64]uint32 { return destDomains } -func (u usdcMessageReader) MessageHashes( +func (u usdcMessageReader) MessagesByTokenID( ctx context.Context, source, dest cciptypes.ChainSelector, tokens map[MessageTokenID]cciptypes.RampTokenAmount, @@ -207,7 +207,7 @@ func (u usdcMessageReader) MessageHashes( // 3. Remapping database events to the proper MessageTokenID out := make(map[MessageTokenID]cciptypes.Bytes) for tokenID, messageID := range eventIDs { - messageHash, ok1 := messageSentEvents[messageID] + message, ok1 := messageSentEvents[messageID] if !ok1 { // Token not available in the source chain, it should never happen at this stage u.lggr.Warnw("Message not found in the source chain", @@ -217,7 +217,7 @@ func (u usdcMessageReader) MessageHashes( ) continue } - out[tokenID] = messageHash + out[tokenID] = message } return out, nil @@ -323,7 +323,7 @@ func NewFakeUSDCMessageReader(messages map[MessageTokenID]cciptypes.Bytes) FakeU return FakeUSDCMessageReader{Messages: messages} } -func (f FakeUSDCMessageReader) MessageHashes( +func (f FakeUSDCMessageReader) MessagesByTokenID( _ context.Context, _, _ cciptypes.ChainSelector, tokens map[MessageTokenID]cciptypes.RampTokenAmount, diff --git a/pkg/reader/usdc_reader_test.go b/pkg/reader/usdc_reader_test.go index fe339a02..0b2b94e0 100644 --- a/pkg/reader/usdc_reader_test.go +++ b/pkg/reader/usdc_reader_test.go @@ -114,7 +114,7 @@ func Test_USDCMessageReader_New(t *testing.T) { } } -func Test_USDCMessageReader_MessageHashes(t *testing.T) { +func Test_USDCMessageReader_MessagesByTokenID(t *testing.T) { ctx := tests.Context(t) emptyChain := cciptypes.ChainSelector(sel.ETHEREUM_MAINNET.Selector) emptyReader := reader.NewMockContractReaderFacade(t) @@ -227,7 +227,7 @@ func Test_USDCMessageReader_MessageHashes(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { - hashes, err1 := usdcReader.MessageHashes( + messages, err1 := usdcReader.MessagesByTokenID( tests.Context(t), tc.sourceSelector, tc.destSelector, @@ -239,8 +239,8 @@ func Test_USDCMessageReader_MessageHashes(t *testing.T) { require.ErrorContains(t, err1, tc.errorMessage) } else { require.NoError(t, err) - require.NotNil(t, hashes) - require.Equal(t, tc.expectedMsgIDs, maps.Keys(hashes)) + require.NotNil(t, messages) + require.Equal(t, tc.expectedMsgIDs, maps.Keys(messages)) } }) }