From e4ac2713e02da1673dd59f4fc7b5ca9c700791a0 Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Mon, 15 Jul 2024 14:47:29 +0300 Subject: [PATCH] fix contract transmitter --- .../ccipcapability/common/common_test.go | 2 +- .../configs/evm/chain_writer.go | 1 + .../configs/evm/contract_reader.go | 1 + core/services/ccipcapability/delegate.go | 3 +- .../ocrimpls/contract_transmitter.go | 53 ++- .../ocrimpls/contract_transmitter_test.go | 331 ++++++++++++------ .../ccipcapability/ocrimpls/keyring.go | 3 +- .../ccipcapability/oraclecreator/inprocess.go | 21 +- .../oraclecreator/inprocess_test.go | 16 +- .../ccipcapability/validate/validate_test.go | 3 +- 10 files changed, 296 insertions(+), 138 deletions(-) diff --git a/core/services/ccipcapability/common/common_test.go b/core/services/ccipcapability/common/common_test.go index 922ef69709..fc22f6ac58 100644 --- a/core/services/ccipcapability/common/common_test.go +++ b/core/services/ccipcapability/common/common_test.go @@ -6,7 +6,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" diff --git a/core/services/ccipcapability/configs/evm/chain_writer.go b/core/services/ccipcapability/configs/evm/chain_writer.go index 338c501a6e..57f9a85d4e 100644 --- a/core/services/ccipcapability/configs/evm/chain_writer.go +++ b/core/services/ccipcapability/configs/evm/chain_writer.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/chainlink-ccip/pkg/consts" "github.com/smartcontractkit/chainlink/v2/common/txmgr" diff --git a/core/services/ccipcapability/configs/evm/contract_reader.go b/core/services/ccipcapability/configs/evm/contract_reader.go index 0a9b6358b4..28b9182e3d 100644 --- a/core/services/ccipcapability/configs/evm/contract_reader.go +++ b/core/services/ccipcapability/configs/evm/contract_reader.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/smartcontractkit/chainlink-ccip/pkg/consts" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_multi_offramp" diff --git a/core/services/ccipcapability/delegate.go b/core/services/ccipcapability/delegate.go index 2a94578d7b..288c843ccc 100644 --- a/core/services/ccipcapability/delegate.go +++ b/core/services/ccipcapability/delegate.go @@ -5,10 +5,11 @@ import ( "fmt" "time" + ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types" + ccipreaderpkg "github.com/smartcontractkit/chainlink-ccip/pkg/reader" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" "github.com/smartcontractkit/chainlink-common/pkg/types" - ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" "github.com/smartcontractkit/chainlink/v2/core/config" diff --git a/core/services/ccipcapability/ocrimpls/contract_transmitter.go b/core/services/ccipcapability/ocrimpls/contract_transmitter.go index 4bd4f346a6..65108d966d 100644 --- a/core/services/ccipcapability/ocrimpls/contract_transmitter.go +++ b/core/services/ccipcapability/ocrimpls/contract_transmitter.go @@ -7,37 +7,54 @@ import ( "math/big" "github.com/google/uuid" - "github.com/smartcontractkit/chainlink-ccip/pkg/consts" - "github.com/smartcontractkit/chainlink-common/pkg/types" - commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/libocr/offchainreporting2/chains/evmutil" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-ccip/pkg/consts" + "github.com/smartcontractkit/chainlink-common/pkg/types" + commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" ) -type ToCalldataFunc func(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) any +type Calldata interface { + ToAny() any +} + +type commitCalldata struct { + ReportContext [3][32]byte + Report []byte + Rs [][32]byte + Ss [][32]byte + RawVs [32]byte +} + +func (c commitCalldata) ToAny() any { + return c +} + +type execCalldata struct { + ReportContext [3][32]byte + Report []byte +} + +func (e execCalldata) ToAny() any { + return e +} + +type ToCalldataFunc func(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) Calldata -func ToCommitCalldata(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) any { - return struct { - ReportContext [3][32]byte - Report []byte - Rs [][32]byte - Ss [][32]byte - Vs [32]byte - }{ +func ToCommitCalldata(rawReportCtx [3][32]byte, report []byte, rs, ss [][32]byte, vs [32]byte) Calldata { + return commitCalldata{ ReportContext: rawReportCtx, Report: report, Rs: rs, Ss: ss, - Vs: vs, + RawVs: vs, } } -func ToExecCalldata(rawReportCtx [3][32]byte, report []byte, _, _ [][32]byte, _ [32]byte) any { - return struct { - ReportContext [3][32]byte - Report []byte - }{ +func ToExecCalldata(rawReportCtx [3][32]byte, report []byte, _, _ [][32]byte, _ [32]byte) Calldata { + return execCalldata{ ReportContext: rawReportCtx, Report: report, } diff --git a/core/services/ccipcapability/ocrimpls/contract_transmitter_test.go b/core/services/ccipcapability/ocrimpls/contract_transmitter_test.go index 553cb9c315..6917921a61 100644 --- a/core/services/ccipcapability/ocrimpls/contract_transmitter_test.go +++ b/core/services/ccipcapability/ocrimpls/contract_transmitter_test.go @@ -1,6 +1,7 @@ package ocrimpls_test import ( + "crypto/rand" "math/big" "net/url" "testing" @@ -12,15 +13,16 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core" "github.com/jmoiron/sqlx" + "github.com/onsi/gomega" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" - txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" - "github.com/smartcontractkit/libocr/offchainreporting2plus/types" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox" + txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" @@ -46,91 +48,132 @@ import ( ) func Test_ContractTransmitter_TransmitWithoutSignatures(t *testing.T) { - t.Run("empty report", func(t *testing.T) { - uni := newTestUniverse[[]byte](t, nil) - - c, err := uni.wrapper.LatestConfigDetails(nil, uint8(cctypes.PluginTypeCCIPExec)) - require.NoError(t, err, "failed to get latest config details") - configDigest := c.ConfigInfo.ConfigDigest - - // create attributed sigs - // only need f+1 which is 2 in this case - rwi := ocr3types.ReportWithInfo[[]byte]{ - Report: []byte{}, - Info: []byte{}, - } - seqNr := uint64(1) - attributedSigs := uni.SignReport(t, configDigest, rwi, seqNr) - - account, err := uni.transmitterWithoutSigs.FromAccount() - require.NoError(t, err, "failed to get from account") - require.Equal(t, ocrtypes.Account(uni.transmitters[0].Hex()), account, "from account mismatch") - err = uni.transmitterWithoutSigs.Transmit(testutils.Context(t), configDigest, seqNr, rwi, attributedSigs) - require.NoError(t, err, "failed to transmit") - uni.backend.Commit() + type testCase struct { + name string + pluginType uint8 + withSigs bool + expectedSigsEnabled bool + report []byte + } - var txStatus uint64 - tests.AssertEventually(t, func() bool { - uni.backend.Commit() - rows, err := uni.db.QueryContext(testutils.Context(t), `SELECT hash FROM evm.tx_attempts LIMIT 1`) - require.NoError(t, err, "failed to query txes") - defer rows.Close() - var txHash []byte - for rows.Next() { - err = rows.Scan(&txHash) - require.NoError(t, err, "failed to scan") - } - t.Log("txHash:", txHash) - receipt, err := uni.simClient.TransactionReceipt(testutils.Context(t), common.BytesToHash(txHash)) - if err != nil { - t.Log("tx not found yet:", hexutil.Encode(txHash)) - return false - } - t.Log("tx found:", hexutil.Encode(txHash), "status:", receipt.Status) - txStatus = receipt.Status - return true + testCases := []testCase{ + { + "empty report with sigs", + uint8(cctypes.PluginTypeCCIPCommit), + true, + true, + []byte{}, + }, + { + "empty report without sigs", + uint8(cctypes.PluginTypeCCIPExec), + false, + false, + []byte{}, + }, + { + "report with data with sigs", + uint8(cctypes.PluginTypeCCIPCommit), + true, + true, + randomReport(t, 96), + }, + { + "report with data without sigs", + uint8(cctypes.PluginTypeCCIPExec), + false, + false, + randomReport(t, 96), + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + testTransmitter(t, tc.pluginType, tc.withSigs, tc.expectedSigsEnabled, tc.report) }) - - require.Equal(t, uint64(1), txStatus, "tx status should be success") - - // check that the event was emitted - events := uni.TransmittedEvents(t) - require.Len(t, events, 1, "expected 1 event") - require.Equal(t, configDigest, events[0].ConfigDigest, "config digest mismatch") - require.Equal(t, seqNr, events[0].SequenceNumber, "seq num mismatch") - }) + } } -func Test_ContractTransmitter_TransmitWithSignatures(t *testing.T) { - t.Run("empty report", func(t *testing.T) { - uni := newTestUniverse[[]byte](t, nil) +func testTransmitter( + t *testing.T, + pluginType uint8, + withSigs bool, + expectedSigsEnabled bool, + report []byte, +) { + uni := newTestUniverse[[]byte](t, nil) + + c, err := uni.wrapper.LatestConfigDetails(nil, pluginType) + require.NoError(t, err, "failed to get latest config details") + configDigest := c.ConfigInfo.ConfigDigest + require.Equal(t, expectedSigsEnabled, c.ConfigInfo.IsSignatureVerificationEnabled, "signature verification enabled setting not correct") + + // set the plugin type on the helper so it fetches the right config info. + // the important aspect is whether signatures should be enabled or not. + _, err = uni.wrapper.SetTransmitOcrPluginType(uni.deployer, pluginType) + require.NoError(t, err, "failed to set plugin type") + uni.backend.Commit() + + // create attributed sigs + // only need f+1 which is 2 in this case + rwi := ocr3types.ReportWithInfo[[]byte]{ + Report: report, + Info: []byte{}, + } + seqNr := uint64(1) + attributedSigs := uni.SignReport(t, configDigest, rwi, seqNr) - c, err := uni.wrapper.LatestConfigDetails(nil, uint8(cctypes.PluginTypeCCIPCommit)) - require.NoError(t, err, "failed to get latest config details") - configDigest := c.ConfigInfo.ConfigDigest + account, err := uni.transmitterWithSigs.FromAccount() + require.NoError(t, err, "failed to get from account") + require.Equal(t, ocrtypes.Account(uni.transmitters[0].Hex()), account, "from account mismatch") + if withSigs { + err = uni.transmitterWithSigs.Transmit(testutils.Context(t), configDigest, seqNr, rwi, attributedSigs) + } else { + err = uni.transmitterWithoutSigs.Transmit(testutils.Context(t), configDigest, seqNr, rwi, attributedSigs) + } + require.NoError(t, err, "failed to transmit") + uni.backend.Commit() - // create attributed sigs - // only need f+1 which is 2 in this case - rwi := ocr3types.ReportWithInfo[[]byte]{ - Report: []byte{}, - Info: []byte{}, + var txStatus uint64 + gomega.NewWithT(t).Eventually(func() bool { + uni.backend.Commit() + rows, err := uni.db.QueryContext(testutils.Context(t), `SELECT hash FROM evm.tx_attempts LIMIT 1`) + require.NoError(t, err, "failed to query txes") + defer rows.Close() + var txHash []byte + for rows.Next() { + require.NoError(t, rows.Scan(&txHash), "failed to scan") + } + t.Log("txHash:", txHash) + receipt, err := uni.simClient.TransactionReceipt(testutils.Context(t), common.BytesToHash(txHash)) + if err != nil { + t.Log("tx not found yet:", hexutil.Encode(txHash)) + return false } - seqNr := uint64(1) - attributedSigs := uni.SignReport(t, configDigest, rwi, seqNr) + t.Log("tx found:", hexutil.Encode(txHash), "status:", receipt.Status) + txStatus = receipt.Status + return true + }, testutils.WaitTimeout(t), 1*time.Second).Should(gomega.BeTrue()) + + // wait for receipt to be written to the db + gomega.NewWithT(t).Eventually(func() bool { + rows, err := uni.db.QueryContext(testutils.Context(t), `SELECT count(*) as cnt FROM evm.receipts LIMIT 1`) + require.NoError(t, err, "failed to query receipts") + defer rows.Close() + var count int + for rows.Next() { + require.NoError(t, rows.Scan(&count), "failed to scan") + } + return count == 1 + }, testutils.WaitTimeout(t), 2*time.Second).Should(gomega.BeTrue()) - account, err := uni.transmitterWithSigs.FromAccount() - require.NoError(t, err, "failed to get from account") - require.Equal(t, ocrtypes.Account(uni.transmitters[0].Hex()), account, "from account mismatch") - err = uni.transmitterWithSigs.Transmit(testutils.Context(t), configDigest, seqNr, rwi, attributedSigs) - require.NoError(t, err, "failed to transmit") - uni.backend.Commit() + require.Equal(t, uint64(1), txStatus, "tx status should be success") - // check that the event was emitted - events := uni.TransmittedEvents(t) - require.Len(t, events, 1, "expected 1 event") - require.Equal(t, configDigest, events[0].ConfigDigest, "config digest mismatch") - require.Equal(t, seqNr, events[0].SequenceNumber, "seq num mismatch") - }) + // check that the event was emitted + events := uni.TransmittedEvents(t) + require.Len(t, events, 1, "expected 1 event") + require.Equal(t, configDigest, events[0].ConfigDigest, "config digest mismatch") + require.Equal(t, seqNr, events[0].SequenceNumber, "seq num mismatch") } type testUniverse[RI any] struct { @@ -226,7 +269,7 @@ func newTestUniverse[RI any](t *testing.T, ks *keyringsAndSigners[RI]) *testUniv ConfigDigest: execConfigDigest, OcrPluginType: uint8(cctypes.PluginTypeCCIPExec), F: f, - IsSignatureVerificationEnabled: true, + IsSignatureVerificationEnabled: false, Signers: signers, Transmitters: []common.Address{ transmitters[0], @@ -253,6 +296,7 @@ func newTestUniverse[RI any](t *testing.T, ks *keyringsAndSigners[RI]) *testUniv txm, gasEstimator := makeTestEvmTxm(t, db, simClient, keyStore.Eth()) require.NoError(t, txm.Start(testutils.Context(t)), "failed to start tx manager") t.Cleanup(func() { require.NoError(t, txm.Close()) }) + chainWriter, err := evm.NewChainWriterService( logger.TestLogger(t), simClient, @@ -260,10 +304,12 @@ func newTestUniverse[RI any](t *testing.T, ks *keyringsAndSigners[RI]) *testUniv gasEstimator, chainWriterConfigRaw(transmitters[0], assets.GWei(1))) require.NoError(t, err, "failed to create chain writer") + require.NoError(t, chainWriter.Start(testutils.Context(t)), "failed to start chain writer") + t.Cleanup(func() { require.NoError(t, chainWriter.Close()) }) transmitterWithSigs := ocrimpls.XXXNewContractTransmitterTestsOnly[RI]( chainWriter, - types.Account(transmitters[0].Hex()), + ocrtypes.Account(transmitters[0].Hex()), contractName, methodTransmitWithSignatures, ocr3HelperAddr.Hex(), @@ -271,7 +317,7 @@ func newTestUniverse[RI any](t *testing.T, ks *keyringsAndSigners[RI]) *testUniv ) transmitterWithoutSigs := ocrimpls.XXXNewContractTransmitterTestsOnly[RI]( chainWriter, - types.Account(transmitters[0].Hex()), + ocrtypes.Account(transmitters[0].Hex()), contractName, methodTransmitWithoutSignatures, ocr3HelperAddr.Hex(), @@ -322,6 +368,13 @@ func (uni testUniverse[RI]) TransmittedEvents(t *testing.T) []*multi_ocr3_helper return events } +func randomReport(t *testing.T, len int) []byte { + report := make([]byte, len) + _, err := rand.Reader.Read(report) + require.NoError(t, err, "failed to read random bytes") + return report +} + const ( contractName = "MultiOCR3Helper" methodTransmitWithSignatures = "TransmitWithSignatures" @@ -371,8 +424,34 @@ func makeTestEvmTxm( KeepFinalizedBlocksDepth: 1000, } - ht := headtracker.NewSimulatedHeadTracker(ethClient, lpOpts.UseFinalityTag, lpOpts.FinalityDepth) - lp := logpoller.NewLogPoller(logpoller.NewORM(testutils.FixtureChainID, db, logger.NullLogger), ethClient, logger.NullLogger, ht, lpOpts) + chainID := big.NewInt(1337) + headSaver := headtracker.NewHeadSaver( + logger.NullLogger, + headtracker.NewORM(*chainID, db), + evmConfig, + evmConfig.HeadTrackerConfig, + ) + + broadcaster := headtracker.NewHeadBroadcaster(logger.NullLogger) + require.NoError(t, broadcaster.Start(testutils.Context(t)), "failed to start head broadcaster") + t.Cleanup(func() { require.NoError(t, broadcaster.Close()) }) + + ht := headtracker.NewHeadTracker( + logger.NullLogger, + ethClient, + evmConfig, + evmConfig.HeadTrackerConfig, + broadcaster, + headSaver, + mailbox.NewMonitor("contract_transmitter_test", logger.NullLogger), + ) + require.NoError(t, ht.Start(testutils.Context(t)), "failed to start head tracker") + t.Cleanup(func() { require.NoError(t, ht.Close()) }) + + lp := logpoller.NewLogPoller(logpoller.NewORM(testutils.FixtureChainID, db, logger.NullLogger), + ethClient, logger.NullLogger, ht, lpOpts) + require.NoError(t, lp.Start(testutils.Context(t)), "failed to start log poller") + t.Cleanup(func() { require.NoError(t, lp.Close()) }) // logic for building components (from evm/evm_txm.go) ------- lggr.Infow("Initializing EVM transaction manager", @@ -398,6 +477,9 @@ func makeTestEvmTxm( estimator) require.NoError(t, err, "can't create tx manager") + _, unsub := broadcaster.Subscribe(txm) + t.Cleanup(unsub) + return txm, estimator } @@ -430,8 +512,38 @@ func (d *TestDatabaseConfig) Listener() config.Listener { return &TestListenerConfig{} } +type TestHeadTrackerConfig struct{} + +// FinalityTagBypass implements config.HeadTracker. +func (t *TestHeadTrackerConfig) FinalityTagBypass() bool { + return false +} + +// HistoryDepth implements config.HeadTracker. +func (t *TestHeadTrackerConfig) HistoryDepth() uint32 { + return 50 +} + +// MaxAllowedFinalityDepth implements config.HeadTracker. +func (t *TestHeadTrackerConfig) MaxAllowedFinalityDepth() uint32 { + return 100 +} + +// MaxBufferSize implements config.HeadTracker. +func (t *TestHeadTrackerConfig) MaxBufferSize() uint32 { + return 100 +} + +// SamplingInterval implements config.HeadTracker. +func (t *TestHeadTrackerConfig) SamplingInterval() time.Duration { + return 1 * time.Second +} + +var _ evmconfig.HeadTracker = (*TestHeadTrackerConfig)(nil) + type TestEvmConfig struct { evmconfig.EVM + HeadTrackerConfig evmconfig.HeadTracker MaxInFlight uint32 ReaperInterval time.Duration ReaperThreshold time.Duration @@ -444,14 +556,28 @@ type TestEvmConfig struct { DetectionApiUrl *url.URL } +func (e *TestEvmConfig) FinalityTagEnabled() bool { + return false +} + +func (e *TestEvmConfig) FinalityDepth() uint32 { + return 42 +} + +func (e *TestEvmConfig) FinalizedBlockOffset() uint32 { + return 42 +} + +func (e *TestEvmConfig) BlockEmissionIdleWarningThreshold() time.Duration { + return 10 * time.Second +} + func (e *TestEvmConfig) Transactions() evmconfig.Transactions { return &transactionsConfig{e: e, autoPurge: &autoPurgeConfig{}} } func (e *TestEvmConfig) NonceAutoSync() bool { return true } -func (e *TestEvmConfig) FinalityDepth() uint32 { return 42 } - func (e *TestEvmConfig) ChainType() chaintype.ChainType { return "" } type TestGasEstimatorConfig struct { @@ -463,26 +589,26 @@ func (g *TestGasEstimatorConfig) BlockHistory() evmconfig.BlockHistory { } func (g *TestGasEstimatorConfig) EIP1559DynamicFees() bool { return false } -func (g *TestGasEstimatorConfig) LimitDefault() uint64 { return 42 } -func (g *TestGasEstimatorConfig) BumpPercent() uint16 { return 42 } +func (g *TestGasEstimatorConfig) LimitDefault() uint64 { return 1e6 } +func (g *TestGasEstimatorConfig) BumpPercent() uint16 { return 2 } func (g *TestGasEstimatorConfig) BumpThreshold() uint64 { return g.bumpThreshold } -func (g *TestGasEstimatorConfig) BumpMin() *assets.Wei { return assets.NewWeiI(42) } -func (g *TestGasEstimatorConfig) FeeCapDefault() *assets.Wei { return assets.NewWeiI(42) } -func (g *TestGasEstimatorConfig) PriceDefault() *assets.Wei { return assets.NewWeiI(42) } -func (g *TestGasEstimatorConfig) TipCapDefault() *assets.Wei { return assets.NewWeiI(42) } -func (g *TestGasEstimatorConfig) TipCapMin() *assets.Wei { return assets.NewWeiI(42) } +func (g *TestGasEstimatorConfig) BumpMin() *assets.Wei { return assets.GWei(1) } +func (g *TestGasEstimatorConfig) FeeCapDefault() *assets.Wei { return assets.GWei(1) } +func (g *TestGasEstimatorConfig) PriceDefault() *assets.Wei { return assets.GWei(1) } +func (g *TestGasEstimatorConfig) TipCapDefault() *assets.Wei { return assets.GWei(1) } +func (g *TestGasEstimatorConfig) TipCapMin() *assets.Wei { return assets.GWei(1) } func (g *TestGasEstimatorConfig) LimitMax() uint64 { return 0 } -func (g *TestGasEstimatorConfig) LimitMultiplier() float32 { return 0 } +func (g *TestGasEstimatorConfig) LimitMultiplier() float32 { return 1 } func (g *TestGasEstimatorConfig) BumpTxDepth() uint32 { return 42 } func (g *TestGasEstimatorConfig) LimitTransfer() uint64 { return 42 } -func (g *TestGasEstimatorConfig) PriceMax() *assets.Wei { return assets.NewWeiI(42) } -func (g *TestGasEstimatorConfig) PriceMin() *assets.Wei { return assets.NewWeiI(42) } +func (g *TestGasEstimatorConfig) PriceMax() *assets.Wei { return assets.GWei(1) } +func (g *TestGasEstimatorConfig) PriceMin() *assets.Wei { return assets.GWei(1) } func (g *TestGasEstimatorConfig) Mode() string { return "FixedPrice" } func (g *TestGasEstimatorConfig) LimitJobType() evmconfig.LimitJobType { return &TestLimitJobTypeConfig{} } func (g *TestGasEstimatorConfig) PriceMaxKey(addr common.Address) *assets.Wei { - return assets.NewWeiI(42) + return assets.GWei(1) } func (e *TestEvmConfig) GasEstimator() evmconfig.GasEstimator { @@ -515,7 +641,7 @@ type transactionsConfig struct { autoPurge evmconfig.AutoPurgeConfig } -func (*transactionsConfig) ForwardersEnabled() bool { return true } +func (*transactionsConfig) ForwardersEnabled() bool { return false } func (t *transactionsConfig) MaxInFlight() uint32 { return t.e.MaxInFlight } func (t *transactionsConfig) MaxQueued() uint64 { return t.e.MaxQueued } func (t *transactionsConfig) ReaperInterval() time.Duration { return t.e.ReaperInterval } @@ -549,7 +675,14 @@ func (c *MockConfig) RPCDefaultBatchSize() uint32 { return c.RpcDefaultBatchS func MakeTestConfigs(t *testing.T) (*MockConfig, *TestDatabaseConfig, *TestEvmConfig) { db := &TestDatabaseConfig{defaultQueryTimeout: utils.DefaultQueryTimeout} - ec := &TestEvmConfig{BumpThreshold: 42, MaxInFlight: uint32(42), MaxQueued: uint64(0), ReaperInterval: time.Duration(0), ReaperThreshold: time.Duration(0)} + ec := &TestEvmConfig{ + HeadTrackerConfig: &TestHeadTrackerConfig{}, + BumpThreshold: 42, + MaxInFlight: uint32(42), + MaxQueued: uint64(0), + ReaperInterval: time.Duration(0), + ReaperThreshold: time.Duration(0), + } config := &MockConfig{EvmConfig: ec} return config, db, ec } diff --git a/core/services/ccipcapability/ocrimpls/keyring.go b/core/services/ccipcapability/ocrimpls/keyring.go index 0d665cc96c..943ad412b4 100644 --- a/core/services/ccipcapability/ocrimpls/keyring.go +++ b/core/services/ccipcapability/ocrimpls/keyring.go @@ -2,9 +2,10 @@ package ocrimpls import ( "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + + "github.com/smartcontractkit/chainlink/v2/core/logger" ) var _ ocr3types.OnchainKeyring[[]byte] = &oc3Keyring[[]byte]{} diff --git a/core/services/ccipcapability/oraclecreator/inprocess.go b/core/services/ccipcapability/oraclecreator/inprocess.go index ced933a64a..3589d2ce2a 100644 --- a/core/services/ccipcapability/oraclecreator/inprocess.go +++ b/core/services/ccipcapability/oraclecreator/inprocess.go @@ -9,15 +9,16 @@ import ( "github.com/google/uuid" "github.com/prometheus/client_golang/prometheus" chainsel "github.com/smartcontractkit/chain-selectors" - commitocr3 "github.com/smartcontractkit/chainlink-ccip/commit" - execocr3 "github.com/smartcontractkit/chainlink-ccip/execute" - ccipreaderpkg "github.com/smartcontractkit/chainlink-ccip/pkg/reader" - cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" "github.com/smartcontractkit/libocr/commontypes" libocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + commitocr3 "github.com/smartcontractkit/chainlink-ccip/commit" + execocr3 "github.com/smartcontractkit/chainlink-ccip/execute" + ccipreaderpkg "github.com/smartcontractkit/chainlink-ccip/pkg/reader" + cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -161,7 +162,7 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp } else { chainReaderConfig = evmconfigs.SourceReaderConfig() } - cr, err := evm.NewChainReaderService( + cr, err2 := evm.NewChainReaderService( context.Background(), i.lggr. Named("EVMChainReaderService"). @@ -171,13 +172,13 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp chain.Client(), chainReaderConfig, ) - if err != nil { + if err2 != nil { return nil, fmt.Errorf("failed to create contract reader for chain %s: %w", chain.ID(), err) } // Even though we only write to the dest chain, we need to create chain writers for all chains // we know about in order to post gas prices on the dest. - cw, err := evm.NewChainWriterService( + cw, err2 := evm.NewChainWriterService( i.lggr.Named("EVMChainWriterService"). Named(chain.ID().String()). Named(pluginType.String()), @@ -186,7 +187,7 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp chain.GasEstimator(), evmrelaytypes.ChainWriterConfig{}, // TODO: pass in config ) - if err != nil { + if err2 != nil { return nil, fmt.Errorf("failed to create chain writer for chain %s: %w", chain.ID(), err) } @@ -210,7 +211,7 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp // assume that we are using the first account in the keybundle as the from account // and that we are able to transmit to the dest chain. // TODO: revisit this in the future, since not all oracles will be able to transmit to the dest chain. - destChainWriter, ok := chainWriters[cciptypes.ChainSelector(config.Config.ChainSelector)] + destChainWriter, ok := chainWriters[config.Config.ChainSelector] if !ok { return nil, fmt.Errorf("no chain writer found for dest chain selector %d, can't create contract transmitter", config.Config.ChainSelector) @@ -288,7 +289,7 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp func(ctx context.Context, msg string) {}), MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"name": fmt.Sprintf("commit-%d", config.Config.ChainSelector)}, prometheus.DefaultRegisterer), MonitoringEndpoint: i.monitoringEndpointGen.GenMonitoringEndpoint( - string(destChainFamily), + destChainFamily, destRelayID.ChainID, string(config.Config.OfframpAddress), synchronization.OCR3CCIPCommit, diff --git a/core/services/ccipcapability/oraclecreator/inprocess_test.go b/core/services/ccipcapability/oraclecreator/inprocess_test.go index 79988aa400..1ab9341ef4 100644 --- a/core/services/ccipcapability/oraclecreator/inprocess_test.go +++ b/core/services/ccipcapability/oraclecreator/inprocess_test.go @@ -13,13 +13,16 @@ import ( "gopkg.in/guregu/null.v4" chainsel "github.com/smartcontractkit/chain-selectors" - "github.com/smartcontractkit/chainlink-ccip/pkg/reader" - "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/libocr/offchainreporting2/types" confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" + "github.com/smartcontractkit/chainlink-ccip/pkg/reader" + "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + + "github.com/smartcontractkit/libocr/commontypes" + "github.com/smartcontractkit/chainlink/v2/core/bridges" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" @@ -41,14 +44,13 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/telemetry" "github.com/smartcontractkit/chainlink/v2/core/testdata/testspecs" "github.com/smartcontractkit/chainlink/v2/core/utils" - "github.com/smartcontractkit/libocr/commontypes" ) func TestOracleCreator_CreateBootstrap(t *testing.T) { db := pgtest.NewSqlxDB(t) keyStore := keystore.New(db, utils.DefaultScryptParams, logger.NullLogger) - keyStore.Unlock(testutils.Context(t), cltest.Password) + require.NoError(t, keyStore.Unlock(testutils.Context(t), cltest.Password), "unable to unlock keystore") p2pKey, err := keyStore.P2P().Create(testutils.Context(t)) require.NoError(t, err) peerID := p2pKey.PeerID() @@ -140,8 +142,8 @@ func TestOracleCreator_CreateBootstrap(t *testing.T) { P2PIds: func() [][32]byte { var ids [][32]byte for _, o := range oracles { - id, err := p2pkey.MakePeerID(o.PeerID) - require.NoError(t, err) + id, err2 := p2pkey.MakePeerID(o.PeerID) + require.NoError(t, err2) ids = append(ids, id) } return ids diff --git a/core/services/ccipcapability/validate/validate_test.go b/core/services/ccipcapability/validate/validate_test.go index 99d8ace5e6..e56da69336 100644 --- a/core/services/ccipcapability/validate/validate_test.go +++ b/core/services/ccipcapability/validate/validate_test.go @@ -3,9 +3,10 @@ package validate_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/smartcontractkit/chainlink/v2/core/services/ccipcapability/validate" "github.com/smartcontractkit/chainlink/v2/core/services/job" - "github.com/stretchr/testify/require" ) func TestNewCCIPSpecToml(t *testing.T) {