Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BCF-2365] Consolidate *Provider Constructors into One #10475

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/chains/cosmos/relayer_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ type LoopRelayerChain struct {
}

func NewLoopRelayerChain(r *pkgcosmos.Relayer, s adapters.Chain) *LoopRelayerChain {

ra := relay.NewRelayerAdapter(r, s)
ra := relay.NewRelayerServerAdapter(r, s)
return &LoopRelayerChain{
Relayer: ra,
chain: s,
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230831132059-42af68994512 // indirect
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230905185157-da01915913a4 // indirect
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230908130052-16ce8fa4a45b // indirect
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918 // indirect
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230829114801-14bf715f805e // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230831132059-42af68994512 h1:DojChlaudA1HAxwQPKmt/EDf36OUeFJ0LJBYClauMyU=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230831132059-42af68994512/go.mod h1:xMwqRdj5vqYhCJXgKVqvyAwdcqM6ZAEhnwEQ4Khsop8=
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230905185157-da01915913a4 h1:yArUq/0t126bl8BRtjLCf2NuHK35CDIkhc3M5P46apc=
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230905185157-da01915913a4/go.mod h1:gWclxGW7rLkbjXn7FGizYlyKhp/boekto4MEYGyiMG4=
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230908130052-16ce8fa4a45b h1:RrG9RuPfQi1Ak7/FdIEDlDpta2PSm5Dghmxpq2ZIO8M=
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230908130052-16ce8fa4a45b/go.mod h1:gWclxGW7rLkbjXn7FGizYlyKhp/boekto4MEYGyiMG4=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca h1:x7M0m512gtXw5Z4B1WJPZ52VgshoIv+IvHqQ8hsH4AE=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca/go.mod h1:RIUJXn7EVp24TL2p4FW79dYjyno23x5mjt1nKN+5WEk=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918 h1:ByVauKFXphRlSNG47lNuxZ9aicu+r8AoNp933VRPpCw=
Expand Down
6 changes: 3 additions & 3 deletions core/services/chainlink/relayer_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *RelayerFactory) NewEVM(ctx context.Context, config EVMFactoryConfig) (m
if err != nil {
return nil, err
}
relayer := evmrelay.NewLoopRelayAdapter(evmrelay.NewRelayer(ccOpts.DB, chain, r.QConfig, ccOpts.Logger, config.CSAETHKeystore, ccOpts.EventBroadcaster), ext)
relayer := evmrelay.NewLoopRelayServerAdapter(evmrelay.NewRelayer(ccOpts.DB, chain, r.QConfig, ccOpts.Logger, config.CSAETHKeystore, ccOpts.EventBroadcaster), ext)
relayers[relayID] = relayer
}

Expand Down Expand Up @@ -135,7 +135,7 @@ func (r *RelayerFactory) NewSolana(ks keystore.Solana, chainCfgs solana.SolanaCo
if err != nil {
return nil, err
}
solanaRelayers[relayId] = relay.NewRelayerAdapter(pkgsolana.NewRelayer(solLggr, chain), chain)
solanaRelayers[relayId] = relay.NewRelayerServerAdapter(pkgsolana.NewRelayer(solLggr, chain), chain)
}
}
return solanaRelayers, nil
Expand Down Expand Up @@ -208,7 +208,7 @@ func (r *RelayerFactory) NewStarkNet(ks keystore.StarkNet, chainCfgs starknet.St
return nil, err
}

starknetRelayers[relayId] = relay.NewRelayerAdapter(pkgstarknet.NewRelayer(starkLggr, chain), chain)
starknetRelayers[relayId] = relay.NewRelayerServerAdapter(pkgstarknet.NewRelayer(starkLggr, chain), chain)
}
}
return starknetRelayers, nil
Expand Down
3 changes: 2 additions & 1 deletion core/services/job/job_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-relay/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"

