Skip to content

Commit

Permalink
Use only one constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
agusaldasoro committed Jul 1, 2024
1 parent ebc91a8 commit 4eb9a08
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 54 deletions.
35 changes: 19 additions & 16 deletions core/services/relay/evm/contract_transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Test_contractTransmitterNoSignatures_Transmit_SignaturesAreNotTransmitted(t
report := types.Report{}
var signatures = oneSignature()

oc := createContractTransmitter(t, transmitter, true)
oc := createContractTransmitter(ctx, t, transmitter, WithExcludeSignatures())

err := oc.Transmit(ctx, reportCtx, report, signatures)
require.NoError(t, err)
Expand All @@ -121,7 +121,7 @@ func Test_contractTransmitter_Transmit_SignaturesAreTransmitted(t *testing.T) {
report := types.Report{}
var signatures = oneSignature()

oc := createContractTransmitter(t, transmitter, false)
oc := createContractTransmitter(ctx, t, transmitter)

err := oc.Transmit(ctx, reportCtx, report, signatures)
require.NoError(t, err)
Expand Down Expand Up @@ -151,18 +151,21 @@ func oneSignature() []ocrtypes.AttributedOnchainSignature {
return []libocr.AttributedOnchainSignature{{Signature: signaturesData, Signer: commontypes.OracleID(54)}}
}

func createContractTransmitter(t *testing.T, transmitter Transmitter, excludeSignatures bool) contractTransmitter {
contractABI, _ := abi.JSON(strings.NewReader(ocr2aggregator.OCR2AggregatorMetaData.ABI))
fields := contractTransmitter{
contractAddress: gethcommon.Address{},
contractABI: contractABI,
transmitter: transmitter,
transmittedEventSig: gethcommon.Hash{},
lp: lpmocks.NewLogPoller(t),
contractReader: evmclimocks.NewClient(t),
lggr: logger.TestLogger(t),
reportToEvmTxMeta: reportToEvmTxMetaNoop,
excludeSigs: excludeSignatures,
}
return fields
func createContractTransmitter(ctx context.Context, t *testing.T, transmitter Transmitter, ops ...OCRTransmitterOption) *contractTransmitter {
contractABI, err := abi.JSON(strings.NewReader(ocr2aggregator.OCR2AggregatorMetaData.ABI))
require.NoError(t, err)
lp := lpmocks.NewLogPoller(t)
lp.On("RegisterFilter", mock.Anything, mock.Anything).Return(nil)
contractTransmitter, err := NewOCRContractTransmitter(
ctx,
gethcommon.Address{},
evmclimocks.NewClient(t),
contractABI,
transmitter,
lp,
logger.TestLogger(t),
ops...,
)
require.NoError(t, err)
return contractTransmitter
}
49 changes: 14 additions & 35 deletions core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import (
"math/big"
"strings"
"sync"
"time"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/ccipcommit"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/ccipexec"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
pkgerrors "github.com/pkg/errors"
"golang.org/x/exp/maps"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/ccipcommit"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/ccipexec"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"

"github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator"
"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median/evmreportcodec"
Expand Down Expand Up @@ -275,7 +274,7 @@ func (r *Relayer) NewPluginProvider(rargs commontypes.RelayArgs, pargs commontyp
return nil, err
}

transmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI, nil, 0)
transmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -432,7 +431,7 @@ func (r *Relayer) NewCCIPCommitProvider(rargs commontypes.RelayArgs, pargs commo
subjectID := chainToUUID(configWatcher.chain.ID())
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{
subjectID: &subjectID,
}, OCR2AggregatorTransmissionContractABI, fn, 0)
}, OCR2AggregatorTransmissionContractABI, WithReportToEthMetadata(fn))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -501,9 +500,11 @@ func (r *Relayer) NewCCIPExecProvider(rargs commontypes.RelayArgs, pargs commont
return nil, err
}
subjectID := chainToUUID(configWatcher.chain.ID())
contractTransmitter, err := newOnChainContractTransmitterExcludeSignatures(ctx, r.lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{
subjectID: &subjectID,
}, OCR2AggregatorTransmissionContractABI, fn, 0)
}, OCR2AggregatorTransmissionContractABI,
WithReportToEthMetadata(fn),
WithExcludeSignatures())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -739,27 +740,7 @@ type configTransmitterOpts struct {
}

