-
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
(feat): Combine common Transmitter into FunctionsContractTransmitter #12473
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a26544
(feat): Copy common Transmitter into FunctionsContractTransmitter to …
justinkaseman 8eb3ea7
Remove unused Functions transmitter reportToEvmTxMeta
justinkaseman 12eaf54
Remove unused txMeta from functions transmitter
justinkaseman eaa00c7
Merge branch 'develop' into FUN-944
justinkaseman f782b30
(test): functions contract transmitter test uses nil txMetadata
justinkaseman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": minor | ||
--- | ||
|
||
Copy common transmitter methods into FunctionsContractTransmitter to enable product specific modification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
"github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil" | ||
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/common/txmgr/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" | ||
|
@@ -25,33 +26,43 @@ import ( | |
evmRelayTypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" | ||
) | ||
|
||
type roundRobinKeystore interface { | ||
GetRoundRobinAddress(ctx context.Context, chainID *big.Int, addresses ...common.Address) (address common.Address, err error) | ||
} | ||
|
||
type txManager interface { | ||
CreateTransaction(ctx context.Context, txRequest txmgr.TxRequest) (tx txmgr.Tx, err error) | ||
} | ||
|
||
type FunctionsContractTransmitter interface { | ||
services.ServiceCtx | ||
ocrtypes.ContractTransmitter | ||
} | ||
|
||
type Transmitter interface { | ||
CreateEthTransaction(ctx context.Context, toAddress common.Address, payload []byte, txMeta *txmgr.TxMeta) error | ||
FromAddress() common.Address | ||
} | ||
|
||
type ReportToEthMetadata func([]byte) (*txmgr.TxMeta, error) | ||
|
||
func reportToEvmTxMetaNoop([]byte) (*txmgr.TxMeta, error) { | ||
return nil, nil | ||
} | ||
|
||
type contractTransmitter struct { | ||
contractAddress atomic.Pointer[common.Address] | ||
contractABI abi.ABI | ||
transmitter Transmitter | ||
transmittedEventSig common.Hash | ||
contractReader contractReader | ||
lp logpoller.LogPoller | ||
lggr logger.Logger | ||
reportToEvmTxMeta ReportToEthMetadata | ||
contractVersion uint32 | ||
reportCodec encoding.ReportCodec | ||
contractAddress atomic.Pointer[common.Address] | ||
contractABI abi.ABI | ||
transmittedEventSig common.Hash | ||
contractReader contractReader | ||
lp logpoller.LogPoller | ||
lggr logger.Logger | ||
reportToEvmTxMeta ReportToEthMetadata | ||
contractVersion uint32 | ||
reportCodec encoding.ReportCodec | ||
txm txManager | ||
fromAddresses []common.Address | ||
gasLimit uint64 | ||
effectiveTransmitterAddress common.Address | ||
strategy types.TxStrategy | ||
checker txmgr.TransmitCheckerSpec | ||
chainID *big.Int | ||
keystore roundRobinKeystore | ||
} | ||
|
||
var _ FunctionsContractTransmitter = &contractTransmitter{} | ||
|
@@ -64,12 +75,24 @@ func transmitterFilterName(addr common.Address) string { | |
func NewFunctionsContractTransmitter( | ||
caller contractReader, | ||
contractABI abi.ABI, | ||
transmitter Transmitter, | ||
lp logpoller.LogPoller, | ||
lggr logger.Logger, | ||
reportToEvmTxMeta ReportToEthMetadata, | ||
contractVersion uint32, | ||
txm txManager, | ||
fromAddresses []common.Address, | ||
gasLimit uint64, | ||
effectiveTransmitterAddress common.Address, | ||
strategy types.TxStrategy, | ||
checker txmgr.TransmitCheckerSpec, | ||
chainID *big.Int, | ||
keystore roundRobinKeystore, | ||
) (*contractTransmitter, error) { | ||
// Ensure that a keystore is provided. | ||
if keystore == nil { | ||
return nil, errors.New("nil keystore provided to transmitter") | ||
} | ||
|
||
transmitted, ok := contractABI.Events["Transmitted"] | ||
if !ok { | ||
return nil, errors.New("invalid ABI, missing transmitted") | ||
|
@@ -87,18 +110,54 @@ func NewFunctionsContractTransmitter( | |
return nil, err | ||
} | ||
return &contractTransmitter{ | ||
contractABI: contractABI, | ||
transmitter: transmitter, | ||
transmittedEventSig: transmitted.ID, | ||
lp: lp, | ||
contractReader: caller, | ||
lggr: lggr.Named("OCRContractTransmitter"), | ||
reportToEvmTxMeta: reportToEvmTxMeta, | ||
contractVersion: contractVersion, | ||
reportCodec: codec, | ||
contractABI: contractABI, | ||
transmittedEventSig: transmitted.ID, | ||
lp: lp, | ||
contractReader: caller, | ||
lggr: lggr.Named("OCRContractTransmitter"), | ||
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. would it help when debugging if the lggr was named: |
||
reportToEvmTxMeta: reportToEvmTxMeta, | ||
contractVersion: contractVersion, | ||
reportCodec: codec, | ||
txm: txm, | ||
fromAddresses: fromAddresses, | ||
gasLimit: gasLimit, | ||
effectiveTransmitterAddress: effectiveTransmitterAddress, | ||
strategy: strategy, | ||
checker: checker, | ||
chainID: chainID, | ||
keystore: keystore, | ||
}, nil | ||
} | ||
|
||
func (oc *contractTransmitter) createEthTransaction(ctx context.Context, toAddress common.Address, payload []byte, txMeta *txmgr.TxMeta) error { | ||
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 think txMeta is always nil so we could remove it from params. |
||
|
||
roundRobinFromAddress, err := oc.keystore.GetRoundRobinAddress(ctx, oc.chainID, oc.fromAddresses...) | ||
if err != nil { | ||
return errors.Wrap(err, "skipped OCR transmission, error getting round-robin address") | ||
} | ||
|
||
_, err = oc.txm.CreateTransaction(ctx, txmgr.TxRequest{ | ||
FromAddress: roundRobinFromAddress, | ||
ToAddress: toAddress, | ||
EncodedPayload: payload, | ||
FeeLimit: oc.gasLimit, | ||
ForwarderAddress: oc.forwarderAddress(), | ||
Strategy: oc.strategy, | ||
Checker: oc.checker, | ||
Meta: txMeta, | ||
}) | ||
return errors.Wrap(err, "skipped OCR transmission") | ||
} | ||
|
||
func (oc *contractTransmitter) forwarderAddress() common.Address { | ||
for _, a := range oc.fromAddresses { | ||
if a == oc.effectiveTransmitterAddress { | ||
return common.Address{} | ||
} | ||
} | ||
return oc.effectiveTransmitterAddress | ||
} | ||
|
||
// Transmit sends the report to the on-chain smart contract's Transmit method. | ||
func (oc *contractTransmitter) Transmit(ctx context.Context, reportCtx ocrtypes.ReportContext, report ocrtypes.Report, signatures []ocrtypes.AttributedOnchainSignature) error { | ||
var rs [][32]byte | ||
|
@@ -161,7 +220,7 @@ func (oc *contractTransmitter) Transmit(ctx context.Context, reportCtx ocrtypes. | |
} | ||
|
||
oc.lggr.Debugw("FunctionsContractTransmitter: transmitting report", "contractAddress", destinationContract, "txMeta", txMeta, "payloadSize", len(payload)) | ||
return errors.Wrap(oc.transmitter.CreateEthTransaction(ctx, destinationContract, payload, txMeta), "failed to send Eth transaction") | ||
return errors.Wrap(oc.createEthTransaction(ctx, destinationContract, payload, txMeta), "failed to send Eth transaction") | ||
} | ||
|
||
type contractReader interface { | ||
|
@@ -240,7 +299,7 @@ func (oc *contractTransmitter) LatestConfigDigestAndEpoch(ctx context.Context) ( | |
|
||
// FromAccount returns the account from which the transmitter invokes the contract | ||
func (oc *contractTransmitter) FromAccount() (ocrtypes.Account, error) { | ||
return ocrtypes.Account(oc.transmitter.FromAddress().String()), nil | ||
return ocrtypes.Account(oc.effectiveTransmitterAddress.String()), nil | ||
} | ||
|
||
func (oc *contractTransmitter) Start(ctx context.Context) error { return nil } | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can get rid of this, it's always set to nil (= no-op). Also remove reportToEvmTxMetaNoop function.