"github.com/smartcontractkit/chainlink/v2/core/assets"
Expand Down Expand Up @@ -911,7 +912,7 @@ func TestORM_ValidateKeyStoreMatch(t *testing.T) {
})

t.Run("test Mercury ETH key validation", func(t *testing.T) {
jb.OCR2OracleSpec.PluginType = job.Mercury
jb.OCR2OracleSpec.PluginType = types.Mercury
err = job.ValidateKeyStoreMatch(jb.OCR2OracleSpec, keyStore, "bad key")
require.EqualError(t, err, "no CSA key matching: \"bad key\"")

Expand Down
54 changes: 17 additions & 37 deletions core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pkg/errors"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-relay/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/bridges"
clnull "github.com/smartcontractkit/chainlink/v2/core/null"
Expand Down Expand Up @@ -310,28 +311,7 @@ func (r JSONConfig) MercuryCredentialName() (string, error) {
return name, nil
}

var ForwardersSupportedPlugins = []OCR2PluginType{Median, DKG, OCR2VRF, OCR2Keeper, OCR2Functions}

// OCR2PluginType defines supported OCR2 plugin types.
type OCR2PluginType string

const (
// Median refers to the median.Median type
Median OCR2PluginType = "median"

DKG OCR2PluginType = "dkg"

OCR2VRF OCR2PluginType = "ocr2vrf"

// Keeper was rebranded to automation. For now the plugin type required in job spec points
// to the new name (automation) but in code we refer it to keepers
// TODO: sc-55296 to rename ocr2keeper to ocr2automation in code
OCR2Keeper OCR2PluginType = "ocr2automation"

OCR2Functions OCR2PluginType = "functions"

Mercury OCR2PluginType = "mercury"
)
var ForwardersSupportedPlugins = []types.OCR2PluginType{types.Median, types.DKG, types.OCR2VRF, types.OCR2Keeper, types.Functions}

// OCR2OracleSpec defines the job spec for OCR2 jobs.
// Relay config is chain specific config for a relay (chain adapter).
Expand All @@ -341,21 +321,21 @@ type OCR2OracleSpec struct {
FeedID *common.Hash `toml:"feedID"`
Relay relay.Network `toml:"relay"`
// TODO BCF-2442 implement ChainID as top level parameter rathe than buried in RelayConfig.
ChainID string `toml:"chainID"`
RelayConfig JSONConfig `toml:"relayConfig"`
P2PV2Bootstrappers pq.StringArray `toml:"p2pv2Bootstrappers"`
OCRKeyBundleID null.String `toml:"ocrKeyBundleID"`
MonitoringEndpoint null.String `toml:"monitoringEndpoint"`
TransmitterID null.String `toml:"transmitterID"`
BlockchainTimeout models.Interval `toml:"blockchainTimeout"`
ContractConfigTrackerPollInterval models.Interval `toml:"contractConfigTrackerPollInterval"`
ContractConfigConfirmations uint16 `toml:"contractConfigConfirmations"`
PluginConfig JSONConfig `toml:"pluginConfig"`
PluginType OCR2PluginType `toml:"pluginType"`
CreatedAt time.Time `toml:"-"`
UpdatedAt time.Time `toml:"-"`
CaptureEATelemetry bool `toml:"captureEATelemetry"`
CaptureAutomationCustomTelemetry bool `toml:"captureAutomationCustomTelemetry"`
ChainID string `toml:"chainID"`
RelayConfig JSONConfig `toml:"relayConfig"`
P2PV2Bootstrappers pq.StringArray `toml:"p2pv2Bootstrappers"`
OCRKeyBundleID null.String `toml:"ocrKeyBundleID"`
MonitoringEndpoint null.String `toml:"monitoringEndpoint"`
TransmitterID null.String `toml:"transmitterID"`
BlockchainTimeout models.Interval `toml:"blockchainTimeout"`
ContractConfigTrackerPollInterval models.Interval `toml:"contractConfigTrackerPollInterval"`
ContractConfigConfirmations uint16 `toml:"contractConfigConfirmations"`
PluginConfig JSONConfig `toml:"pluginConfig"`
PluginType types.OCR2PluginType `toml:"pluginType"`
CreatedAt time.Time `toml:"-"`
UpdatedAt time.Time `toml:"-"`
CaptureEATelemetry bool `toml:"captureEATelemetry"`
CaptureAutomationCustomTelemetry bool `toml:"captureAutomationCustomTelemetry"`
}

func (s *OCR2OracleSpec) RelayID() (relay.ID, error) {
Expand Down
8 changes: 5 additions & 3 deletions core/services/job/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

"github.com/smartcontractkit/sqlx"

"github.com/smartcontractkit/chainlink-relay/pkg/types"

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
Expand Down Expand Up @@ -268,7 +270,7 @@ func (o *orm) CreateJob(jb *Job, qopts ...pg.QOpt) error {
return errors.Errorf("forwarding is not currently supported for %s jobs", jb.OCR2OracleSpec.PluginType)
}

if jb.OCR2OracleSpec.PluginType == Mercury {
if jb.OCR2OracleSpec.PluginType == types.Mercury {
if jb.OCR2OracleSpec.FeedID == nil {
return errors.New("feed ID is required for mercury plugin type")
}
Expand All @@ -278,7 +280,7 @@ func (o *orm) CreateJob(jb *Job, qopts ...pg.QOpt) error {
}
}

if jb.OCR2OracleSpec.PluginType == Median {
if jb.OCR2OracleSpec.PluginType == types.Median {
var cfg medianconfig.PluginConfig
err = json.Unmarshal(jb.OCR2OracleSpec.PluginConfig.Bytes(), &cfg)
if err != nil {
Expand Down Expand Up @@ -456,7 +458,7 @@ func (o *orm) CreateJob(jb *Job, qopts ...pg.QOpt) error {

// ValidateKeyStoreMatch confirms that the key has a valid match in the keystore
func ValidateKeyStoreMatch(spec *OCR2OracleSpec, keyStore keystore.Master, key string) error {
if spec.PluginType == Mercury {
if spec.PluginType == types.Mercury {
_, err := keyStore.CSA().Get(key)
if err != nil {
return errors.Errorf("no CSA key matching: %q", key)
Expand Down
2 changes: 1 addition & 1 deletion core/services/job/spawner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type relayGetter struct {
}

func (g *relayGetter) Get(id relay.ID) (loop.Relayer, error) {
return evmrelayer.NewLoopRelayAdapter(g.r, g.e), nil
return evmrelayer.NewLoopRelayServerAdapter(g.r, g.e), nil
}

func TestSpawner_CreateJobDeleteJob(t *testing.T) {
Expand Down
28 changes: 17 additions & 11 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ func (d *Delegate) cleanupEVM(jb job.Job, q pg.Queryer, relayID relay.ID) error

var filters []string
switch spec.PluginType {
case job.OCR2VRF:
case types.OCR2VRF:
filters, err = ocr2coordinator.FilterNamesFromSpec(spec)
if err != nil {
d.lggr.Errorw("failed to derive ocr2vrf filter names from spec", "err", err, "spec", spec)
}
case job.OCR2Keeper:
case types.OCR2Keeper:
filters, err = ocr2keeper.FilterNamesFromSpec20(spec)
if err != nil {
d.lggr.Errorw("failed to derive ocr2keeper filter names from spec", "err", err, "spec", spec)
Expand Down Expand Up @@ -405,22 +405,22 @@ func (d *Delegate) ServicesForSpec(jb job.Job, qopts ...pg.QOpt) ([]job.ServiceC

ctx := lggrCtx.ContextWithValues(context.Background())
switch spec.PluginType {
case job.Mercury:
case types.Mercury:
return d.newServicesMercury(ctx, lggr, jb, runResults, bootstrapPeers, kb, ocrDB, lc, ocrLogger)

case job.Median:
case types.Median:
return d.newServicesMedian(ctx, lggr, jb, runResults, bootstrapPeers, kb, ocrDB, lc, ocrLogger)

case job.DKG:
case types.DKG:
return d.newServicesDKG(lggr, jb, bootstrapPeers, kb, ocrDB, lc, ocrLogger)

case job.OCR2VRF:
case types.OCR2VRF:
return d.newServicesOCR2VRF(lggr, jb, runResults, bootstrapPeers, kb, ocrDB, lc)

case job.OCR2Keeper:
case types.OCR2Keeper:
return d.newServicesOCR2Keepers(lggr, jb, runResults, bootstrapPeers, kb, ocrDB, lc, ocrLogger)

case job.OCR2Functions:
case types.Functions:
const (
_ int32 = iota
thresholdPluginId
Expand All @@ -437,7 +437,7 @@ func (d *Delegate) ServicesForSpec(jb job.Job, qopts ...pg.QOpt) ([]job.ServiceC

func GetEVMEffectiveTransmitterID(jb *job.Job, chain evm.Chain, lggr logger.SugaredLogger) (string, error) {
spec := jb.OCR2OracleSpec
if spec.PluginType == job.Mercury {
if spec.PluginType == types.Mercury {
return spec.TransmitterID.String, nil
}

Expand All @@ -448,7 +448,7 @@ func GetEVMEffectiveTransmitterID(jb *job.Job, chain evm.Chain, lggr logger.Suga
if err != nil {
return "", err
}
if len(sendingKeys) > 1 && spec.PluginType != job.OCR2VRF {
if len(sendingKeys) > 1 && spec.PluginType != types.OCR2VRF {
return "", errors.New("only ocr2 vrf should have more than 1 sending key")
}
spec.TransmitterID = null.StringFrom(sendingKeys[0])
Expand Down Expand Up @@ -514,13 +514,14 @@ func (d *Delegate) newServicesMercury(
return nil, fmt.Errorf("mercury services: failed to get chain %s: %w", rid.ChainID, err)
}

mercuryProvider, err2 := relayer.NewMercuryProvider(ctx,
provider, err2 := relayer.NewPluginProvider(ctx,
types.RelayArgs{
ExternalJobID: jb.ExternalJobID,
JobID: spec.ID,
ContractID: spec.ContractID,
New: d.isNewlyCreatedJob,
RelayConfig: spec.RelayConfig.Bytes(),
ProviderType: string(spec.PluginType),
}, types.PluginArgs{
TransmitterID: transmitterID,
PluginConfig: spec.PluginConfig.Bytes(),
Expand All @@ -529,6 +530,11 @@ func (d *Delegate) newServicesMercury(
return nil, err2
}

mercuryProvider, ok := provider.(types.MercuryProvider)
if !ok {
return nil, errors.New("could not coerce PluginProvider to MercuryProvider")
}

oracleArgsNoPlugin := libocr2.MercuryOracleArgs{
BinaryNetworkEndpointFactory: d.peerWrapper.Peer2,
V2Bootstrappers: bootstrapPeers,
Expand Down
11 changes: 6 additions & 5 deletions core/services/ocr2/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-relay/pkg/types"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
txmmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr/mocks"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestGetEVMEffectiveTransmitterID(t *testing.T) {

type testCase struct {
name string
pluginType job.OCR2PluginType
pluginType types.OCR2PluginType
transmitterID null.String
sendingKeys []any
expectedError bool
Expand All @@ -75,7 +76,7 @@ func TestGetEVMEffectiveTransmitterID(t *testing.T) {
testCases := []testCase{
{
name: "mercury plugin should just return transmitterID",
pluginType: job.Mercury,
pluginType: types.Mercury,
transmitterID: null.StringFrom("Mercury transmitterID"),
expectedTransmitterID: "Mercury transmitterID",
},
Expand All @@ -91,7 +92,7 @@ func TestGetEVMEffectiveTransmitterID(t *testing.T) {
},
{
name: "when transmitterID is not defined and plugin is ocr2vrf, it should allow>1 sendingKeys and set transmitterID to the first one",
pluginType: job.OCR2VRF,
pluginType: types.OCR2VRF,
sendingKeys: []any{"0x7e57000000000000000000000000000000000000", "0x7e57000000000000000000000000000000000001", "0x7e57000000000000000000000000000000000002"},
expectedTransmitterID: "0x7e57000000000000000000000000000000000000",
},
Expand All @@ -109,15 +110,15 @@ func TestGetEVMEffectiveTransmitterID(t *testing.T) {
},
{
name: "when forwarders are enabled and when transmitterID is not defined, it should use first sendingKey to retrieve forwarder address",
pluginType: job.OCR2VRF,
pluginType: types.OCR2VRF,
forwardingEnabled: true,
sendingKeys: []any{"0x7e57000000000000000000000000000000000001", "0x7e57000000000000000000000000000000000002"},
getForwarderForEOAArg: common.HexToAddress("0x7e57000000000000000000000000000000000001"),
expectedTransmitterID: "0x7e58000000000000000000000000000000000000",
},
{
name: "when forwarders are enabled but forwarder address fails to be retrieved and when transmitterID is not defined, it should default to using first sendingKey",
pluginType: job.OCR2VRF,
pluginType: types.OCR2VRF,
forwardingEnabled: true,
sendingKeys: []any{"0x7e57000000000000000000000000000000000001", "0x7e57000000000000000000000000000000000002"},
getForwarderForEOAArg: common.HexToAddress("0x7e57000000000000000000000000000000000001"),
Expand Down
14 changes: 11 additions & 3 deletions core/services/ocr2/plugins/median/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package median
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -67,19 +68,26 @@ func NewMedianServices(ctx context.Context,
}
spec := jb.OCR2OracleSpec

provider, err := relayer.NewMedianProvider(ctx, types.RelayArgs{
provider, err := relayer.NewPluginProvider(ctx, types.RelayArgs{
ExternalJobID: jb.ExternalJobID,
JobID: spec.ID,
ContractID: spec.ContractID,
New: isNewlyCreatedJob,
RelayConfig: spec.RelayConfig.Bytes(),
ProviderType: string(spec.PluginType),
}, types.PluginArgs{
TransmitterID: spec.TransmitterID.String,
PluginConfig: spec.PluginConfig.Bytes(),
})
if err != nil {
return
}

medianProvider, ok := provider.(types.MedianProvider)
if !ok {
return nil, errors.New("could not coerce PluginProvider to MedianProvider")
krehermann marked this conversation as resolved.
Show resolved Hide resolved
}

srvs = append(srvs, provider)
argsNoPlugin.ContractTransmitter = provider.ContractTransmitter()
argsNoPlugin.ContractConfigTracker = provider.ContractConfigTracker()
Expand Down Expand Up @@ -113,11 +121,11 @@ func NewMedianServices(ctx context.Context,
abort()
return
}
median := loop.NewMedianService(lggr, telem, cmdFn, provider, dataSource, juelsPerFeeCoinSource, errorLog)
median := loop.NewMedianService(lggr, telem, cmdFn, medianProvider, dataSource, juelsPerFeeCoinSource, errorLog)
argsNoPlugin.ReportingPluginFactory = median
srvs = append(srvs, median)
} else {
argsNoPlugin.ReportingPluginFactory, err = NewPlugin(lggr).NewMedianFactory(ctx, provider, dataSource, juelsPerFeeCoinSource, errorLog)
argsNoPlugin.ReportingPluginFactory, err = NewPlugin(lggr).NewMedianFactory(ctx, medianProvider, dataSource, juelsPerFeeCoinSource, errorLog)
if err != nil {
err = fmt.Errorf("failed to create median factory: %w", err)
abort()
Expand Down
Loading
Loading