-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add special transmitter for OCR2 feeds #13323
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package ocrcommon | |
import ( | ||
"context" | ||
"math/big" | ||
"slices" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/pkg/errors" | ||
|
@@ -63,6 +64,51 @@ func NewTransmitter( | |
}, nil | ||
} | ||
|
||
type txManagerOCR2 interface { | ||
CreateTransaction(ctx context.Context, txRequest txmgr.TxRequest) (tx txmgr.Tx, err error) | ||
GetForwarderForEOAOCR2Feeds(ctx context.Context, eoa, ocr2AggregatorID common.Address) (forwarder common.Address, err error) | ||
} | ||
|
||
type ocr2FeedsTransmitter struct { | ||
ocr2Aggregator common.Address | ||
txManagerOCR2 | ||
transmitter | ||
} | ||
|
||
// NewOCR2FeedsTransmitter creates a new eth transmitter that handles OCR2 Feeds specific logic surrounding forwarders. | ||
// ocr2FeedsTransmitter validates forwarders before every transmission, enabling smooth onchain config changes without job restarts. | ||
func NewOCR2FeedsTransmitter( | ||
txm txManagerOCR2, | ||
fromAddresses []common.Address, | ||
ocr2Aggregator common.Address, | ||
gasLimit uint64, | ||
effectiveTransmitterAddress common.Address, | ||
strategy types.TxStrategy, | ||
checker txmgr.TransmitCheckerSpec, | ||
chainID *big.Int, | ||
keystore roundRobinKeystore, | ||
) (Transmitter, error) { | ||
// Ensure that a keystore is provided. | ||
if keystore == nil { | ||
return nil, errors.New("nil keystore provided to transmitter") | ||
} | ||
|
||
return &ocr2FeedsTransmitter{ | ||
ocr2Aggregator: ocr2Aggregator, | ||
txManagerOCR2: txm, | ||
transmitter: transmitter{ | ||
txm: txm, | ||
fromAddresses: fromAddresses, | ||
gasLimit: gasLimit, | ||
effectiveTransmitterAddress: effectiveTransmitterAddress, | ||
strategy: strategy, | ||
checker: checker, | ||
chainID: chainID, | ||
keystore: keystore, | ||
}, | ||
}, nil | ||
} | ||
|
||
func (t *transmitter) CreateEthTransaction(ctx context.Context, toAddress common.Address, payload []byte, txMeta *txmgr.TxMeta) error { | ||
roundRobinFromAddress, err := t.keystore.GetRoundRobinAddress(ctx, t.chainID, t.fromAddresses...) | ||
if err != nil { | ||
|
@@ -94,3 +140,62 @@ func (t *transmitter) forwarderAddress() common.Address { | |
} | ||
return t.effectiveTransmitterAddress | ||
} | ||
|
||
func (t *ocr2FeedsTransmitter) CreateEthTransaction(ctx context.Context, toAddress common.Address, payload []byte, txMeta *txmgr.TxMeta) error { | ||
roundRobinFromAddress, err := t.keystore.GetRoundRobinAddress(ctx, t.chainID, t.fromAddresses...) | ||
if err != nil { | ||
return errors.Wrap(err, "skipped OCR transmission, error getting round-robin address") | ||
} | ||
|
||
forwarderAddress, err := t.forwarderAddress(ctx, roundRobinFromAddress, toAddress) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = t.txm.CreateTransaction(ctx, txmgr.TxRequest{ | ||
FromAddress: roundRobinFromAddress, | ||
ToAddress: toAddress, | ||
EncodedPayload: payload, | ||
FeeLimit: t.gasLimit, | ||
ForwarderAddress: forwarderAddress, | ||
Strategy: t.strategy, | ||
Checker: t.checker, | ||
Meta: txMeta, | ||
}) | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that context.Background() works here? Might require libocr changes to pass in actual context There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already incoming. I will update this as part of that work. |
||
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) { | ||
return common.Address{}, nil | ||
} | ||
|
||
forwarderAddress, err := t.GetForwarderForEOAOCR2Feeds(ctx, eoa, ocr2Aggregator) | ||
if err != nil { | ||
return common.Address{}, err | ||
} | ||
|
||
// if forwarder address is in fromAddresses, then none of the forwarders are valid | ||
if slices.Contains(t.fromAddresses, forwarderAddress) { | ||
forwarderAddress = common.Address{} | ||
} | ||
|
||
return forwarderAddress, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind explaining this "specific logic" in a comment here? I'm curious what is special about forwarders in OCR2 Feeds that we need a separate transmitter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, was about to add a description. This change should allow the ocr2 feeds job to always validate its sender before transmitting. This means checking if forwarders are authorized for EOA and if they are set as a transmitter on the OCR2 aggregator contract. Previously forwarders were chosen once during job start.