Skip to content

Commit

Permalink
Keep 2.0 as is to reduce testing impact
Browse files Browse the repository at this point in the history
  • Loading branch information
ferglor committed Dec 15, 2023
1 parent 1aa9fb5 commit ccd1495
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
33 changes: 3 additions & 30 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,36 +1231,9 @@ func (d *Delegate) newServicesOCR2Keepers20(
return nil, fmt.Errorf("keepers2.0 services: failed to get chain (%s): %w", rid.ChainID, err2)
}

transmitterID := spec.TransmitterID.String
relayer, err := d.RelayGetter.Get(rid)
if err != nil {
return nil, ErrRelayNotEnabled{Err: err, Relay: spec.Relay, PluginName: "mercury"}
}

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

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

rgstry, encoder, logProvider, err := ocr2keeper.EVMDependencies20(jb, lggr, chain)
if err != nil {
return nil, errors.Wrap(err, "could not build dependencies for ocr2 keepers")
keeperProvider, rgstry, encoder, logProvider, err2 := ocr2keeper.EVMDependencies20(jb, d.db, lggr, chain, d.ethKs)
if err2 != nil {
return nil, errors.Wrap(err2, "could not build dependencies for ocr2 keepers")
}

w := &logWriter{log: lggr.Named("Automation Dependencies")}
Expand Down
40 changes: 37 additions & 3 deletions core/services/ocr2/plugins/ocr2keeper/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package ocr2keeper

import (
"fmt"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"

"github.com/jmoiron/sqlx"

Expand Down Expand Up @@ -40,18 +43,49 @@ var (
ErrNoChainFromSpec = fmt.Errorf("could not create chain from spec")
)

func EVMProvider(db *sqlx.DB, chain legacyevm.Chain, lggr logger.Logger, spec job.Job, ethKeystore keystore.Eth) (evmrelay.OCR2KeeperProvider, error) {
oSpec := spec.OCR2OracleSpec
ocr2keeperRelayer := evmrelay.NewOCR2KeeperRelayer(db, chain, lggr.Named("OCR2KeeperRelayer"), ethKeystore)

keeperProvider, err := ocr2keeperRelayer.NewOCR2KeeperProvider(
types.RelayArgs{
ExternalJobID: spec.ExternalJobID,
JobID: oSpec.ID,
ContractID: oSpec.ContractID,
RelayConfig: oSpec.RelayConfig.Bytes(),
},
types.PluginArgs{
TransmitterID: oSpec.TransmitterID.String,
PluginConfig: oSpec.PluginConfig.Bytes(),
},
)
if err != nil {
return nil, fmt.Errorf("%w: failed to create new ocr2keeper provider", err)
}

return keeperProvider, nil
}

func EVMDependencies20(
spec job.Job,
db *sqlx.DB,
lggr logger.Logger,
chain legacyevm.Chain,
) (*evmregistry20.EvmRegistry, Encoder20, *evmregistry20.LogProvider, error) {
ethKeystore keystore.Eth,
) (evmrelay.OCR2KeeperProvider, *evmregistry20.EvmRegistry, Encoder20, *evmregistry20.LogProvider, error) {
var err error

var keeperProvider evmrelay.OCR2KeeperProvider
var registry *evmregistry20.EvmRegistry

// the provider will be returned as a dependency
if keeperProvider, err = EVMProvider(db, chain, lggr, spec, ethKeystore); err != nil {
return nil, nil, nil, nil, err
}

rAddr := ethkey.MustEIP55Address(spec.OCR2OracleSpec.ContractID).Address()
if registry, err = evmregistry20.NewEVMRegistryService(rAddr, chain, lggr); err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}

encoder := evmregistry20.EVMAutomationEncoder20{}
Expand All @@ -62,7 +96,7 @@ func EVMDependencies20(
// TODO: accept a version of the registry contract and use the correct interfaces
logProvider, err := evmregistry20.NewLogProvider(lggr, chain.LogPoller(), rAddr, chain.Client(), lookbackBlocks)

return registry, encoder, logProvider, err
return keeperProvider, registry, encoder, logProvider, err
}

func FilterNamesFromSpec20(spec *job.OCR2OracleSpec) (names []string, err error) {
Expand Down

0 comments on commit ccd1495

Please sign in to comment.