From aa68ab208ad6b8fda7099e67071a9aae96a9ddf6 Mon Sep 17 00:00:00 2001 From: ilija Date: Fri, 24 May 2024 23:14:35 +0200 Subject: [PATCH] Add ocr2FeedsTransmitter FromAddress() --- core/services/ocrcommon/transmitter.go | 20 +++++++++++++++++++- core/services/relay/evm/evm.go | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/services/ocrcommon/transmitter.go b/core/services/ocrcommon/transmitter.go index 581d4187c63..bfb007d1b3e 100644 --- a/core/services/ocrcommon/transmitter.go +++ b/core/services/ocrcommon/transmitter.go @@ -70,6 +70,7 @@ type txManagerOCR2 interface { } type ocr2FeedsTransmitter struct { + ocr2Aggregator common.Address txManagerOCR2 transmitter } @@ -79,6 +80,7 @@ type ocr2FeedsTransmitter struct { func NewOCR2FeedsTransmitter( txm txManagerOCR2, fromAddresses []common.Address, + ocr2Aggregator common.Address, gasLimit uint64, effectiveTransmitterAddress common.Address, strategy types.TxStrategy, @@ -92,7 +94,8 @@ func NewOCR2FeedsTransmitter( } return &ocr2FeedsTransmitter{ - txManagerOCR2: txm, + ocr2Aggregator: ocr2Aggregator, + txManagerOCR2: txm, transmitter: transmitter{ txm: txm, fromAddresses: fromAddresses, @@ -163,6 +166,21 @@ func (t *ocr2FeedsTransmitter) CreateEthTransaction(ctx context.Context, toAddre return errors.Wrap(err, "skipped OCR transmission") } +// FromAddress for ocr2FeedsTransmitter returns valid forwarder or effectiveTransmitterAddress if forwarders are not set. +func (t *ocr2FeedsTransmitter) FromAddress() common.Address { + roundRobinFromAddress, err := t.keystore.GetRoundRobinAddress(context.Background(), t.chainID, t.fromAddresses...) + if err != nil { + return t.effectiveTransmitterAddress + } + + forwarderAddress, err := t.forwarderAddress(context.Background(), roundRobinFromAddress, t.ocr2Aggregator) + if err != nil || forwarderAddress == (common.Address{}) { + return t.effectiveTransmitterAddress + } + + return forwarderAddress +} + func (t *ocr2FeedsTransmitter) 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.fromAddresses, t.effectiveTransmitterAddress) { diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index e73b6211099..2fb76e360da 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -574,6 +574,7 @@ func newOnChainContractTransmitter(ctx context.Context, lggr logger.Logger, rarg transmitter, err = ocrcommon.NewOCR2FeedsTransmitter( configWatcher.chain.TxManager(), fromAddresses, + common.HexToAddress(rargs.ContractID), gasLimit, effectiveTransmitterAddress, strategy,