Skip to content

Commit

Permalink
Add ContractTransmitter helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin committed Nov 29, 2024
1 parent 3bd32a3 commit 00c0f63
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
4 changes: 0 additions & 4 deletions core/services/ocrcommon/dual_transmittrer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions core/services/relay/evm/dual_contract_transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() }
31 changes: 29 additions & 2 deletions core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,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 {
Expand Down Expand Up @@ -879,7 +906,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
}
Expand All @@ -893,7 +920,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,
}

Expand Down

0 comments on commit 00c0f63

Please sign in to comment.