From 5e101de905b694f729176690f96b68cd3826d026 Mon Sep 17 00:00:00 2001 From: ilija Date: Mon, 13 Nov 2023 22:02:18 +0100 Subject: [PATCH] Register lp filter for chain reader in median provider constructor --- core/services/relay/evm/chain_reader.go | 29 +++++++++++++++++++++++++ core/services/relay/evm/evm.go | 6 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/core/services/relay/evm/chain_reader.go b/core/services/relay/evm/chain_reader.go index 99bdd64d58a..5bd9cbc8c65 100644 --- a/core/services/relay/evm/chain_reader.go +++ b/core/services/relay/evm/chain_reader.go @@ -5,13 +5,19 @@ import ( "fmt" "strings" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/pkg/errors" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" + evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" + "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" @@ -175,6 +181,29 @@ type chainReader struct { chain evm.Chain } +func registerLogPollerFilters(cr chainReader, contractAddress common.Address, contractName string) error { + chainContractReader, exists := cr.chainContractReaders[contractName] + if !exists { + return fmt.Errorf("%s contract is not defined in chain reader config", contractName) + } + + abiEvents := chainContractReader.ParsedContractABI.Events + for _, crd := range chainContractReader.ChainReaderDefinitions { + if crd.ReadType == types.Event { + eventSig := abiEvents[crd.ChainSpecificName].ID + err := cr.lp.RegisterFilter(logpoller.Filter{ + Name: crd.ChainSpecificName, + EventSigs: evmtypes.HashArray{eventSig}, + Addresses: evmtypes.AddressArray{contractAddress}, + }) + if err != nil { + return err + } + } + } + return nil +} + func (cr *chainReader) Encode(ctx context.Context, item any, itemType string) (ocrtypes.Report, error) { return nil, fmt.Errorf("Unimplemented method Encode called %w", relaytypes.ErrorChainReaderUnsupported{}) } diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 4dfd4b60b8c..3969c42adf9 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -11,11 +11,11 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" pkgerrors "github.com/pkg/errors" + "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median/evmreportcodec" "go.uber.org/multierr" "github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator" "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" - "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median/evmreportcodec" "github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" "github.com/smartcontractkit/sqlx" @@ -30,6 +30,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/keystore" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" + coremedianplugin "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/median" mercuryconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/mercury/config" "github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon" "github.com/smartcontractkit/chainlink/v2/core/services/pg" @@ -538,6 +539,9 @@ func (r *Relayer) NewMedianProvider(rargs relaytypes.RelayArgs, pargs relaytypes medianProvider.chainReader = nil } else { medianProvider.chainReader = chainReader + if err = registerLogPollerFilters(*chainReader, common.HexToAddress(rargs.ContractID), coremedianplugin.ContractName); err != nil { + return nil, err + } } return &medianProvider, nil