-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor secondary transmission (#15358)
* Refactor secondary transmission * Add dual transmission ABI * Update dual transmission ABI * Update ABI Add forwarder for secondary transmission * Refactor dual transmitter Add tests * Add missing test file * Add missing file * Fix lint * Fix lint Fix test * Pass txManagerOCR2 to ocr2FeedsDualTransmission * Add dualTransmission meta validation * Implement feedback * Add ContractTransmitter helper function * Add debug logging * Add hint and refund validation * rename file typo
- Loading branch information
1 parent
98adf6d
commit 1251ee3
Showing
11 changed files
with
743 additions
and
87 deletions.
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
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
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,134 @@ | ||
package ocrcommon | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"net/url" | ||
"slices" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/common/txmgr/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/forwarders" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" | ||
) | ||
|
||
type ocr2FeedsDualTransmission struct { | ||
txm txManager | ||
primaryFromAddresses []common.Address | ||
gasLimit uint64 | ||
primaryEffectiveTransmitterAddress common.Address | ||
strategy types.TxStrategy | ||
checker txmgr.TransmitCheckerSpec | ||
chainID *big.Int | ||
keystore roundRobinKeystore | ||
|
||
ocr2Aggregator common.Address | ||
txManagerOCR2 | ||
|
||
secondaryContractAddress common.Address | ||
secondaryFromAddress common.Address | ||
secondaryMeta map[string][]string | ||
} | ||
|
||
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) { | ||
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.primaryFromAddresses, forwarderAddress) { | ||
forwarderAddress = common.Address{} | ||
} | ||
|
||
return forwarderAddress, nil | ||
} | ||
|
||
func (t *ocr2FeedsDualTransmission) CreateEthTransaction(ctx context.Context, toAddress common.Address, payload []byte, txMeta *txmgr.TxMeta) error { | ||
roundRobinFromAddress, err := t.keystore.GetRoundRobinAddress(ctx, t.chainID, t.primaryFromAddresses...) | ||
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: skipped primary transmission") | ||
} | ||
|
||
func (t *ocr2FeedsDualTransmission) CreateSecondaryEthTransaction(ctx context.Context, payload []byte, txMeta *txmgr.TxMeta) error { | ||
forwarderAddress, err := t.forwarderAddress(ctx, t.secondaryFromAddress, t.secondaryContractAddress) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if txMeta == nil { | ||
txMeta = &txmgr.TxMeta{} | ||
} | ||
|
||
dualBroadcast := true | ||
dualBroadcastParams := t.urlParams() | ||
|
||
txMeta.DualBroadcast = &dualBroadcast | ||
txMeta.DualBroadcastParams = &dualBroadcastParams | ||
|
||
_, err = t.txm.CreateTransaction(ctx, txmgr.TxRequest{ | ||
FromAddress: t.secondaryFromAddress, | ||
ToAddress: t.secondaryContractAddress, | ||
EncodedPayload: payload, | ||
ForwarderAddress: forwarderAddress, | ||
FeeLimit: t.gasLimit, | ||
Strategy: t.strategy, | ||
Checker: t.checker, | ||
Meta: txMeta, | ||
}) | ||
|
||
return errors.Wrap(err, "skipped secondary transmission") | ||
} | ||
|
||
func (t *ocr2FeedsDualTransmission) FromAddress(ctx context.Context) common.Address { | ||
roundRobinFromAddress, err := t.keystore.GetRoundRobinAddress(ctx, t.chainID, t.primaryFromAddresses...) | ||
if err != nil { | ||
return t.primaryEffectiveTransmitterAddress | ||
} | ||
|
||
forwarderAddress, err := t.GetForwarderForEOAOCR2Feeds(ctx, roundRobinFromAddress, t.ocr2Aggregator) | ||
if errors.Is(err, forwarders.ErrForwarderForEOANotFound) { | ||
// if there are no valid forwarders try to fallback to eoa | ||
return roundRobinFromAddress | ||
} else if err != nil { | ||
return t.primaryEffectiveTransmitterAddress | ||
} | ||
|
||
return forwarderAddress | ||
} | ||
|
||
func (t *ocr2FeedsDualTransmission) urlParams() string { | ||
values := url.Values{} | ||
for k, v := range t.secondaryMeta { | ||
for _, p := range v { | ||
values.Add(k, p) | ||
} | ||
} | ||
return values.Encode() | ||
} |
Oops, something went wrong.