// newOnChainContractTransmitter creates a new contract transmitter.
func newOnChainContractTransmitter(ctx context.Context, lggr logger.Logger, rargs commontypes.RelayArgs, ethKeystore keystore.Eth, configWatcher *configWatcher, opts configTransmitterOpts, transmissionContractABI abi.ABI, reportToEvmTxMeta ReportToEthMetadata, transmissionContractRetention time.Duration) (*contractTransmitter, error) {
transmitter, err := generateTransmitterFrom(ctx, rargs, ethKeystore, configWatcher, opts)
if err != nil {
return nil, err
}

return NewOCRContractTransmitter(
ctx,
configWatcher.contractAddress,
configWatcher.chain.Client(),
transmissionContractABI,
transmitter,
configWatcher.chain.LogPoller(),
lggr,
WithReportToEthMetadata(reportToEvmTxMeta),
WithRetention(transmissionContractRetention),
)
}

// newOnChainContractTransmitterExcludeSignatures creates a new contract transmitter that avoids sending the signatures as they are validated offchain.
func newOnChainContractTransmitterExcludeSignatures(ctx context.Context, lggr logger.Logger, rargs commontypes.RelayArgs, ethKeystore keystore.Eth, configWatcher *configWatcher, opts configTransmitterOpts, transmissionContractABI abi.ABI, reportToEvmTxMeta ReportToEthMetadata, transmissionContractRetention time.Duration) (*contractTransmitter, error) {
func newOnChainContractTransmitter(ctx context.Context, lggr logger.Logger, rargs commontypes.RelayArgs, ethKeystore keystore.Eth, configWatcher *configWatcher, opts configTransmitterOpts, transmissionContractABI abi.ABI, ocrTransmitterOpts ...OCRTransmitterOption) (*contractTransmitter, error) {
transmitter, err := generateTransmitterFrom(ctx, rargs, ethKeystore, configWatcher, opts)
if err != nil {
return nil, err
Expand All @@ -773,9 +754,7 @@ func newOnChainContractTransmitterExcludeSignatures(ctx context.Context, lggr lo
transmitter,
configWatcher.chain.LogPoller(),
lggr,
WithReportToEthMetadata(reportToEvmTxMeta),
WithRetention(transmissionContractRetention),
WithExcludeSignatures(),
ocrTransmitterOpts...,
)
}

Expand Down Expand Up @@ -898,7 +877,7 @@ func (r *Relayer) NewMedianProvider(rargs commontypes.RelayArgs, pargs commontyp

reportCodec := evmreportcodec.ReportCodec{}

contractTransmitter, err := newOnChainContractTransmitter(ctx, lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI, nil, 0)
contractTransmitter, err := newOnChainContractTransmitter(ctx, lggr, rargs, r.ks.Eth(), configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/relay/evm/ocr2keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *ocr2keeperRelayer) NewOCR2KeeperProvider(rargs commontypes.RelayArgs, p
}

gasLimit := cfgWatcher.chain.Config().EVM().OCR2().Automation().GasLimit()
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ethKeystore, cfgWatcher, configTransmitterOpts{pluginGasLimit: &gasLimit}, OCR2AggregatorTransmissionContractABI, nil, 0)
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ethKeystore, cfgWatcher, configTransmitterOpts{pluginGasLimit: &gasLimit}, OCR2AggregatorTransmissionContractABI)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/services/relay/evm/ocr2vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *ocr2vrfRelayer) NewDKGProvider(rargs commontypes.RelayArgs, pargs commo
if err != nil {
return nil, err
}
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ethKeystore, configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI, nil, 0)
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ethKeystore, configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI)
if err != nil {
return nil, err
}
Expand All @@ -89,7 +89,7 @@ func (r *ocr2vrfRelayer) NewOCR2VRFProvider(rargs commontypes.RelayArgs, pargs c
if err != nil {
return nil, err
}
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ethKeystore, configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI, nil, 0)
contractTransmitter, err := newOnChainContractTransmitter(ctx, r.lggr, rargs, r.ethKeystore, configWatcher, configTransmitterOpts{}, OCR2AggregatorTransmissionContractABI)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4eb9a08

Please sign in to comment.