Skip to content

Commit

Permalink
[BCI-3991] - Remove CR from relayer struct (#14146)
Browse files Browse the repository at this point in the history
* remove CR from relayer struct

* add changeset

* init contract reader from relay args
  • Loading branch information
Farber98 authored Aug 28, 2024
1 parent c39590e commit d0d2f30
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-dogs-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

remove chainReader from the Relayer struct. #internal
22 changes: 17 additions & 5 deletions core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ type Relayer struct {
lggr logger.SugaredLogger
ks CSAETHKeystore
mercuryPool wsrpc.Pool
chainReader commontypes.ContractReader
codec commontypes.Codec
capabilitiesRegistry coretypes.CapabilitiesRegistry

Expand Down Expand Up @@ -273,10 +272,14 @@ func (r *Relayer) NewOCR3CapabilityProvider(rargs commontypes.RelayArgs, pargs c
func (r *Relayer) NewPluginProvider(rargs commontypes.RelayArgs, pargs commontypes.PluginArgs) (commontypes.PluginProvider, error) {
// TODO https://smartcontract-it.atlassian.net/browse/BCF-2887
ctx := context.Background()

lggr := logger.Sugared(r.lggr).Named("PluginProvider").Named(rargs.ExternalJobID.String())
relayOpts := types.NewRelayOpts(rargs)
relayConfig, err := relayOpts.RelayConfig()
if err != nil {
return nil, fmt.Errorf("failed to get relay config: %w", err)
}

configWatcher, err := newStandardConfigProvider(ctx, r.lggr, r.chain, types.NewRelayOpts(rargs))
configWatcher, err := newStandardConfigProvider(ctx, r.lggr, r.chain, relayOpts)
if err != nil {
return nil, err
}
Expand All @@ -286,8 +289,17 @@ func (r *Relayer) NewPluginProvider(rargs commontypes.RelayArgs, pargs commontyp
return nil, err
}

var chainReaderService ChainReaderService
if relayConfig.ChainReader != nil {
if chainReaderService, err = NewChainReaderService(ctx, lggr, r.chain.LogPoller(), r.chain.HeadTracker(), r.chain.Client(), *relayConfig.ChainReader); err != nil {
return nil, err
}
} else {
lggr.Info("ChainReader missing from RelayConfig")
}

return NewPluginProvider(
r.chainReader,
chainReaderService,
r.codec,
transmitter,
configWatcher,
Expand Down Expand Up @@ -379,7 +391,7 @@ func (r *Relayer) NewMercuryProvider(rargs commontypes.RelayArgs, pargs commonty
}
transmitter := mercury.NewTransmitter(lggr, r.transmitterCfg, clients, privKey.PublicKey, rargs.JobID, *relayConfig.FeedID, r.mercuryORM, transmitterCodec, r.triggerCapability)

return NewMercuryProvider(cp, r.chainReader, r.codec, NewMercuryChainReader(r.chain.HeadTracker()), transmitter, reportCodecV1, reportCodecV2, reportCodecV3, reportCodecV4, lggr), nil
return NewMercuryProvider(cp, r.codec, NewMercuryChainReader(r.chain.HeadTracker()), transmitter, reportCodecV1, reportCodecV2, reportCodecV3, reportCodecV4, lggr), nil
}

func (r *Relayer) NewLLOProvider(rargs commontypes.RelayArgs, pargs commontypes.PluginArgs) (commontypes.LLOProvider, error) {
Expand Down
5 changes: 1 addition & 4 deletions core/services/relay/evm/mercury_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var _ commontypes.MercuryProvider = (*mercuryProvider)(nil)

type mercuryProvider struct {
cp commontypes.ConfigProvider
chainReader commontypes.ContractReader
codec commontypes.Codec
transmitter evmmercury.Transmitter
reportCodecV1 v1.ReportCodec
Expand All @@ -39,7 +38,6 @@ type mercuryProvider struct {

func NewMercuryProvider(
cp commontypes.ConfigProvider,
chainReader commontypes.ContractReader,
codec commontypes.Codec,
mercuryChainReader mercurytypes.ChainReader,
transmitter evmmercury.Transmitter,
Expand All @@ -51,7 +49,6 @@ func NewMercuryProvider(
) *mercuryProvider {
return &mercuryProvider{
cp,
chainReader,
codec,
transmitter,
reportCodecV1,
Expand Down Expand Up @@ -132,7 +129,7 @@ func (p *mercuryProvider) MercuryServerFetcher() mercurytypes.ServerFetcher {
}

func (p *mercuryProvider) ChainReader() commontypes.ContractReader {
return p.chainReader
return nil
}

var _ mercurytypes.ChainReader = (*mercuryChainReader)(nil)
Expand Down
21 changes: 15 additions & 6 deletions core/services/relay/evm/plugin_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

type pluginProvider struct {
services.Service
chainReader types.ContractReader
chainReader ChainReaderService
codec types.Codec
contractTransmitter ocrtypes.ContractTransmitter
contractTransmitter ContractTransmitter
configWatcher *configWatcher
lggr logger.Logger
ms services.MultiStart
Expand All @@ -23,9 +23,9 @@ type pluginProvider struct {
var _ types.PluginProvider = (*pluginProvider)(nil)

func NewPluginProvider(
chainReader types.ContractReader,
chainReader ChainReaderService,
codec types.Codec,
contractTransmitter ocrtypes.ContractTransmitter,
contractTransmitter ContractTransmitter,
configWatcher *configWatcher,
lggr logger.Logger,
) *pluginProvider {
Expand All @@ -46,6 +46,10 @@ func (p *pluginProvider) Ready() error { return nil }
func (p *pluginProvider) HealthReport() map[string]error {
hp := map[string]error{p.Name(): p.Ready()}
services.CopyHealth(hp, p.configWatcher.HealthReport())
services.CopyHealth(hp, p.contractTransmitter.HealthReport())
if p.chainReader != nil {
services.CopyHealth(hp, p.chainReader.HealthReport())
}
return hp
}

Expand All @@ -70,9 +74,14 @@ func (p *pluginProvider) Codec() types.Codec {
}

func (p *pluginProvider) Start(ctx context.Context) error {
return p.configWatcher.Start(ctx)
srvcs := []services.StartClose{p.configWatcher, p.contractTransmitter}
if p.chainReader != nil {
srvcs = append(srvcs, p.chainReader)
}

return p.ms.Start(ctx, srvcs...)
}

func (p *pluginProvider) Close() error {
return p.configWatcher.Close()
return p.ms.Close()
}

0 comments on commit d0d2f30

Please sign in to comment.