Skip to content

Commit

Permalink
Register lp filter for chain reader in median provider constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Nov 13, 2023
1 parent 9393d07 commit 5e101de
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions core/services/relay/evm/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
}
Expand Down
6 changes: 5 additions & 1 deletion core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5e101de

Please sign in to comment.