From 83e576f6bf222296a47f359fe620840833d626c0 Mon Sep 17 00:00:00 2001 From: chainchad <96362174+chainchad@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:11:28 -0400 Subject: [PATCH 1/2] Add slack alerts for failing crib integrations (#14122) * Add slack alerts for failing crib integrations * Bump version to action with fix --- .github/workflows/crib-integration-test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/crib-integration-test.yml b/.github/workflows/crib-integration-test.yml index a67ac641bf9..0dda07f285e 100644 --- a/.github/workflows/crib-integration-test.yml +++ b/.github/workflows/crib-integration-test.yml @@ -73,7 +73,7 @@ jobs: echo $GITHUB_WORKSPACE - name: Deploy and validate CRIB Environment for Core - uses: smartcontractkit/.github/actions/crib-deploy-environment@c0b38e6c40d72d01b8d2f24f92623a2538b3dedb # crib-deploy-environment@0.5.0 + uses: smartcontractkit/.github/actions/crib-deploy-environment@9a4954089045a765eca4bac68f396b2df5a5ea25 # crib-deploy-environment@0.7.1 id: deploy-crib with: github-token: ${{ steps.token.outputs.access-token }} @@ -85,6 +85,7 @@ jobs: ingress-base-domain: ${{ secrets.INGRESS_BASE_DOMAIN_STAGE }} k8s-cluster-name: ${{ secrets.AWS_K8S_CLUSTER_NAME_STAGE }} devspace-profiles: "local-dev-simulated-core-ocr1" + crib-alert-slack-webhook: ${{ secrets.CRIB_ALERT_SLACK_WEBHOOK }} - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - name: Setup go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 @@ -99,7 +100,7 @@ jobs: CRIB_NODES: 5 GAP_URL: ${{ secrets.GAP_URL }} SETH_LOG_LEVEL: info -# RESTY_DEBUG: true + # RESTY_DEBUG: true TEST_PERSISTENCE: true run: |- go test -v -run TestCRIB @@ -108,4 +109,4 @@ jobs: if: always() && steps.deploy-crib.outputs.devspace-namespace != '' uses: smartcontractkit/.github/actions/crib-purge-environment@c0b38e6c40d72d01b8d2f24f92623a2538b3dedb # crib-purge-environment@0.1.0 with: - namespace: ${{ steps.deploy-crib.outputs.devspace-namespace }} \ No newline at end of file + namespace: ${{ steps.deploy-crib.outputs.devspace-namespace }} From 3f0fad643d554d2445273a67f58974cb6a785ec4 Mon Sep 17 00:00:00 2001 From: Juan Farber Date: Wed, 14 Aug 2024 16:52:49 -0300 Subject: [PATCH 2/2] [BCI-3863] - Use filtered logs in eventBinding GetLatestValue instead of manual filtering (#14096) * Use filtered logs in eventBinding GetLatestValue instead of manual filtering * handle one filter simple expression case for topic filters * and instead of or for matching all topic filters conditions * add changeset * nit comment to reduce createTopicFilters func * add address to query name in GetLatestValue and QueryKey * key not necessary as we are using logpoller filters --- .changeset/early-glasses-rhyme.md | 5 ++ core/services/relay/evm/event_binding.go | 67 ++++++++++-------------- 2 files changed, 32 insertions(+), 40 deletions(-) create mode 100644 .changeset/early-glasses-rhyme.md diff --git a/.changeset/early-glasses-rhyme.md b/.changeset/early-glasses-rhyme.md new file mode 100644 index 00000000000..aa35bf897ea --- /dev/null +++ b/.changeset/early-glasses-rhyme.md @@ -0,0 +1,5 @@ +--- +"chainlink": minor +--- + +use FilteredLogs in EventBinding GetLatestValue instead of manual filtering. #internal diff --git a/core/services/relay/evm/event_binding.go b/core/services/relay/evm/event_binding.go index 97ddc99a107..7b62d862b35 100644 --- a/core/services/relay/evm/event_binding.go +++ b/core/services/relay/evm/event_binding.go @@ -169,7 +169,7 @@ func (e *eventBinding) QueryKey(ctx context.Context, filter query.KeyFilter, lim } remapped.Expressions = append(defaultExpressions, remapped.Expressions...) - logs, err := e.lp.FilteredLogs(ctx, remapped, limitAndSort, e.contractName+"-"+e.eventName) + logs, err := e.lp.FilteredLogs(ctx, remapped, limitAndSort, e.contractName+"-"+e.address.String()+"-"+e.eventName) if err != nil { return nil, err } @@ -227,32 +227,41 @@ func (e *eventBinding) getLatestValueWithFilters( return err } - fai := filtersAndIndices[0] - remainingFilters := filtersAndIndices[1:] - - logs, err := e.lp.IndexedLogs(ctx, e.hash, e.address, 1, []common.Hash{fai}, confs) + // Create limiter and filter for the query. + limiter := query.NewLimitAndSort(query.CountLimit(1), query.NewSortBySequence(query.Desc)) + filter, err := query.Where( + "", + logpoller.NewAddressFilter(e.address), + logpoller.NewEventSigFilter(e.hash), + logpoller.NewConfirmationsFilter(confs), + createTopicFilters(filtersAndIndices), + ) if err != nil { return wrapInternalErr(err) } - // TODO Use filtered logs here BCF-3316 - // TODO: there should be a better way to ask log poller to filter these - // First, you should be able to ask for as many topics to match - // Second, you should be able to get the latest only - var logToUse *logpoller.Log - for _, log := range logs { - tmp := log - if compareLogs(&tmp, logToUse) > 0 && matchesRemainingFilters(&tmp, remainingFilters) { - // copy so that it's not pointing to the changing variable - logToUse = &tmp - } + // Gets the latest log that matches the filter and limiter. + logs, err := e.lp.FilteredLogs(ctx, filter, limiter, e.contractName+"-"+e.address.String()+"-"+e.eventName) + if err != nil { + return wrapInternalErr(err) } - if logToUse == nil { + if len(logs) == 0 { return fmt.Errorf("%w: no events found", commontypes.ErrNotFound) } - return e.decodeLog(ctx, logToUse, into) + return e.decodeLog(ctx, &logs[0], into) +} + +func createTopicFilters(filtersAndIndices []common.Hash) query.Expression { + var expressions []query.Expression + for topicID, fai := range filtersAndIndices { + // first topic index is 1-based, so we add 1. + expressions = append(expressions, logpoller.NewEventByTopicFilter( + uint64(topicID+1), []primitives.ValueComparator{{Value: fai.Hex(), Operator: primitives.Eq}}, + )) + } + return query.And(expressions...) } // convertToOffChainType creates a struct based on contract abi with applied codec modifiers. @@ -270,28 +279,6 @@ func (e *eventBinding) convertToOffChainType(params any) (any, error) { return offChain, nil } -func compareLogs(log, use *logpoller.Log) int64 { - if use == nil { - return 1 - } - - if log.BlockNumber != use.BlockNumber { - return log.BlockNumber - use.BlockNumber - } - - return log.LogIndex - use.LogIndex -} - -func matchesRemainingFilters(log *logpoller.Log, filters []common.Hash) bool { - for i, rfai := range filters { - if !reflect.DeepEqual(rfai[:], log.Topics[i+2]) { - return false - } - } - - return true -} - // encodeParams accepts nativeParams and encodes them to match onchain topics. func (e *eventBinding) encodeParams(nativeParams reflect.Value) ([]common.Hash, error) { for nativeParams.Kind() == reflect.Pointer {