From 298ee8171e24001d2f284b0c9bd11ad7ada82b52 Mon Sep 17 00:00:00 2001 From: george-dorin Date: Thu, 28 Nov 2024 13:21:41 +0200 Subject: [PATCH] Add ContractTransmitter helper function --- core/services/ocrcommon/dual_transmittrer.go | 4 --- .../relay/evm/dual_contract_transmitter.go | 12 +++++++ core/services/relay/evm/evm.go | 31 +++++++++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/core/services/ocrcommon/dual_transmittrer.go b/core/services/ocrcommon/dual_transmittrer.go index 8c23d5b6636..efc60978f19 100644 --- a/core/services/ocrcommon/dual_transmittrer.go +++ b/core/services/ocrcommon/dual_transmittrer.go @@ -32,10 +32,6 @@ type ocr2FeedsDualTransmission struct { secondaryMeta map[string][]string } -func (t *ocr2FeedsDualTransmission) SendSecondaryTransaction() bool { - return true -} - func (t *ocr2FeedsDualTransmission) forwarderAddress(ctx context.Context, eoa, ocr2Aggregator common.Address) (common.Address, error) { // If effectiveTransmitterAddress is in fromAddresses, then forwarders aren't set. if slices.Contains(t.primaryFromAddresses, t.primaryEffectiveTransmitterAddress) { diff --git a/core/services/relay/evm/dual_contract_transmitter.go b/core/services/relay/evm/dual_contract_transmitter.go index 645a8b6c3e1..656270939fe 100644 --- a/core/services/relay/evm/dual_contract_transmitter.go +++ b/core/services/relay/evm/dual_contract_transmitter.go @@ -25,6 +25,8 @@ import ( // TODO: Remove when new dual transmitter contracts are merged var dtABI = `[{"inputs":[{"internalType":"bytes32[3]","name":"reportContext","type":"bytes32[3]"},{"internalType":"bytes","name":"report","type":"bytes"},{"internalType":"bytes32[]","name":"rs","type":"bytes32[]"},{"internalType":"bytes32[]","name":"ss","type":"bytes32[]"},{"internalType":"bytes32","name":"rawVs","type":"bytes32"}],"name":"transmitSecondary","outputs":[],"stateMutability":"nonpayable","type":"function"}]` +var _ ContractTransmitter = (*dualContractTransmitter)(nil) + type dualContractTransmitter struct { contractAddress gethcommon.Address contractABI abi.ABI @@ -168,3 +170,13 @@ func (oc *dualContractTransmitter) LatestConfigDigestAndEpoch(ctx context.Contex func (oc *dualContractTransmitter) FromAccount(ctx context.Context) (ocrtypes.Account, error) { return ocrtypes.Account(oc.transmitter.FromAddress(ctx).String()), nil } + +func (oc *dualContractTransmitter) Start(ctx context.Context) error { return nil } +func (oc *dualContractTransmitter) Close() error { return nil } + +// Has no state/lifecycle so it's always healthy and ready +func (oc *dualContractTransmitter) Ready() error { return nil } +func (oc *dualContractTransmitter) HealthReport() map[string]error { + return map[string]error{oc.Name(): nil} +} +func (oc *dualContractTransmitter) Name() string { return oc.lggr.Name() } diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 8008fc4fd9e..6f4975a0b34 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -750,6 +750,33 @@ func newOnChainContractTransmitter(ctx context.Context, lggr logger.Logger, rarg ) } +// newOnChainDualContractTransmitter creates a new dual contract transmitter. +func newOnChainDualContractTransmitter(ctx context.Context, lggr logger.Logger, rargs commontypes.RelayArgs, ethKeystore keystore.Eth, configWatcher *configWatcher, opts configTransmitterOpts, transmissionContractABI abi.ABI, ocrTransmitterOpts ...OCRTransmitterOption) (*dualContractTransmitter, error) { + transmitter, err := generateTransmitterFrom(ctx, rargs, ethKeystore, configWatcher, opts) + if err != nil { + return nil, err + } + + return NewOCRDualContractTransmitter( + ctx, + configWatcher.contractAddress, + configWatcher.chain.Client(), + transmissionContractABI, + transmitter, + configWatcher.chain.LogPoller(), + lggr, + ocrTransmitterOpts..., + ) +} + +func NewContractTransmitter(ctx context.Context, lggr logger.Logger, rargs commontypes.RelayArgs, ethKeystore keystore.Eth, configWatcher *configWatcher, opts configTransmitterOpts, transmissionContractABI abi.ABI, dualTransmission bool, ocrTransmitterOpts ...OCRTransmitterOption) (ContractTransmitter, error) { + if dualTransmission { + return newOnChainDualContractTransmitter(ctx, lggr, rargs, ethKeystore, configWatcher, opts, transmissionContractABI, ocrTransmitterOpts...) + } + + return newOnChainContractTransmitter(ctx, lggr, rargs, ethKeystore, configWatcher, opts, transmissionContractABI, ocrTransmitterOpts...) +} + func generateTransmitterFrom(ctx context.Context, rargs commontypes.RelayArgs, ethKeystore keystore.Eth, configWatcher *configWatcher, opts configTransmitterOpts) (Transmitter, error) { var relayConfig types.RelayConfig if err := json.Unmarshal(rargs.RelayConfig, &relayConfig); err != nil { @@ -887,7 +914,7 @@ func (r *Relayer) NewMedianProvider(ctx context.Context, rargs commontypes.Relay reportCodec := evmreportcodec.ReportCodec{} - contractTransmitter, err := newOnChainContractTransmitter(ctx, lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI) + ct, err := NewContractTransmitter(ctx, lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI, relayConfig.EnableDualTransmission) if err != nil { return nil, err } @@ -901,7 +928,7 @@ func (r *Relayer) NewMedianProvider(ctx context.Context, rargs commontypes.Relay lggr: lggr.Named("MedianProvider"), configWatcher: configWatcher, reportCodec: reportCodec, - contractTransmitter: contractTransmitter, + contractTransmitter: ct, medianContract: medianContract, }