Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav committed Feb 13, 2024
1 parent 03b272a commit cc70a2f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
12 changes: 10 additions & 2 deletions core/services/relay/evm/config_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ func configPollerFilterName(addr common.Address) string {
return logpoller.FilterName("OCR2ConfigPoller", addr.String())
}

func NewConfigPoller(lggr logger.Logger, client client.Client, destChainPoller logpoller.LogPoller, aggregatorContractAddr common.Address, configStoreAddr *common.Address, ld LogDecoder) (evmRelayTypes.ConfigPoller, error) {
return newConfigPoller(lggr, client, destChainPoller, aggregatorContractAddr, configStoreAddr, ld)
type CPConfig struct {
Client client.Client
DestinationChainPoller logpoller.LogPoller
AggregatorContractAddress common.Address
ConfigStoreAddress *common.Address
LogDecoder LogDecoder
}

func NewConfigPoller(lggr logger.Logger, cfg CPConfig) (evmRelayTypes.ConfigPoller, error) {
return newConfigPoller(lggr, cfg.Client, cfg.DestinationChainPoller, cfg.AggregatorContractAddress, cfg.ConfigStoreAddress, cfg.LogDecoder)
}

func newConfigPoller(lggr logger.Logger, client client.Client, destChainPoller logpoller.LogPoller, aggregatorContractAddr common.Address, configStoreAddr *common.Address, ld LogDecoder) (*configPoller, error) {
Expand Down
4 changes: 2 additions & 2 deletions core/services/relay/evm/config_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestConfigPoller(t *testing.T) {
}

t.Run("LatestConfig errors if there is no config in logs and config store is unconfigured", func(t *testing.T) {
cp, err := NewConfigPoller(lggr, ethClient, lp, ocrAddress, nil, ld)
cp, err := NewConfigPoller(lggr, CPConfig{ethClient, lp, ocrAddress, nil, ld})
require.NoError(t, err)

_, err = cp.LatestConfig(testutils.Context(t), 0)
Expand All @@ -103,7 +103,7 @@ func TestConfigPoller(t *testing.T) {
})

t.Run("happy path (with config store)", func(t *testing.T) {
cp, err := NewConfigPoller(lggr, ethClient, lp, ocrAddress, &configStoreContractAddr, ld)
cp, err := NewConfigPoller(lggr, CPConfig{ethClient, lp, ocrAddress, &configStoreContractAddr, ld})
require.NoError(t, err)
// Should have no config to begin with.
_, configDigest, err := cp.LatestConfigDetails(testutils.Context(t))
Expand Down
40 changes: 19 additions & 21 deletions core/services/relay/evm/ocr2keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,28 @@ import (
"encoding/json"
"fmt"

iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
evm "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"

"github.com/smartcontractkit/chainlink-common/pkg/types/automation"

"github.com/ethereum/go-ethereum/common"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/plugin"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/automation"
"github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/plugin"

commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
evm "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
)

Expand Down Expand Up @@ -221,12 +217,14 @@ func newOCR2KeeperConfigProvider(lggr logger.Logger, chain legacyevm.Chain, rarg

configPoller, err := NewConfigPoller(
lggr.With("contractID", rargs.ContractID),
chain.Client(),
chain.LogPoller(),
contractAddress,
// TODO: Does ocr2keeper need to support config contract? DF-19182
nil,
OCR2AggregatorLogDecoder,
CPConfig{
chain.Client(),
chain.LogPoller(),
contractAddress,
// TODO: Does ocr2keeper need to support config contract? DF-19182
nil,
OCR2AggregatorLogDecoder,
},
)
if err != nil {
return nil, errors.Wrap(err, "failed to create config poller")
Expand Down
14 changes: 8 additions & 6 deletions core/services/relay/evm/ocr2vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ func newOCR2VRFConfigProvider(lggr logger.Logger, chain legacyevm.Chain, rargs c
contractAddress := common.HexToAddress(rargs.ContractID)
configPoller, err := NewConfigPoller(
lggr.With("contractID", rargs.ContractID),
chain.Client(),
chain.LogPoller(),
contractAddress,
// TODO: Does ocr2vrf need to support config contract? DF-19182
nil,
OCR2AggregatorLogDecoder,
CPConfig{
chain.Client(),
chain.LogPoller(),
contractAddress,
// TODO: Does ocr2vrf need to support config contract? DF-19182
nil,
OCR2AggregatorLogDecoder,
},
)
if err != nil {
return nil, err
Expand Down
16 changes: 9 additions & 7 deletions core/services/relay/evm/standard_config_provider.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package evm

import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
pkgerrors "github.com/pkg/errors"

"github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
Expand All @@ -16,7 +16,7 @@ import (

func newStandardConfigProvider(lggr logger.Logger, chain legacyevm.Chain, opts *types.RelayOpts) (*configWatcher, error) {
if !common.IsHexAddress(opts.ContractID) {
return nil, pkgerrors.Errorf("invalid contractID, expected hex address")
return nil, errors.New("invalid contractID, expected hex address")
}

aggregatorAddress := common.HexToAddress(opts.ContractID)
Expand All @@ -36,11 +36,13 @@ func newContractConfigProvider(lggr logger.Logger, chain legacyevm.Chain, opts *
}
cp, err = NewConfigPoller(
lggr,
chain.Client(),
chain.LogPoller(),
aggregatorAddress,
relayConfig.ConfigContractAddress,
ld,
CPConfig{
chain.Client(),
chain.LogPoller(),
aggregatorAddress,
relayConfig.ConfigContractAddress,
ld,
},
)
if err != nil {
return nil, err
Expand Down

0 comments on commit cc70a2f

Please sign in to comment.