diff --git a/.changeset/four-shoes-trade.md b/.changeset/four-shoes-trade.md new file mode 100644 index 00000000000..cb5c9f4be6b --- /dev/null +++ b/.changeset/four-shoes-trade.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +Removed AppConfig from Evm config #internal diff --git a/core/chains/evm/config/chain_scoped.go b/core/chains/evm/config/chain_scoped.go index 2201831feaf..292582ddbc7 100644 --- a/core/chains/evm/config/chain_scoped.go +++ b/core/chains/evm/config/chain_scoped.go @@ -4,29 +4,21 @@ import ( "math/big" "time" - "go.uber.org/multierr" - - ocr "github.com/smartcontractkit/libocr/offchainreporting" - ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types" - "github.com/smartcontractkit/chainlink-common/pkg/assets" "github.com/smartcontractkit/chainlink-common/pkg/logger" commonconfig "github.com/smartcontractkit/chainlink/v2/common/config" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" - "github.com/smartcontractkit/chainlink/v2/core/config" ) -func NewTOMLChainScopedConfig(appCfg config.AppConfig, tomlConfig *toml.EVMConfig, lggr logger.Logger) *ChainScoped { +func NewTOMLChainScopedConfig(tomlConfig *toml.EVMConfig, lggr logger.Logger) *ChainScoped { return &ChainScoped{ - AppConfig: appCfg, evmConfig: &EVMConfig{C: tomlConfig}, lggr: lggr} } // ChainScoped implements config.ChainScopedConfig with a gencfg.BasicConfig and EVMConfig. type ChainScoped struct { - config.AppConfig lggr logger.Logger evmConfig *EVMConfig @@ -44,24 +36,6 @@ func (c *ChainScoped) BlockEmissionIdleWarningThreshold() time.Duration { return c.EVM().NodeNoNewHeadsThreshold() } -func (c *ChainScoped) Validate() (err error) { - // Most per-chain validation is done on startup, but this combines globals as well. - lc := ocrtypes.LocalConfig{ - BlockchainTimeout: c.OCR().BlockchainTimeout(), - ContractConfigConfirmations: c.EVM().OCR().ContractConfirmations(), - ContractConfigTrackerPollInterval: c.OCR().ContractPollInterval(), - ContractConfigTrackerSubscribeInterval: c.OCR().ContractSubscribeInterval(), - ContractTransmitterTransmitTimeout: c.EVM().OCR().ContractTransmitterTransmitTimeout(), - DatabaseTimeout: c.EVM().OCR().DatabaseTimeout(), - DataSourceTimeout: c.OCR().ObservationTimeout(), - DataSourceGracePeriod: c.EVM().OCR().ObservationGracePeriod(), - } - if ocrerr := ocr.SanityCheckLocalConfig(lc); ocrerr != nil { - err = multierr.Append(err, ocrerr) - } - return -} - type EVMConfig struct { C *toml.EVMConfig } diff --git a/core/chains/evm/config/config.go b/core/chains/evm/config/config.go index b9ff9ea9f8e..7295b29b096 100644 --- a/core/chains/evm/config/config.go +++ b/core/chains/evm/config/config.go @@ -11,7 +11,6 @@ import ( commonconfig "github.com/smartcontractkit/chainlink/v2/common/config" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" - "github.com/smartcontractkit/chainlink/v2/core/config" ) type EVM interface { @@ -148,8 +147,5 @@ type NodePool interface { // //go:generate mockery --quiet --name ChainScopedConfig --output ./mocks/ --case=underscore type ChainScopedConfig interface { - config.AppConfig - Validate() error - EVM() EVM } diff --git a/core/chains/evm/config/mocks/chain_scoped_config.go b/core/chains/evm/config/mocks/chain_scoped_config.go index 29b6d6f3f3e..a72e4b4d043 100644 --- a/core/chains/evm/config/mocks/chain_scoped_config.go +++ b/core/chains/evm/config/mocks/chain_scoped_config.go @@ -4,15 +4,7 @@ package mocks import ( config "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" - coreconfig "github.com/smartcontractkit/chainlink/v2/core/config" - mock "github.com/stretchr/testify/mock" - - time "time" - - uuid "github.com/google/uuid" - - zapcore "go.uber.org/zap/zapcore" ) // ChainScopedConfig is an autogenerated mock type for the ChainScopedConfig type @@ -20,124 +12,6 @@ type ChainScopedConfig struct { mock.Mock } -// AppID provides a mock function with given fields: -func (_m *ChainScopedConfig) AppID() uuid.UUID { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for AppID") - } - - var r0 uuid.UUID - if rf, ok := ret.Get(0).(func() uuid.UUID); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(uuid.UUID) - } - } - - return r0 -} - -// AuditLogger provides a mock function with given fields: -func (_m *ChainScopedConfig) AuditLogger() coreconfig.AuditLogger { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for AuditLogger") - } - - var r0 coreconfig.AuditLogger - if rf, ok := ret.Get(0).(func() coreconfig.AuditLogger); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.AuditLogger) - } - } - - return r0 -} - -// AutoPprof provides a mock function with given fields: -func (_m *ChainScopedConfig) AutoPprof() coreconfig.AutoPprof { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for AutoPprof") - } - - var r0 coreconfig.AutoPprof - if rf, ok := ret.Get(0).(func() coreconfig.AutoPprof); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.AutoPprof) - } - } - - return r0 -} - -// Capabilities provides a mock function with given fields: -func (_m *ChainScopedConfig) Capabilities() coreconfig.Capabilities { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Capabilities") - } - - var r0 coreconfig.Capabilities - if rf, ok := ret.Get(0).(func() coreconfig.Capabilities); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Capabilities) - } - } - - return r0 -} - -// CosmosEnabled provides a mock function with given fields: -func (_m *ChainScopedConfig) CosmosEnabled() bool { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for CosmosEnabled") - } - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// Database provides a mock function with given fields: -func (_m *ChainScopedConfig) Database() coreconfig.Database { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Database") - } - - var r0 coreconfig.Database - if rf, ok := ret.Get(0).(func() coreconfig.Database); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Database) - } - } - - return r0 -} - // EVM provides a mock function with given fields: func (_m *ChainScopedConfig) EVM() config.EVM { ret := _m.Called() @@ -158,561 +32,6 @@ func (_m *ChainScopedConfig) EVM() config.EVM { return r0 } -// EVMEnabled provides a mock function with given fields: -func (_m *ChainScopedConfig) EVMEnabled() bool { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for EVMEnabled") - } - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// EVMRPCEnabled provides a mock function with given fields: -func (_m *ChainScopedConfig) EVMRPCEnabled() bool { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for EVMRPCEnabled") - } - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// Feature provides a mock function with given fields: -func (_m *ChainScopedConfig) Feature() coreconfig.Feature { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Feature") - } - - var r0 coreconfig.Feature - if rf, ok := ret.Get(0).(func() coreconfig.Feature); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Feature) - } - } - - return r0 -} - -// FluxMonitor provides a mock function with given fields: -func (_m *ChainScopedConfig) FluxMonitor() coreconfig.FluxMonitor { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for FluxMonitor") - } - - var r0 coreconfig.FluxMonitor - if rf, ok := ret.Get(0).(func() coreconfig.FluxMonitor); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.FluxMonitor) - } - } - - return r0 -} - -// Insecure provides a mock function with given fields: -func (_m *ChainScopedConfig) Insecure() coreconfig.Insecure { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Insecure") - } - - var r0 coreconfig.Insecure - if rf, ok := ret.Get(0).(func() coreconfig.Insecure); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Insecure) - } - } - - return r0 -} - -// InsecureFastScrypt provides a mock function with given fields: -func (_m *ChainScopedConfig) InsecureFastScrypt() bool { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for InsecureFastScrypt") - } - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// JobPipeline provides a mock function with given fields: -func (_m *ChainScopedConfig) JobPipeline() coreconfig.JobPipeline { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for JobPipeline") - } - - var r0 coreconfig.JobPipeline - if rf, ok := ret.Get(0).(func() coreconfig.JobPipeline); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.JobPipeline) - } - } - - return r0 -} - -// Keeper provides a mock function with given fields: -func (_m *ChainScopedConfig) Keeper() coreconfig.Keeper { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Keeper") - } - - var r0 coreconfig.Keeper - if rf, ok := ret.Get(0).(func() coreconfig.Keeper); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Keeper) - } - } - - return r0 -} - -// Log provides a mock function with given fields: -func (_m *ChainScopedConfig) Log() coreconfig.Log { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Log") - } - - var r0 coreconfig.Log - if rf, ok := ret.Get(0).(func() coreconfig.Log); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Log) - } - } - - return r0 -} - -// LogConfiguration provides a mock function with given fields: log, warn -func (_m *ChainScopedConfig) LogConfiguration(log coreconfig.LogfFn, warn coreconfig.LogfFn) { - _m.Called(log, warn) -} - -// Mercury provides a mock function with given fields: -func (_m *ChainScopedConfig) Mercury() coreconfig.Mercury { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Mercury") - } - - var r0 coreconfig.Mercury - if rf, ok := ret.Get(0).(func() coreconfig.Mercury); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Mercury) - } - } - - return r0 -} - -// OCR provides a mock function with given fields: -func (_m *ChainScopedConfig) OCR() coreconfig.OCR { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for OCR") - } - - var r0 coreconfig.OCR - if rf, ok := ret.Get(0).(func() coreconfig.OCR); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.OCR) - } - } - - return r0 -} - -// OCR2 provides a mock function with given fields: -func (_m *ChainScopedConfig) OCR2() coreconfig.OCR2 { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for OCR2") - } - - var r0 coreconfig.OCR2 - if rf, ok := ret.Get(0).(func() coreconfig.OCR2); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.OCR2) - } - } - - return r0 -} - -// P2P provides a mock function with given fields: -func (_m *ChainScopedConfig) P2P() coreconfig.P2P { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for P2P") - } - - var r0 coreconfig.P2P - if rf, ok := ret.Get(0).(func() coreconfig.P2P); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.P2P) - } - } - - return r0 -} - -// Password provides a mock function with given fields: -func (_m *ChainScopedConfig) Password() coreconfig.Password { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Password") - } - - var r0 coreconfig.Password - if rf, ok := ret.Get(0).(func() coreconfig.Password); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Password) - } - } - - return r0 -} - -// Prometheus provides a mock function with given fields: -func (_m *ChainScopedConfig) Prometheus() coreconfig.Prometheus { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Prometheus") - } - - var r0 coreconfig.Prometheus - if rf, ok := ret.Get(0).(func() coreconfig.Prometheus); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Prometheus) - } - } - - return r0 -} - -// Pyroscope provides a mock function with given fields: -func (_m *ChainScopedConfig) Pyroscope() coreconfig.Pyroscope { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Pyroscope") - } - - var r0 coreconfig.Pyroscope - if rf, ok := ret.Get(0).(func() coreconfig.Pyroscope); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Pyroscope) - } - } - - return r0 -} - -// RootDir provides a mock function with given fields: -func (_m *ChainScopedConfig) RootDir() string { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for RootDir") - } - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Sentry provides a mock function with given fields: -func (_m *ChainScopedConfig) Sentry() coreconfig.Sentry { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Sentry") - } - - var r0 coreconfig.Sentry - if rf, ok := ret.Get(0).(func() coreconfig.Sentry); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Sentry) - } - } - - return r0 -} - -// SetLogLevel provides a mock function with given fields: lvl -func (_m *ChainScopedConfig) SetLogLevel(lvl zapcore.Level) error { - ret := _m.Called(lvl) - - if len(ret) == 0 { - panic("no return value specified for SetLogLevel") - } - - var r0 error - if rf, ok := ret.Get(0).(func(zapcore.Level) error); ok { - r0 = rf(lvl) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SetLogSQL provides a mock function with given fields: logSQL -func (_m *ChainScopedConfig) SetLogSQL(logSQL bool) { - _m.Called(logSQL) -} - -// SetPasswords provides a mock function with given fields: keystore, vrf -func (_m *ChainScopedConfig) SetPasswords(keystore *string, vrf *string) { - _m.Called(keystore, vrf) -} - -// ShutdownGracePeriod provides a mock function with given fields: -func (_m *ChainScopedConfig) ShutdownGracePeriod() time.Duration { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for ShutdownGracePeriod") - } - - var r0 time.Duration - if rf, ok := ret.Get(0).(func() time.Duration); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(time.Duration) - } - - return r0 -} - -// SolanaEnabled provides a mock function with given fields: -func (_m *ChainScopedConfig) SolanaEnabled() bool { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for SolanaEnabled") - } - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// StarkNetEnabled provides a mock function with given fields: -func (_m *ChainScopedConfig) StarkNetEnabled() bool { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for StarkNetEnabled") - } - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// TelemetryIngress provides a mock function with given fields: -func (_m *ChainScopedConfig) TelemetryIngress() coreconfig.TelemetryIngress { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for TelemetryIngress") - } - - var r0 coreconfig.TelemetryIngress - if rf, ok := ret.Get(0).(func() coreconfig.TelemetryIngress); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.TelemetryIngress) - } - } - - return r0 -} - -// Threshold provides a mock function with given fields: -func (_m *ChainScopedConfig) Threshold() coreconfig.Threshold { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Threshold") - } - - var r0 coreconfig.Threshold - if rf, ok := ret.Get(0).(func() coreconfig.Threshold); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Threshold) - } - } - - return r0 -} - -// Tracing provides a mock function with given fields: -func (_m *ChainScopedConfig) Tracing() coreconfig.Tracing { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Tracing") - } - - var r0 coreconfig.Tracing - if rf, ok := ret.Get(0).(func() coreconfig.Tracing); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.Tracing) - } - } - - return r0 -} - -// Validate provides a mock function with given fields: -func (_m *ChainScopedConfig) Validate() error { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Validate") - } - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// ValidateDB provides a mock function with given fields: -func (_m *ChainScopedConfig) ValidateDB() error { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for ValidateDB") - } - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// WebServer provides a mock function with given fields: -func (_m *ChainScopedConfig) WebServer() coreconfig.WebServer { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for WebServer") - } - - var r0 coreconfig.WebServer - if rf, ok := ret.Get(0).(func() coreconfig.WebServer); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(coreconfig.WebServer) - } - } - - return r0 -} - // NewChainScopedConfig creates a new instance of ChainScopedConfig. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewChainScopedConfig(t interface { diff --git a/core/chains/evm/log/helpers_test.go b/core/chains/evm/log/helpers_test.go index 8919b848aca..0d725b8594b 100644 --- a/core/chains/evm/log/helpers_test.go +++ b/core/chains/evm/log/helpers_test.go @@ -110,7 +110,7 @@ func newBroadcasterHelperWithEthClient(t *testing.T, ethClient evmclient.Client, m[r.Chain().ID().String()] = r.Chain() } legacyChains := legacyevm.NewLegacyChains(m, cc.AppConfig().EVMConfigs()) - pipelineHelper := cltest.NewJobPipelineV2(t, config.WebServer(), config.JobPipeline(), config.Database(), legacyChains, db, kst, nil, nil) + pipelineHelper := cltest.NewJobPipelineV2(t, globalConfig.WebServer(), globalConfig.JobPipeline(), globalConfig.Database(), legacyChains, db, kst, nil, nil) return &broadcasterHelper{ t: t, diff --git a/core/chains/evm/txmgr/broadcaster_test.go b/core/chains/evm/txmgr/broadcaster_test.go index 14968126bf9..9ab8a808a88 100644 --- a/core/chains/evm/txmgr/broadcaster_test.go +++ b/core/chains/evm/txmgr/broadcaster_test.go @@ -54,6 +54,7 @@ func NewTestEthBroadcaster( txStore txmgr.TestEvmTxStore, ethClient client.Client, keyStore keystore.Eth, + gconfig chainlink.GeneralConfig, config evmconfig.ChainScopedConfig, checkerFactory txmgr.TransmitCheckerFactory, nonceAutoSync bool, @@ -68,7 +69,7 @@ func NewTestEthBroadcaster( return gas.NewFixedPriceEstimator(config.EVM().GasEstimator(), nil, ge.BlockHistory(), lggr, nil) }, ge.EIP1559DynamicFees(), ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, keyStore, estimator) - ethBroadcaster := txmgrcommon.NewBroadcaster(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(config.EVM().GasEstimator()), config.EVM().Transactions(), config.Database().Listener(), keyStore, txBuilder, nonceTracker, lggr, checkerFactory, nonceAutoSync) + ethBroadcaster := txmgrcommon.NewBroadcaster(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(config.EVM().GasEstimator()), config.EVM().Transactions(), gconfig.Database().Listener(), keyStore, txBuilder, nonceTracker, lggr, checkerFactory, nonceAutoSync) // Mark instance as test ethBroadcaster.XXXTestDisableUnstartedTxAutoProcessing() @@ -93,7 +94,7 @@ func TestEthBroadcaster_Lifecycle(t *testing.T) { txmgr.NewEvmTxmConfig(evmcfg.EVM()), txmgr.NewEvmTxmFeeConfig(evmcfg.EVM().GasEstimator()), evmcfg.EVM().Transactions(), - evmcfg.Database().Listener(), + cfg.Database().Listener(), ethKeyStore, txBuilder, logger.Test(t), @@ -151,7 +152,7 @@ func TestEthBroadcaster_LoadNextSequenceMapFailure_StartupSuccess(t *testing.T) txmgr.NewEvmTxmConfig(evmcfg.EVM()), txmgr.NewEvmTxmFeeConfig(evmcfg.EVM().GasEstimator()), evmcfg.EVM().Transactions(), - evmcfg.Database().Listener(), + cfg.Database().Listener(), ethKeyStore, txBuilder, logger.Test(t), @@ -182,7 +183,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { ethClient.On("PendingNonceAt", mock.Anything, otherAddress).Return(uint64(0), nil).Once() lggr := logger.Test(t) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, checkerFactory, false, nonceTracker) toAddress := gethCommon.HexToAddress("0x6C03DDA95a2AEd917EeCc6eddD4b9D16E6380411") timeNow := time.Now() @@ -383,7 +384,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { evmcfg = evmtest.NewChainScopedConfig(t, cfg) ethClient.On("PendingNonceAt", mock.Anything, otherAddress).Return(uint64(1), nil).Once() nonceTracker = txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient)) - eb = NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker) + eb = NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, checkerFactory, false, nonceTracker) t.Run("sends transactions with type 0x2 in EIP-1559 mode", func(t *testing.T) { ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -533,7 +534,7 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) { checkerFactory := &testCheckerFactory{} ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, checkerFactory, false, nonceTracker) checker := txmgr.TransmitCheckerSpec{ CheckerType: txmgr.TransmitCheckerTypeSimulate, @@ -682,7 +683,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success_WithMultiplier(t *testing ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { assert.Equal(t, int(1600), int(tx.Gas())) @@ -764,7 +765,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) // Crashed right after we commit the database transaction that saved // the nonce to the eth_tx so evm.key_states.next_nonce has not been @@ -803,7 +804,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) @@ -840,7 +841,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) @@ -876,7 +877,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) @@ -914,7 +915,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) @@ -956,7 +957,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) @@ -1022,7 +1023,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { lggr := logger.Test(t) txmClient := txmgr.NewEvmTxmClient(ethClient) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmClient) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) ctx := testutils.Context(t) require.NoError(t, commonutils.JustError(db.Exec(`SET CONSTRAINTS fk_pipeline_runs_pruning_key DEFERRED`))) @@ -1157,7 +1158,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { }, evmcfg.EVM().GasEstimator().EIP1559DynamicFees(), evmcfg.EVM().GasEstimator()) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), evmcfg.EVM().GasEstimator(), ethKeyStore, estimator) localNextNonce = getLocalNextNonce(t, nonceTracker, fromAddress) - eb2 := txmgr.NewEvmBroadcaster(txStore, txmClient, txmgr.NewEvmTxmConfig(evmcfg.EVM()), txmgr.NewEvmTxmFeeConfig(evmcfg.EVM().GasEstimator()), evmcfg.EVM().Transactions(), evmcfg.Database().Listener(), ethKeyStore, txBuilder, lggr, &testCheckerFactory{}, false) + eb2 := txmgr.NewEvmBroadcaster(txStore, txmClient, txmgr.NewEvmTxmConfig(evmcfg.EVM()), txmgr.NewEvmTxmFeeConfig(evmcfg.EVM().GasEstimator()), evmcfg.EVM().Transactions(), cfg.Database().Listener(), ethKeyStore, txBuilder, lggr, &testCheckerFactory{}, false) retryable, err := eb2.ProcessUnstartedTxs(ctx, fromAddress) assert.NoError(t, err) assert.False(t, retryable) @@ -1481,7 +1482,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { c.EVM[0].GasEstimator.BumpMin = assets.NewWeiI(0) c.EVM[0].GasEstimator.BumpPercent = ptr[uint16](0) })) - eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg2, &testCheckerFactory{}, false, nonceTracker) + eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg2, &testCheckerFactory{}, false, nonceTracker) mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) // First was underpriced @@ -1573,7 +1574,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { })) localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(localNextNonce, nil).Once() - eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg2, &testCheckerFactory{}, false, nonceTracker) + eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg2, &testCheckerFactory{}, false, nonceTracker) mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) underpricedError := "transaction underpriced" localNextNonce = getLocalNextNonce(t, nonceTracker, fromAddress) @@ -1604,7 +1605,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { c.EVM[0].GasEstimator.TipCapDefault = assets.NewWeiI(0) })) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(localNextNonce, nil).Once() - eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg2, &testCheckerFactory{}, false, nonceTracker) + eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg2, &testCheckerFactory{}, false, nonceTracker) retryable, err := eb2.ProcessUnstartedTxs(ctx, fromAddress) require.Error(t, err) @@ -1619,7 +1620,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { })) localNextNonce = getLocalNextNonce(t, nonceTracker, fromAddress) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(localNextNonce, nil).Once() - eb2 = NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg2, &testCheckerFactory{}, false, nonceTracker) + eb2 = NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg2, &testCheckerFactory{}, false, nonceTracker) // Second was underpriced but above minimum ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -1667,7 +1668,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_KeystoreErrors(t *testing.T) { ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() lggr := logger.Test(t) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, kst, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, kst, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) ctx := testutils.Context(t) _, err := nonceTracker.GetNextSequence(ctx, fromAddress) require.NoError(t, err) @@ -1716,7 +1717,7 @@ func TestEthBroadcaster_Trigger(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) lggr := logger.Test(t) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) eb.Trigger(testutils.NewAddress()) eb.Trigger(testutils.NewAddress()) @@ -1788,7 +1789,7 @@ func TestEthBroadcaster_NonceTracker_InProgressTx(t *testing.T) { // Tx with nonce 0 in DB will set local nonce map to value to 1 mustInsertInProgressEthTxWithAttempt(t, txStore, evmtypes.Nonce(inProgressTxNonce), fromAddress) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient)) - eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, checkerFactory, false, nonceTracker) + eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, checkerFactory, false, nonceTracker) // Check the local nonce map was set to 1 higher than in-progress tx nonce nonce := getLocalNextNonce(t, nonceTracker, fromAddress) diff --git a/core/chains/evm/txmgr/confirmer_test.go b/core/chains/evm/txmgr/confirmer_test.go index f368aea9c57..88c7dfc0a53 100644 --- a/core/chains/evm/txmgr/confirmer_test.go +++ b/core/chains/evm/txmgr/confirmer_test.go @@ -46,9 +46,9 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" ) -func newTestChainScopedConfig(t *testing.T) evmconfig.ChainScopedConfig { +func newTestChainScopedConfig(t *testing.T) (chainlink.GeneralConfig, evmconfig.ChainScopedConfig) { cfg := configtest.NewTestGeneralConfig(t) - return evmtest.NewChainScopedConfig(t, cfg) + return cfg, evmtest.NewChainScopedConfig(t, cfg) } func newBroadcastLegacyEthTxAttempt(t *testing.T, etxID int64, gasPrice ...int64) txmgr.TxAttempt { @@ -114,7 +114,7 @@ func TestEthConfirmer_Lifecycle(t *testing.T) { t.Parallel() db := pgtest.NewSqlxDB(t) - config := newTestChainScopedConfig(t) + gconfig, config := newTestChainScopedConfig(t) txStore := newTxStore(t, db) ethClient := evmtest.NewEthClientMockWithDefaultChain(t) @@ -129,7 +129,7 @@ func TestEthConfirmer_Lifecycle(t *testing.T) { ge := config.EVM().GasEstimator() feeEstimator := gas.NewEvmFeeEstimator(lggr, newEst, ge.EIP1559DynamicFees(), ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, ethKeyStore, feeEstimator) - ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), config.Database(), ethKeyStore, txBuilder, lggr) + ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), gconfig.Database(), ethKeyStore, txBuilder, lggr) ctx := testutils.Context(t) // Can't close unstarted instance @@ -184,7 +184,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { t.Parallel() db := pgtest.NewSqlxDB(t) - config := newTestChainScopedConfig(t) + gconfig, config := newTestChainScopedConfig(t) txStore := cltest.NewTestTxStore(t, db) ethClient := evmtest.NewEthClientMockWithDefaultChain(t) @@ -192,7 +192,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) nonce := int64(0) ctx := testutils.Context(t) @@ -609,7 +609,7 @@ func TestEthConfirmer_CheckForReceipts_batching(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) @@ -669,7 +669,7 @@ func TestEthConfirmer_CheckForReceipts_HandlesNonFwdTxsWithForwardingEnabled(t * evmcfg := evmtest.NewChainScopedConfig(t, cfg) _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // tx is not forwarded and doesn't have meta set. EthConfirmer should handle nil meta values etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) @@ -722,7 +722,7 @@ func TestEthConfirmer_CheckForReceipts_only_likely_confirmed(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) var attempts []txmgr.TxAttempt @@ -767,7 +767,7 @@ func TestEthConfirmer_CheckForReceipts_should_not_check_for_likely_unconfirmed(t t.Parallel() db := pgtest.NewSqlxDB(t) - config := newTestChainScopedConfig(t) + gconfig, config := newTestChainScopedConfig(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -776,7 +776,7 @@ func TestEthConfirmer_CheckForReceipts_should_not_check_for_likely_unconfirmed(t ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ctx := testutils.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 1, fromAddress) @@ -807,7 +807,7 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt_scoped_to_key(t ethClient.On("SequenceAt", mock.Anything, mock.Anything, mock.Anything).Return(evmtypes.Nonce(20), nil) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -874,7 +874,7 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1134,7 +1134,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1213,7 +1213,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_batchSendTransactions_fails(t evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1277,7 +1277,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_smallEvmRPCBatchSize_middleBa evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1360,7 +1360,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { lggr := logger.Test(t) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) t.Run("returns nothing when there are no transactions", func(t *testing.T) { etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) @@ -1746,7 +1746,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_MaxFeeScenario(t *testing.T) { addresses := []gethCommon.Address{fromAddress} kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Maybe() // Use a mock keystore for this test - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) currentHead := int64(30) oldEnough := int64(19) nonce := int64(0) @@ -1814,7 +1814,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { addresses := []gethCommon.Address{fromAddress} kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Maybe() // Use a mock keystore for this test - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) currentHead := int64(30) oldEnough := int64(19) nonce := int64(0) @@ -2247,7 +2247,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.NewWeiI(60500000000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2 := newEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) + ec2 := newEthConfirmer(t, txStore, ethClient, gcfg, newCfg, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return evmtypes.Nonce(tx.Nonce()) == *etx3.Sequence && gasPrice.Cmp(tx.GasPrice()) == 0 @@ -2277,7 +2277,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.NewWeiI(60480000000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2 := newEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) + ec2 := newEthConfirmer(t, txStore, ethClient, gcfg, newCfg, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return evmtypes.Nonce(tx.Nonce()) == *etx3.Sequence && gasPrice.Cmp(tx.GasPrice()) == 0 @@ -2345,7 +2345,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.GWei(1000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2 := newEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) + ec2 := newEthConfirmer(t, txStore, ethClient, gcfg, newCfg, ethKeyStore, nil) // Third attempt failed to bump, resubmits old one instead ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { @@ -2431,7 +2431,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("terminally underpriced transaction with in_progress attempt is retried with more gas", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) originalBroadcastAt := time.Unix(1616509100, 0) etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, nonce, fromAddress, txmgrtypes.TxAttemptInProgress, originalBroadcastAt) @@ -2455,7 +2455,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in legacy mode", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, nonce, fromAddress) nonce++ @@ -2487,7 +2487,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in EIP-1559 mode", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) etx := mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress) nonce++ @@ -2535,7 +2535,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { // keyStates, err := ethKeyStore.GetStatesForKeys(keys) // require.NoError(t, err) - config := newTestChainScopedConfig(t) + gconfig, config := newTestChainScopedConfig(t) currentHead := int64(30) oldEnough := int64(19) nonce := int64(0) @@ -2551,7 +2551,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { insufficientEthError := errors.New("insufficient funds for gas * price + value") t.Run("saves attempt with state 'insufficient_eth' if eth node returns this error", func(t *testing.T) { - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2577,7 +2577,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }) t.Run("does not bump gas when previous error was 'out of eth', instead resubmits existing transaction", func(t *testing.T) { - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2602,7 +2602,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }) t.Run("saves the attempt as broadcast after node wallet has been topped up with sufficient balance", func(t *testing.T) { - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2634,7 +2634,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { c.EVM[0].GasEstimator.BumpTxDepth = ptr(uint32(depth)) }) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) for i := 0; i < etxCount; i++ { n := nonce @@ -2668,8 +2668,8 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - config := newTestChainScopedConfig(t) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + gconfig, config := newTestChainScopedConfig(t) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) head := evmtypes.Head{ Hash: utils.NewHash(), @@ -2838,7 +2838,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - config := newTestChainScopedConfig(t) + gconfig, config := newTestChainScopedConfig(t) mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, config.EVM().ChainID()) mustInsertInProgressEthTx(t, txStore, 0, fromAddress) etx1 := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress) @@ -2849,7 +2849,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("rebroadcasts one eth_tx if it falls within in nonce range", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && @@ -2864,7 +2864,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("uses default gas limit if overrideGasLimit is 0", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && @@ -2879,7 +2879,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("rebroadcasts several eth_txes in nonce range", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && tx.Gas() == overrideGasLimit @@ -2893,7 +2893,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("broadcasts zero transactions if eth_tx doesn't exist for that nonce", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(1) @@ -2919,7 +2919,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("zero transactions use default gas limit if override wasn't specified", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(0) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && tx.Gas() == config.EVM().GasEstimator().LimitDefault() @@ -2964,7 +2964,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { pgtest.MustExec(t, db, `SET CONSTRAINTS pipeline_runs_pipeline_spec_id_fkey DEFERRED`) t.Run("doesn't process task runs that are not suspended (possibly already previously resumed)", func(t *testing.T) { - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(context.Context, uuid.UUID, interface{}, error) error { + ec := newEthConfirmer(t, txStore, ethClient, config, evmcfg, ethKeyStore, func(context.Context, uuid.UUID, interface{}, error) error { t.Fatal("No value expected") return nil }) @@ -2983,7 +2983,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { }) t.Run("doesn't process task runs where the receipt is younger than minConfirmations", func(t *testing.T) { - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(context.Context, uuid.UUID, interface{}, error) error { + ec := newEthConfirmer(t, txStore, ethClient, config, evmcfg, ethKeyStore, func(context.Context, uuid.UUID, interface{}, error) error { t.Fatal("No value expected") return nil }) @@ -3004,7 +3004,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { ch := make(chan interface{}) nonce := evmtypes.Nonce(3) var err error - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(ctx context.Context, id uuid.UUID, value interface{}, thisErr error) error { + ec := newEthConfirmer(t, txStore, ethClient, config, evmcfg, ethKeyStore, func(ctx context.Context, id uuid.UUID, value interface{}, thisErr error) error { err = thisErr ch <- value return nil @@ -3057,7 +3057,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { } ch := make(chan data) nonce := evmtypes.Nonce(4) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(ctx context.Context, id uuid.UUID, value interface{}, err error) error { + ec := newEthConfirmer(t, txStore, ethClient, config, evmcfg, ethKeyStore, func(ctx context.Context, id uuid.UUID, value interface{}, err error) error { ch <- data{value, err} return nil }) @@ -3104,7 +3104,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { t.Run("does not mark callback complete if callback fails", func(t *testing.T) { nonce := evmtypes.Nonce(5) - ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(context.Context, uuid.UUID, interface{}, error) error { + ec := newEthConfirmer(t, txStore, ethClient, config, evmcfg, ethKeyStore, func(context.Context, uuid.UUID, interface{}, error) error { return errors.New("error") }) @@ -3127,14 +3127,14 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { func ptr[T any](t T) *T { return &t } -func newEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient client.Client, config evmconfig.ChainScopedConfig, ks keystore.Eth, fn txmgrcommon.ResumeCallback) *txmgr.Confirmer { +func newEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient client.Client, gconfig chainlink.GeneralConfig, config evmconfig.ChainScopedConfig, ks keystore.Eth, fn txmgrcommon.ResumeCallback) *txmgr.Confirmer { lggr := logger.Test(t) ge := config.EVM().GasEstimator() estimator := gas.NewEvmFeeEstimator(lggr, func(lggr logger.Logger) gas.EvmEstimator { return gas.NewFixedPriceEstimator(ge, nil, ge.BlockHistory(), lggr, nil) }, ge.EIP1559DynamicFees(), ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, ks, estimator) - ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), config.Database(), ks, txBuilder, lggr) + ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), gconfig.Database(), ks, txBuilder, lggr) ec.SetResumeCallback(fn) servicetest.Run(t, ec) return ec diff --git a/core/chains/evm/txmgr/evm_tx_store_test.go b/core/chains/evm/txmgr/evm_tx_store_test.go index 1d1d85c0960..cf38b2d1275 100644 --- a/core/chains/evm/txmgr/evm_tx_store_test.go +++ b/core/chains/evm/txmgr/evm_tx_store_test.go @@ -371,7 +371,7 @@ func TestORM_SetBroadcastBeforeBlockNum(t *testing.T) { t.Parallel() db := pgtest.NewSqlxDB(t) - cfg := newTestChainScopedConfig(t) + _, cfg := newTestChainScopedConfig(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() ethClient := evmtest.NewEthClientMockWithDefaultChain(t) @@ -692,7 +692,7 @@ func TestORM_FindTxesPendingCallback(t *testing.T) { func Test_FindTxWithIdempotencyKey(t *testing.T) { t.Parallel() db := pgtest.NewSqlxDB(t) - cfg := newTestChainScopedConfig(t) + _, cfg := newTestChainScopedConfig(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) diff --git a/core/chains/evm/txmgr/txmgr_test.go b/core/chains/evm/txmgr/txmgr_test.go index 691b83f8e4c..b76c9255b2b 100644 --- a/core/chains/evm/txmgr/txmgr_test.go +++ b/core/chains/evm/txmgr/txmgr_test.go @@ -547,7 +547,7 @@ func TestTxm_Reset(t *testing.T) { ethClient.On("PendingNonceAt", mock.Anything, addr2).Return(uint64(44), nil).Maybe() estimator := gas.NewEstimator(logger.Test(t), ethClient, cfg.EVM(), cfg.EVM().GasEstimator()) - txm, err := makeTestEvmTxm(t, db, ethClient, estimator, cfg.EVM(), cfg.EVM().GasEstimator(), cfg.EVM().Transactions(), cfg.Database(), cfg.Database().Listener(), kst.Eth()) + txm, err := makeTestEvmTxm(t, db, ethClient, estimator, cfg.EVM(), cfg.EVM().GasEstimator(), cfg.EVM().Transactions(), gcfg.Database(), gcfg.Database().Listener(), kst.Eth()) require.NoError(t, err) cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, addr2) diff --git a/core/chains/legacyevm/chain.go b/core/chains/legacyevm/chain.go index 1066eeecbea..00a235f391b 100644 --- a/core/chains/legacyevm/chain.go +++ b/core/chains/legacyevm/chain.go @@ -206,7 +206,7 @@ func NewTOMLChain(ctx context.Context, chain *toml.EVMConfig, opts ChainRelayExt if !chain.IsEnabled() { return nil, errChainDisabled{ChainID: chainID} } - cfg := evmconfig.NewTOMLChainScopedConfig(opts.AppConfig, chain, l) + cfg := evmconfig.NewTOMLChainScopedConfig(chain, l) // note: per-chain validation is not necessary at this point since everything is checked earlier on boot. return newChain(ctx, cfg, chain.Nodes, opts) } @@ -215,7 +215,7 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod chainID := cfg.EVM().ChainID() l := opts.Logger var client evmclient.Client - if !cfg.EVMRPCEnabled() { + if !opts.AppConfig.EVMRPCEnabled() { client = evmclient.NewNullClient(chainID, l) } else if opts.GenEthClient == nil { client = evmclient.NewEvmClient(cfg.EVM().NodePool(), cfg.EVM(), l, chainID, nodes) @@ -226,7 +226,7 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod headBroadcaster := headtracker.NewHeadBroadcaster(l) headSaver := headtracker.NullSaver var headTracker httypes.HeadTracker - if !cfg.EVMRPCEnabled() { + if !opts.AppConfig.EVMRPCEnabled() { headTracker = headtracker.NullTracker } else if opts.GenHeadTracker == nil { orm := headtracker.NewORM(*chainID, opts.DB) @@ -237,7 +237,7 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod } logPoller := logpoller.LogPollerDisabled - if cfg.Feature().LogPoller() { + if opts.AppConfig.Feature().LogPoller() { if opts.GenLogPoller != nil { logPoller = opts.GenLogPoller(chainID) } else { @@ -256,7 +256,7 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod } // note: gas estimator is started as a part of the txm - txm, gasEstimator, err := newEvmTxm(opts.SqlxDB, opts.DB, cfg.EVM(), cfg.EVMRPCEnabled(), cfg.Database(), cfg.Database().Listener(), client, l, logPoller, opts) + txm, gasEstimator, err := newEvmTxm(opts.SqlxDB, opts.DB, cfg.EVM(), opts.AppConfig.EVMRPCEnabled(), opts.AppConfig.Database(), opts.AppConfig.Database().Listener(), client, l, logPoller, opts) if err != nil { return nil, fmt.Errorf("failed to instantiate EvmTxm for chain with ID %s: %w", chainID.String(), err) } @@ -270,13 +270,13 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod } var balanceMonitor monitor.BalanceMonitor - if cfg.EVMRPCEnabled() && cfg.EVM().BalanceMonitor().Enabled() { + if opts.AppConfig.EVMRPCEnabled() && cfg.EVM().BalanceMonitor().Enabled() { balanceMonitor = monitor.NewBalanceMonitor(client, opts.KeyStore, l) headBroadcaster.Subscribe(balanceMonitor) } var logBroadcaster log.Broadcaster - if !cfg.EVMRPCEnabled() { + if !opts.AppConfig.EVMRPCEnabled() { logBroadcaster = &log.NullBroadcaster{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)} } else if opts.GenLogBroadcaster == nil { logORM := log.NewORM(opts.SqlxDB, *chainID) diff --git a/core/cmd/shell_local.go b/core/cmd/shell_local.go index 66ceafa5cb2..8e29dada9a5 100644 --- a/core/cmd/shell_local.go +++ b/core/cmd/shell_local.go @@ -636,7 +636,7 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) { txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), chain.Config().EVM().GasEstimator(), keyStore.Eth(), nil) cfg := txmgr.NewEvmTxmConfig(chain.Config().EVM()) feeCfg := txmgr.NewEvmTxmFeeConfig(chain.Config().EVM().GasEstimator()) - ec := txmgr.NewEvmConfirmer(orm, txmgr.NewEvmTxmClient(ethClient), cfg, feeCfg, chain.Config().EVM().Transactions(), chain.Config().Database(), keyStore.Eth(), txBuilder, chain.Logger()) + ec := txmgr.NewEvmConfirmer(orm, txmgr.NewEvmTxmClient(ethClient), cfg, feeCfg, chain.Config().EVM().Transactions(), app.GetConfig().Database(), keyStore.Eth(), txBuilder, chain.Logger()) totalNonces := endingNonce - beginningNonce + 1 nonces := make([]evmtypes.Nonce, totalNonces) for i := int64(0); i < totalNonces; i++ { diff --git a/core/cmd/shell_local_test.go b/core/cmd/shell_local_test.go index 0db99d1a57a..d608d3931d0 100644 --- a/core/cmd/shell_local_test.go +++ b/core/cmd/shell_local_test.go @@ -302,6 +302,7 @@ func TestShell_RebroadcastTransactions_Txm(t *testing.T) { app.On("GetSqlxDB").Return(sqlxDB) app.On("GetKeyStore").Return(keyStore) app.On("ID").Maybe().Return(uuid.New()) + app.On("GetConfig").Return(config) ethClient := evmtest.NewEthClientMockWithDefaultChain(t) legacy := cltest.NewLegacyChainsWithMockChain(t, ethClient, config) @@ -383,6 +384,7 @@ func TestShell_RebroadcastTransactions_OutsideRange_Txm(t *testing.T) { app.On("GetSqlxDB").Return(sqlxDB) app.On("GetKeyStore").Return(keyStore) app.On("ID").Maybe().Return(uuid.New()) + app.On("GetConfig").Return(config) ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethClient.On("Dial", mock.Anything).Return(nil) legacy := cltest.NewLegacyChainsWithMockChain(t, ethClient, config) @@ -487,6 +489,7 @@ func TestShell_RebroadcastTransactions_AddressCheck(t *testing.T) { if test.shouldError { require.ErrorContains(t, client.RebroadcastTransactions(c), test.errorContains) } else { + app.On("GetConfig").Return(config).Once() require.NoError(t, client.RebroadcastTransactions(c)) } diff --git a/core/internal/features/features_test.go b/core/internal/features/features_test.go index 516f0ae0907..75ff98d05be 100644 --- a/core/internal/features/features_test.go +++ b/core/internal/features/features_test.go @@ -869,7 +869,7 @@ func TestIntegration_OCR(t *testing.T) { err = appBootstrap.Start(testutils.Context(t)) require.NoError(t, err) - jb, err := ocr.ValidatedOracleSpecToml(appBootstrap.GetRelayers().LegacyEVMChains(), fmt.Sprintf(` + jb, err := ocr.ValidatedOracleSpecToml(appBootstrap.Config, appBootstrap.GetRelayers().LegacyEVMChains(), fmt.Sprintf(` type = "offchainreporting" schemaVersion = 1 name = "boot" @@ -938,7 +938,7 @@ isBootstrapPeer = true // Note we need: observationTimeout + observationGracePeriod + DeltaGrace (500ms) < DeltaRound (1s) // So 200ms + 200ms + 500ms < 1s - jb, err := ocr.ValidatedOracleSpecToml(apps[i].GetRelayers().LegacyEVMChains(), fmt.Sprintf(` + jb, err := ocr.ValidatedOracleSpecToml(apps[i].Config, apps[i].GetRelayers().LegacyEVMChains(), fmt.Sprintf(` type = "offchainreporting" schemaVersion = 1 name = "web oracle spec" @@ -1094,7 +1094,7 @@ func TestIntegration_OCR_ForwarderFlow(t *testing.T) { require.NoError(t, err) // set forwardingAllowed = true - jb, err := ocr.ValidatedOracleSpecToml(appBootstrap.GetRelayers().LegacyEVMChains(), fmt.Sprintf(` + jb, err := ocr.ValidatedOracleSpecToml(appBootstrap.Config, appBootstrap.GetRelayers().LegacyEVMChains(), fmt.Sprintf(` type = "offchainreporting" schemaVersion = 1 name = "boot" @@ -1165,7 +1165,7 @@ isBootstrapPeer = true // Note we need: observationTimeout + observationGracePeriod + DeltaGrace (500ms) < DeltaRound (1s) // So 200ms + 200ms + 500ms < 1s // forwardingAllowed = true - jb, err := ocr.ValidatedOracleSpecToml(apps[i].GetRelayers().LegacyEVMChains(), fmt.Sprintf(` + jb, err := ocr.ValidatedOracleSpecToml(apps[i].Config, apps[i].GetRelayers().LegacyEVMChains(), fmt.Sprintf(` type = "offchainreporting" schemaVersion = 1 name = "web oracle spec" diff --git a/core/internal/testutils/evmtest/evmtest.go b/core/internal/testutils/evmtest/evmtest.go index 83c356bf1a3..311ee2ec33a 100644 --- a/core/internal/testutils/evmtest/evmtest.go +++ b/core/internal/testutils/evmtest/evmtest.go @@ -53,7 +53,7 @@ func NewChainScopedConfig(t testing.TB, cfg legacyevm.AppConfig) evmconfig.Chain } } - return evmconfig.NewTOMLChainScopedConfig(cfg, evmCfg, logger.TestLogger(t)) + return evmconfig.NewTOMLChainScopedConfig(evmCfg, logger.TestLogger(t)) } diff --git a/core/internal/testutils/evmtest/v2/evmtest.go b/core/internal/testutils/evmtest/v2/evmtest.go index 22b2bc5e0ca..5621d91e748 100644 --- a/core/internal/testutils/evmtest/v2/evmtest.go +++ b/core/internal/testutils/evmtest/v2/evmtest.go @@ -6,7 +6,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" "github.com/smartcontractkit/chainlink/v2/core/logger" ) @@ -18,5 +17,5 @@ func ChainArbitrumRinkeby(t *testing.T) config.ChainScopedConfig { return scoped func scopedConfig(t *testing.T, chainID int64) config.ChainScopedConfig { id := big.NewI(chainID) evmCfg := toml.EVMConfig{ChainID: id, Chain: toml.Defaults(id)} - return config.NewTOMLChainScopedConfig(configtest.NewTestGeneralConfig(t), &evmCfg, logger.TestLogger(t)) + return config.NewTOMLChainScopedConfig(&evmCfg, logger.TestLogger(t)) } diff --git a/core/services/blockhashstore/bhs_test.go b/core/services/blockhashstore/bhs_test.go index 94e9f22ee7c..b2e978293df 100644 --- a/core/services/blockhashstore/bhs_test.go +++ b/core/services/blockhashstore/bhs_test.go @@ -49,7 +49,7 @@ func TestStoreRotatesFromAddresses(t *testing.T) { require.NoError(t, err) bhs, err := blockhashstore.NewBulletproofBHS( chain.Config().EVM().GasEstimator(), - chain.Config().Database(), + cfg.Database(), fromAddresses, txm, store, diff --git a/core/services/blockhashstore/delegate.go b/core/services/blockhashstore/delegate.go index 243259a2b1a..3c5109f82c1 100644 --- a/core/services/blockhashstore/delegate.go +++ b/core/services/blockhashstore/delegate.go @@ -12,6 +12,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" + "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" v1 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/trusted_blockhash_store" @@ -25,8 +26,14 @@ import ( var _ job.ServiceCtx = &service{} +type Config interface { + Feature() config.Feature + Database() config.Database +} + // Delegate creates BlockhashStore feeder jobs. type Delegate struct { + cfg Config logger logger.Logger legacyChains legacyevm.LegacyChainContainer ks keystore.Eth @@ -34,11 +41,13 @@ type Delegate struct { // NewDelegate creates a new Delegate. func NewDelegate( + cfg Config, logger logger.Logger, legacyChains legacyevm.LegacyChainContainer, ks keystore.Eth, ) *Delegate { return &Delegate{ + cfg: cfg, logger: logger, legacyChains: legacyChains, ks: ks, @@ -68,7 +77,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) ([]job.Servi "getting chain ID %d: %w", jb.BlockhashStoreSpec.EVMChainID.ToInt(), err) } - if !chain.Config().Feature().LogPoller() { + if !d.cfg.Feature().LogPoller() { return nil, errors.New("log poller must be enabled to run blockhashstore") } @@ -151,7 +160,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) ([]job.Servi bpBHS, err := NewBulletproofBHS( chain.Config().EVM().GasEstimator(), - chain.Config().Database(), + d.cfg.Database(), fromAddresses, chain.TxManager(), bhs, diff --git a/core/services/blockhashstore/delegate_test.go b/core/services/blockhashstore/delegate_test.go index 6aaeb59152a..6bc93546605 100644 --- a/core/services/blockhashstore/delegate_test.go +++ b/core/services/blockhashstore/delegate_test.go @@ -33,7 +33,7 @@ func TestDelegate_JobType(t *testing.T) { t.Parallel() lggr := logger.TestLogger(t) - delegate := blockhashstore.NewDelegate(lggr, nil, nil) + delegate := blockhashstore.NewDelegate(nil, lggr, nil, nil) assert.Equal(t, job.BlockhashStore, delegate.JobType()) } @@ -72,7 +72,7 @@ func createTestDelegate(t *testing.T) (*blockhashstore.Delegate, *testData) { }, ) legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders) - return blockhashstore.NewDelegate(lggr, legacyChains, kst), &testData{ + return blockhashstore.NewDelegate(cfg, lggr, legacyChains, kst), &testData{ ethClient: ethClient, ethKeyStore: kst, legacyChains: legacyChains, diff --git a/core/services/blockheaderfeeder/delegate.go b/core/services/blockheaderfeeder/delegate.go index b750b735de8..d848ba7c61e 100644 --- a/core/services/blockheaderfeeder/delegate.go +++ b/core/services/blockheaderfeeder/delegate.go @@ -11,6 +11,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" + "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" v1 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" @@ -25,18 +26,26 @@ import ( var _ job.ServiceCtx = &service{} +type Config interface { + Feature() config.Feature + Database() config.Database +} + type Delegate struct { + cfg Config logger logger.Logger legacyChains legacyevm.LegacyChainContainer ks keystore.Eth } func NewDelegate( + cfg Config, logger logger.Logger, legacyChains legacyevm.LegacyChainContainer, ks keystore.Eth, ) *Delegate { return &Delegate{ + cfg: cfg, logger: logger, legacyChains: legacyChains, ks: ks, @@ -65,7 +74,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) ([]job.Servi "getting chain ID %d: %w", jb.BlockHeaderFeederSpec.EVMChainID.ToInt(), err) } - if !chain.Config().Feature().LogPoller() { + if !d.cfg.Feature().LogPoller() { return nil, errors.New("log poller must be enabled to run blockheaderfeeder") } @@ -144,7 +153,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) ([]job.Servi coordinators = append(coordinators, coord) } - bpBHS, err := blockhashstore.NewBulletproofBHS(chain.Config().EVM().GasEstimator(), chain.Config().Database(), fromAddresses, chain.TxManager(), bhs, nil, chain.ID(), d.ks) + bpBHS, err := blockhashstore.NewBulletproofBHS(chain.Config().EVM().GasEstimator(), d.cfg.Database(), fromAddresses, chain.TxManager(), bhs, nil, chain.ID(), d.ks) if err != nil { return nil, errors.Wrap(err, "building bulletproof bhs") } diff --git a/core/services/chainlink/application.go b/core/services/chainlink/application.go index 8542074c27c..88a6fadf345 100644 --- a/core/services/chainlink/application.go +++ b/core/services/chainlink/application.go @@ -333,6 +333,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) { legacyEVMChains, mailMon), job.Keeper: keeper.NewDelegate( + cfg, sqlxDB, jobORM, pipelineRunner, @@ -355,10 +356,12 @@ func NewApplication(opts ApplicationOpts) (Application, error) { pipelineRunner, globalLogger), job.BlockhashStore: blockhashstore.NewDelegate( + cfg, globalLogger, legacyEVMChains, keyStore.Eth()), job.BlockHeaderFeeder: blockheaderfeeder.NewDelegate( + cfg, globalLogger, legacyEVMChains, keyStore.Eth()), @@ -387,6 +390,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) { delegates[job.FluxMonitor] = &job.NullDelegate{Type: job.FluxMonitor} } else { delegates[job.FluxMonitor] = fluxmonitorv2.NewDelegate( + cfg, keyStore.Eth(), jobORM, pipelineORM, @@ -420,7 +424,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) { telemetryManager, legacyEVMChains, globalLogger, - cfg.Database(), + cfg, mailMon, ) } else { @@ -494,6 +498,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) { sqlxDB, jobSpawner, keyStore, + cfg, cfg.Insecure(), cfg.JobPipeline(), cfg.OCR(), diff --git a/core/services/feeds/config.go b/core/services/feeds/config.go index 141e4910960..e2ec889b23b 100644 --- a/core/services/feeds/config.go +++ b/core/services/feeds/config.go @@ -4,8 +4,14 @@ import ( "time" commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" + coreconfig "github.com/smartcontractkit/chainlink/v2/core/config" ) +type GeneralConfig interface { + OCR() coreconfig.OCR + Insecure() coreconfig.Insecure +} + type JobConfig interface { DefaultHTTPTimeout() commonconfig.Duration } @@ -25,5 +31,7 @@ type OCR2Config interface { ContractPollInterval() time.Duration ContractTransmitterTransmitTimeout() time.Duration DatabaseTimeout() time.Duration + DefaultTransactionQueueDepth() uint32 + SimulateTransactions() bool TraceLogging() bool } diff --git a/core/services/feeds/orm_test.go b/core/services/feeds/orm_test.go index 0cf20cf9800..3a0a17c99e0 100644 --- a/core/services/feeds/orm_test.go +++ b/core/services/feeds/orm_test.go @@ -1669,7 +1669,7 @@ func createJob(t *testing.T, db *sqlx.DB, externalJobID uuid.UUID) *job.Job { _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: externalJobID.String(), TransmitterAddress: address.Hex(), diff --git a/core/services/feeds/service.go b/core/services/feeds/service.go index 27d324d2342..8c4ea7a36bf 100644 --- a/core/services/feeds/service.go +++ b/core/services/feeds/service.go @@ -111,6 +111,7 @@ type service struct { ocr1KeyStore keystore.OCR ocr2KeyStore keystore.OCR2 jobSpawner job.Spawner + gCfg GeneralConfig insecureCfg InsecureConfig jobCfg JobConfig ocrCfg OCRConfig @@ -129,6 +130,7 @@ func NewService( db *sqlx.DB, jobSpawner job.Spawner, keyStore keystore.Master, + gCfg GeneralConfig, insecureCfg InsecureConfig, jobCfg JobConfig, ocrCfg OCRConfig, @@ -149,6 +151,7 @@ func NewService( csaKeyStore: keyStore.CSA(), ocr1KeyStore: keyStore.OCR(), ocr2KeyStore: keyStore.OCR2(), + gCfg: gCfg, insecureCfg: insecureCfg, jobCfg: jobCfg, ocrCfg: ocrCfg, @@ -1137,7 +1140,7 @@ func (s *service) generateJob(ctx context.Context, spec string) (*job.Job, error if !s.ocrCfg.Enabled() { return nil, ErrOCRDisabled } - js, err = ocr.ValidatedOracleSpecToml(s.legacyChains, spec) + js, err = ocr.ValidatedOracleSpecToml(s.gCfg, s.legacyChains, spec) case job.OffchainReporting2: if !s.ocr2cfg.Enabled() { return nil, ErrOCR2Disabled diff --git a/core/services/feeds/service_test.go b/core/services/feeds/service_test.go index 536584a0846..f83a98986e2 100644 --- a/core/services/feeds/service_test.go +++ b/core/services/feeds/service_test.go @@ -177,7 +177,6 @@ func setupTestServiceCfg(t *testing.T, overrideCfg func(c *chainlink.Config, s * db := pgtest.NewSqlxDB(t) gcfg := configtest.NewGeneralConfig(t, overrideCfg) keyStore := new(ksmocks.Master) - scopedConfig := evmtest.NewChainScopedConfig(t, gcfg) ethKeyStore := cltest.NewKeyStore(t, db).Eth() relayExtenders := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, GeneralConfig: gcfg, HeadTracker: headtracker.NullTracker, KeyStore: ethKeyStore}) @@ -187,7 +186,7 @@ func setupTestServiceCfg(t *testing.T, overrideCfg func(c *chainlink.Config, s * keyStore.On("P2P").Return(p2pKeystore) keyStore.On("OCR").Return(ocr1Keystore) keyStore.On("OCR2").Return(ocr2Keystore) - svc := feeds.NewService(orm, jobORM, db, spawner, keyStore, scopedConfig.Insecure(), scopedConfig.JobPipeline(), scopedConfig.OCR(), scopedConfig.OCR2(), scopedConfig.Database(), legacyChains, lggr, "1.0.0", nil) + svc := feeds.NewService(orm, jobORM, db, spawner, keyStore, gcfg, gcfg.Insecure(), gcfg.JobPipeline(), gcfg.OCR(), gcfg.OCR2(), gcfg.Database(), legacyChains, lggr, "1.0.0", nil) svc.SetConnectionsManager(connMgr) return &TestService{ diff --git a/core/services/fluxmonitorv2/delegate.go b/core/services/fluxmonitorv2/delegate.go index 72aa04c7201..b7b0df77cc4 100644 --- a/core/services/fluxmonitorv2/delegate.go +++ b/core/services/fluxmonitorv2/delegate.go @@ -10,14 +10,21 @@ import ( txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" + "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/keystore" "github.com/smartcontractkit/chainlink/v2/core/services/pipeline" ) +type DelegateConfig interface { + FluxMonitor() config.FluxMonitor + JobPipeline() config.JobPipeline +} + // Delegate represents a Flux Monitor delegate type Delegate struct { + cfg DelegateConfig db *sqlx.DB ethKeyStore keystore.Eth jobORM job.ORM @@ -31,6 +38,7 @@ var _ job.Delegate = (*Delegate)(nil) // NewDelegate constructs a new delegate func NewDelegate( + cfg DelegateConfig, ethKeyStore keystore.Eth, jobORM job.ORM, pipelineORM pipeline.ORM, @@ -40,6 +48,7 @@ func NewDelegate( lggr logger.Logger, ) *Delegate { return &Delegate{ + cfg: cfg, db: db, ethKeyStore: ethKeyStore, jobORM: jobORM, @@ -69,10 +78,9 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] if err != nil { return nil, err } - cfg := chain.Config() - strategy := txmgrcommon.NewQueueingTxStrategy(jb.ExternalJobID, cfg.FluxMonitor().DefaultTransactionQueueDepth()) + strategy := txmgrcommon.NewQueueingTxStrategy(jb.ExternalJobID, d.cfg.FluxMonitor().DefaultTransactionQueueDepth()) var checker txmgr.TransmitCheckerSpec - if chain.Config().FluxMonitor().SimulateTransactions() { + if d.cfg.FluxMonitor().SimulateTransactions() { checker.CheckerType = txmgr.TransmitCheckerTypeSimulate } @@ -88,7 +96,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] d.pipelineRunner, chain.Config().EVM(), chain.Config().EVM().GasEstimator(), - chain.Config().JobPipeline(), + d.cfg.JobPipeline(), d.lggr, ) if err != nil { diff --git a/core/services/job/helpers_test.go b/core/services/job/helpers_test.go index b35389ad4ad..22e1b0bef63 100644 --- a/core/services/job/helpers_test.go +++ b/core/services/job/helpers_test.go @@ -216,7 +216,7 @@ func makeMinimalHTTPOracleSpec(t *testing.T, db *sqlx.DB, cfg chainlink.GeneralC keyStore := cltest.NewKeyStore(t, db) relayExtenders := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, Client: evmtest.NewEthClientMockWithDefaultChain(t), GeneralConfig: cfg, KeyStore: keyStore.Eth()}) legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders) - _, err := ocr.ValidatedOracleSpecToml(legacyChains, s) + _, err := ocr.ValidatedOracleSpecToml(cfg, legacyChains, s) require.NoError(t, err) err = toml.Unmarshal([]byte(s), &os) require.NoError(t, err) diff --git a/core/services/job/job_orm_test.go b/core/services/job/job_orm_test.go index 3cd94735ca8..91018ef6f55 100644 --- a/core/services/job/job_orm_test.go +++ b/core/services/job/job_orm_test.go @@ -360,7 +360,7 @@ func TestORM_DeleteJob_DeletesAssociatedRecords(t *testing.T) { _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) relayExtenders := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, GeneralConfig: config, KeyStore: keyStore.Eth()}) legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ TransmitterAddress: address.Hex(), DS1BridgeName: bridge.Name.String(), DS2BridgeName: bridge2.Name.String(), @@ -765,7 +765,7 @@ func TestORM_CreateJob_OCR_DuplicatedContractAddress(t *testing.T) { }) relayExtenders := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, GeneralConfig: config, KeyStore: keyStore.Eth()}) legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, spec.Toml()) + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, spec.Toml()) require.NoError(t, err) t.Run("with a set chain id", func(t *testing.T) { @@ -777,7 +777,7 @@ func TestORM_CreateJob_OCR_DuplicatedContractAddress(t *testing.T) { externalJobID = uuid.NullUUID{UUID: uuid.New(), Valid: true} spec.JobID = externalJobID.UUID.String() - jba, err := ocr.ValidatedOracleSpecToml(legacyChains, spec.Toml()) + jba, err := ocr.ValidatedOracleSpecToml(config, legacyChains, spec.Toml()) require.NoError(t, err) err = jobORM.CreateJob(&jba) // Try to add duplicate job with default id require.Error(t, err) @@ -785,7 +785,7 @@ func TestORM_CreateJob_OCR_DuplicatedContractAddress(t *testing.T) { externalJobID = uuid.NullUUID{UUID: uuid.New(), Valid: true} spec.JobID = externalJobID.UUID.String() - jb2, err := ocr.ValidatedOracleSpecToml(legacyChains, spec.Toml()) + jb2, err := ocr.ValidatedOracleSpecToml(config, legacyChains, spec.Toml()) require.NoError(t, err) err = jobORM.CreateJob(&jb2) // Try to add duplicate job with custom id @@ -1007,7 +1007,7 @@ func Test_FindJobs(t *testing.T) { _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) relayExtenders := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, GeneralConfig: config, KeyStore: keyStore.Eth()}) legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders) - jb1, err := ocr.ValidatedOracleSpecToml(legacyChains, + jb1, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: uuid.New().String(), TransmitterAddress: address.Hex(), @@ -1092,7 +1092,7 @@ func Test_FindJob(t *testing.T) { _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) relayExtenders := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, GeneralConfig: config, KeyStore: keyStore.Eth()}) legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders) - job, err := ocr.ValidatedOracleSpecToml(legacyChains, + job, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: externalJobID.String(), Name: "orig ocr spec", @@ -1103,7 +1103,7 @@ func Test_FindJob(t *testing.T) { ) require.NoError(t, err) - jobSameAddress, err := ocr.ValidatedOracleSpecToml(legacyChains, + jobSameAddress, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: uuid.New().String(), TransmitterAddress: address.Hex(), @@ -1322,7 +1322,7 @@ func Test_FindPipelineRuns(t *testing.T) { externalJobID := uuid.New() _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: externalJobID.String(), TransmitterAddress: address.Hex(), @@ -1384,7 +1384,7 @@ func Test_PipelineRunsByJobID(t *testing.T) { externalJobID := uuid.New() _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: externalJobID.String(), TransmitterAddress: address.Hex(), @@ -1450,7 +1450,7 @@ func Test_FindPipelineRunIDsByJobID(t *testing.T) { key, err := ethkey.NewV2() require.NoError(t, err) - jb, err = ocr.ValidatedOracleSpecToml(legacyChains, + jb, err = ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: jobID, Name: fmt.Sprintf("Job #%v", jobID), @@ -1554,7 +1554,7 @@ func Test_FindPipelineRunsByIDs(t *testing.T) { externalJobID := uuid.New() _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: externalJobID.String(), TransmitterAddress: address.Hex(), @@ -1730,7 +1730,7 @@ func Test_CountPipelineRunsByJobID(t *testing.T) { externalJobID := uuid.New() _, address := cltest.MustInsertRandomKey(t, keyStore.Eth()) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, testspecs.GenerateOCRSpec(testspecs.OCRSpecParams{ JobID: externalJobID.String(), TransmitterAddress: address.Hex(), diff --git a/core/services/job/models.go b/core/services/job/models.go index 67b7b8b0bbe..8621d6cd5dd 100644 --- a/core/services/job/models.go +++ b/core/services/job/models.go @@ -327,6 +327,22 @@ func (r JSONConfig) MercuryCredentialName() (string, error) { return name, nil } +func (r JSONConfig) ApplyDefaultsOCR2(cfg ocr2Config) { + _, ok := r["defaultTransactionQueueDepth"] + if !ok { + r["defaultTransactionQueueDepth"] = cfg.DefaultTransactionQueueDepth() + } + _, ok = r["simulateTransactions"] + if !ok { + r["simulateTransactions"] = cfg.SimulateTransactions() + } +} + +type ocr2Config interface { + DefaultTransactionQueueDepth() uint32 + SimulateTransactions() bool +} + var ForwardersSupportedPlugins = []types.OCR2PluginType{types.Median, types.DKG, types.OCR2VRF, types.OCR2Keeper, types.Functions} // OCR2OracleSpec defines the job spec for OCR2 jobs. diff --git a/core/services/job/orm_test.go b/core/services/job/orm_test.go index 2e19669417a..fb0e846b9d2 100644 --- a/core/services/job/orm_test.go +++ b/core/services/job/orm_test.go @@ -34,13 +34,13 @@ func TestLoadConfigVarsLocalOCR(t *testing.T) { chainConfig := evmtest.NewChainScopedConfig(t, config) jobSpec := &job.OCROracleSpec{} - jobSpec = job.LoadConfigVarsLocalOCR(chainConfig.EVM().OCR(), *jobSpec, chainConfig.OCR()) + jobSpec = job.LoadConfigVarsLocalOCR(chainConfig.EVM().OCR(), *jobSpec, config.OCR()) - require.Equal(t, models.Interval(chainConfig.OCR().ObservationTimeout()), jobSpec.ObservationTimeout) - require.Equal(t, models.Interval(chainConfig.OCR().BlockchainTimeout()), jobSpec.BlockchainTimeout) - require.Equal(t, models.Interval(chainConfig.OCR().ContractSubscribeInterval()), jobSpec.ContractConfigTrackerSubscribeInterval) - require.Equal(t, models.Interval(chainConfig.OCR().ContractPollInterval()), jobSpec.ContractConfigTrackerPollInterval) - require.Equal(t, chainConfig.OCR().CaptureEATelemetry(), jobSpec.CaptureEATelemetry) + require.Equal(t, models.Interval(config.OCR().ObservationTimeout()), jobSpec.ObservationTimeout) + require.Equal(t, models.Interval(config.OCR().BlockchainTimeout()), jobSpec.BlockchainTimeout) + require.Equal(t, models.Interval(config.OCR().ContractSubscribeInterval()), jobSpec.ContractConfigTrackerSubscribeInterval) + require.Equal(t, models.Interval(config.OCR().ContractPollInterval()), jobSpec.ContractConfigTrackerPollInterval) + require.Equal(t, config.OCR().CaptureEATelemetry(), jobSpec.CaptureEATelemetry) require.Equal(t, chainConfig.EVM().OCR().ContractConfirmations(), jobSpec.ContractConfigConfirmations) require.Equal(t, models.Interval(chainConfig.EVM().OCR().DatabaseTimeout()), *jobSpec.DatabaseTimeout) diff --git a/core/services/job/runner_integration_test.go b/core/services/job/runner_integration_test.go index e13b1025b8b..26a78a8624e 100644 --- a/core/services/job/runner_integration_test.go +++ b/core/services/job/runner_integration_test.go @@ -198,7 +198,7 @@ func TestRunner(t *testing.T) { // Reference a different one legacyChains := cltest.NewLegacyChainsWithMockChain(t, nil, config) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, fmt.Sprintf(` + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, fmt.Sprintf(` type = "offchainreporting" schemaVersion = 1 evmChainID = 0 @@ -446,7 +446,7 @@ answer1 [type=median index=0]; evmChainID = "0" ` s = fmt.Sprintf(s, cltest.NewEIP55Address()) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, s) + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, s) require.NoError(t, err) err = toml.Unmarshal([]byte(s), &jb) require.NoError(t, err) @@ -468,7 +468,7 @@ answer1 [type=median index=0]; monitoringEndpoint, legacyChains, lggr, - config.Database(), + config, servicetest.Run(t, mailboxtest.NewMonitor(t)), ) _, err = sd.ServicesForSpec(testutils.Context(t), jb) @@ -481,7 +481,7 @@ answer1 [type=median index=0]; require.NoError(t, err) s := fmt.Sprintf(minimalNonBootstrapTemplate, cltest.NewEIP55Address(), transmitterAddress.Hex(), kb.ID(), "http://blah.com", "") - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, s) + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, s) require.NoError(t, err) err = toml.Unmarshal([]byte(s), &jb) require.NoError(t, err) @@ -503,7 +503,7 @@ answer1 [type=median index=0]; monitoringEndpoint, legacyChains, lggr, - config.Database(), + config, servicetest.Run(t, mailboxtest.NewMonitor(t)), ) _, err = sd.ServicesForSpec(testutils.Context(t), jb) @@ -512,7 +512,7 @@ answer1 [type=median index=0]; t.Run("test min bootstrap", func(t *testing.T) { s := fmt.Sprintf(minimalBootstrapTemplate, cltest.NewEIP55Address()) - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, s) + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, s) require.NoError(t, err) err = toml.Unmarshal([]byte(s), &jb) require.NoError(t, err) @@ -531,7 +531,7 @@ answer1 [type=median index=0]; monitoringEndpoint, legacyChains, lggr, - config.Database(), + config, servicetest.Run(t, mailboxtest.NewMonitor(t)), ) _, err = sd.ServicesForSpec(testutils.Context(t), jb) @@ -565,7 +565,7 @@ answer1 [type=median index=0]; require.NoError(t, err) s := fmt.Sprintf(minimalNonBootstrapTemplate, cltest.NewEIP55Address(), transmitterAddress.Hex(), kb.ID(), "http://blah.com", "") - jb, err := ocr.ValidatedOracleSpecToml(legacyChains, s) + jb, err := ocr.ValidatedOracleSpecToml(config, legacyChains, s) require.NoError(t, err) err = toml.Unmarshal([]byte(s), &jb) require.NoError(t, err) @@ -587,7 +587,7 @@ answer1 [type=median index=0]; monitoringEndpoint, legacyChains, lggr, - config.Database(), + config, servicetest.Run(t, mailboxtest.NewMonitor(t)), ) @@ -632,7 +632,7 @@ answer1 [type=median index=0]; monitoringEndpoint, legacyChains, lggr, - config.Database(), + config, servicetest.Run(t, mailboxtest.NewMonitor(t)), ) services, err := sd.ServicesForSpec(testutils.Context(t), *jb) diff --git a/core/services/job/spawner_test.go b/core/services/job/spawner_test.go index d3927da6590..5f4f933b9c3 100644 --- a/core/services/job/spawner_test.go +++ b/core/services/job/spawner_test.go @@ -132,7 +132,7 @@ func TestSpawner_CreateJobDeleteJob(t *testing.T) { serviceA1.On("Start", mock.Anything).Return(nil).Once() serviceA2.On("Start", mock.Anything).Return(nil).Once().Run(func(mock.Arguments) { eventuallyA.ItHappened() }) mailMon := servicetest.Run(t, mailboxtest.NewMonitor(t)) - dA := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config.Database(), mailMon) + dA := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config, mailMon) delegateA := &delegate{jobA.Type, []job.ServiceCtx{serviceA1, serviceA2}, 0, make(chan struct{}), dA} eventuallyB := cltest.NewAwaiter() @@ -140,7 +140,7 @@ func TestSpawner_CreateJobDeleteJob(t *testing.T) { serviceB2 := mocks.NewServiceCtx(t) serviceB1.On("Start", mock.Anything).Return(nil).Once() serviceB2.On("Start", mock.Anything).Return(nil).Once().Run(func(mock.Arguments) { eventuallyB.ItHappened() }) - dB := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config.Database(), mailMon) + dB := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config, mailMon) delegateB := &delegate{jobB.Type, []job.ServiceCtx{serviceB1, serviceB2}, 0, make(chan struct{}), dB} spawner := job.NewSpawner(orm, config.Database(), noopChecker{}, map[job.Type]job.Delegate{ @@ -191,7 +191,7 @@ func TestSpawner_CreateJobDeleteJob(t *testing.T) { lggr := logger.TestLogger(t) orm := NewTestORM(t, db, pipeline.NewORM(db, lggr, config.JobPipeline().MaxSuccessfulRuns()), bridges.NewORM(db), keyStore, config.Database()) mailMon := servicetest.Run(t, mailboxtest.NewMonitor(t)) - d := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config.Database(), mailMon) + d := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config, mailMon) delegateA := &delegate{jobA.Type, []job.ServiceCtx{serviceA1, serviceA2}, 0, nil, d} spawner := job.NewSpawner(orm, config.Database(), noopChecker{}, map[job.Type]job.Delegate{ jobA.Type: delegateA, @@ -225,7 +225,7 @@ func TestSpawner_CreateJobDeleteJob(t *testing.T) { lggr := logger.TestLogger(t) orm := NewTestORM(t, db, pipeline.NewORM(db, lggr, config.JobPipeline().MaxSuccessfulRuns()), bridges.NewORM(db), keyStore, config.Database()) mailMon := servicetest.Run(t, mailboxtest.NewMonitor(t)) - d := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config.Database(), mailMon) + d := ocr.NewDelegate(nil, orm, nil, nil, nil, monitoringEndpoint, legacyChains, logger.TestLogger(t), config, mailMon) delegateA := &delegate{jobA.Type, []job.ServiceCtx{serviceA1, serviceA2}, 0, nil, d} spawner := job.NewSpawner(orm, config.Database(), noopChecker{}, map[job.Type]job.Delegate{ jobA.Type: delegateA, diff --git a/core/services/keeper/delegate.go b/core/services/keeper/delegate.go index 9652434759b..184a61e1e1a 100644 --- a/core/services/keeper/delegate.go +++ b/core/services/keeper/delegate.go @@ -9,6 +9,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" + "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/pipeline" @@ -17,7 +18,12 @@ import ( // To make sure Delegate struct implements job.Delegate interface var _ job.Delegate = (*Delegate)(nil) +type DelegateConfig interface { + Keeper() config.Keeper +} + type Delegate struct { + cfg DelegateConfig logger logger.Logger db *sqlx.DB jrm job.ORM @@ -28,6 +34,7 @@ type Delegate struct { // NewDelegate is the constructor of Delegate func NewDelegate( + cfg DelegateConfig, db *sqlx.DB, jrm job.ORM, pr pipeline.Runner, @@ -36,6 +43,7 @@ func NewDelegate( mailMon *mailbox.Monitor, ) *Delegate { return &Delegate{ + cfg: cfg, logger: logger, db: db, jrm: jrm, @@ -94,7 +102,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services } } - keeper := chain.Config().Keeper() + keeper := d.cfg.Keeper() registry := keeper.Registry() registrySynchronizer := NewRegistrySynchronizer(RegistrySynchronizerOptions{ Job: spec, @@ -117,7 +125,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services chain.HeadBroadcaster(), chain.GasEstimator(), svcLogger, - chain.Config().Keeper(), + d.cfg.Keeper(), effectiveKeeperAddress, ) diff --git a/core/services/keeper/orm_test.go b/core/services/keeper/orm_test.go index 3d305f3e2b1..439970b381b 100644 --- a/core/services/keeper/orm_test.go +++ b/core/services/keeper/orm_test.go @@ -14,16 +14,15 @@ import ( "github.com/jmoiron/sqlx" - evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" evmutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" "github.com/smartcontractkit/chainlink/v2/core/logger" + "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/services/keeper" "github.com/smartcontractkit/chainlink/v2/core/utils" bigmath "github.com/smartcontractkit/chainlink/v2/core/utils/big_math" @@ -36,12 +35,11 @@ var ( func setupKeeperDB(t *testing.T) ( *sqlx.DB, - evmconfig.ChainScopedConfig, + chainlink.GeneralConfig, *keeper.ORM, ) { - gcfg := configtest.NewGeneralConfig(t, nil) + cfg := configtest.NewGeneralConfig(t, nil) db := pgtest.NewSqlxDB(t) - cfg := evmtest.NewChainScopedConfig(t, gcfg) orm := keeper.NewORM(db, logger.TestLogger(t)) return db, cfg, orm } diff --git a/core/services/keeper/upkeep_executer_test.go b/core/services/keeper/upkeep_executer_test.go index 33850ea7134..ec23331f904 100644 --- a/core/services/keeper/upkeep_executer_test.go +++ b/core/services/keeper/upkeep_executer_test.go @@ -89,7 +89,7 @@ func setup(t *testing.T, estimator gas.EvmFeeEstimator, overrideFn func(c *chain registry, jb := cltest.MustInsertKeeperRegistry(t, db, orm, keyStore.Eth(), 0, 1, 20) lggr := logger.TestLogger(t) - executer := keeper.NewUpkeepExecuter(jb, orm, jpv2.Pr, ethClient, ch.HeadBroadcaster(), ch.GasEstimator(), lggr, ch.Config().Keeper(), jb.KeeperSpec.FromAddress.Address()) + executer := keeper.NewUpkeepExecuter(jb, orm, jpv2.Pr, ethClient, ch.HeadBroadcaster(), ch.GasEstimator(), lggr, cfg.Keeper(), jb.KeeperSpec.FromAddress.Address()) upkeep := cltest.MustInsertUpkeepForRegistry(t, db, registry) servicetest.Run(t, executer) return db, cfg, ethClient, executer, registry, upkeep, jb, jpv2, txm, keyStore, ch, orm @@ -262,14 +262,14 @@ func Test_UpkeepExecuter_PerformsUpkeep_Happy(t *testing.T) { }) t.Run("errors if submission chain not found", func(t *testing.T) { - db, _, ethMock, _, _, _, _, jpv2, _, keyStore, ch, orm := setup(t, mockEstimator(t), nil) + db, cfg, ethMock, _, _, _, _, jpv2, _, keyStore, ch, orm := setup(t, mockEstimator(t), nil) registry, jb := cltest.MustInsertKeeperRegistry(t, db, orm, keyStore.Eth(), 0, 1, 20) // change chain ID to non-configured chain jb.KeeperSpec.EVMChainID = (*ubig.Big)(big.NewInt(999)) cltest.MustInsertUpkeepForRegistry(t, db, registry) lggr := logger.TestLogger(t) - executer := keeper.NewUpkeepExecuter(jb, orm, jpv2.Pr, ethMock, ch.HeadBroadcaster(), ch.GasEstimator(), lggr, ch.Config().Keeper(), jb.KeeperSpec.FromAddress.Address()) + executer := keeper.NewUpkeepExecuter(jb, orm, jpv2.Pr, ethMock, ch.HeadBroadcaster(), ch.GasEstimator(), lggr, cfg.Keeper(), jb.KeeperSpec.FromAddress.Address()) err := executer.Start(testutils.Context(t)) require.NoError(t, err) head := newHead() diff --git a/core/services/ocr/config.go b/core/services/ocr/config.go index 53ec9f9cea9..0dca9e83b3c 100644 --- a/core/services/ocr/config.go +++ b/core/services/ocr/config.go @@ -4,13 +4,15 @@ import ( ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types" evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" + "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/services/job" - "github.com/smartcontractkit/chainlink/v2/core/services/pg" ) // Config contains OCR configurations for a job. type Config interface { - pg.QConfig + Insecure() config.Insecure + JobPipeline() config.JobPipeline + OCR() config.OCR } func toLocalConfig(cfg ValidationConfig, evmOcrConfig evmconfig.OCR, insecureCfg insecureConfig, spec job.OCROracleSpec, ocrConfig job.OCRConfig) ocrtypes.LocalConfig { diff --git a/core/services/ocr/contract_tracker_test.go b/core/services/ocr/contract_tracker_test.go index 5473a2c924c..6f8b05c6436 100644 --- a/core/services/ocr/contract_tracker_test.go +++ b/core/services/ocr/contract_tracker_test.go @@ -20,7 +20,6 @@ import ( htmocks "github.com/smartcontractkit/chainlink/v2/common/headtracker/mocks" evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" - evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" logmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/log/mocks" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/offchain_aggregator_wrapper" @@ -55,13 +54,10 @@ type contractTrackerUni struct { } func newContractTrackerUni(t *testing.T, opts ...interface{}) (uni contractTrackerUni) { - var cfg evmconfig.ChainScopedConfig var filterer *offchainaggregator.OffchainAggregatorFilterer var contract *offchain_aggregator_wrapper.OffchainAggregator for _, opt := range opts { switch v := opt.(type) { - case evmconfig.ChainScopedConfig: - cfg = v case *offchainaggregator.OffchainAggregatorFilterer: filterer = v case *offchain_aggregator_wrapper.OffchainAggregator: @@ -70,9 +66,8 @@ func newContractTrackerUni(t *testing.T, opts ...interface{}) (uni contractTrack t.Fatalf("unrecognised option type %T", v) } } - if cfg == nil { - cfg = evmtest.NewChainScopedConfig(t, configtest.NewTestGeneralConfig(t)) - } + gcfg := configtest.NewTestGeneralConfig(t) + cfg := evmtest.NewChainScopedConfig(t, gcfg) if filterer == nil { filterer = mustNewFilterer(t) } diff --git a/core/services/ocr/delegate.go b/core/services/ocr/delegate.go index b16ede8089f..88561bd1c3a 100644 --- a/core/services/ocr/delegate.go +++ b/core/services/ocr/delegate.go @@ -12,13 +12,13 @@ import ( "github.com/jmoiron/sqlx" - commonlogger "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox" - "github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator" ocr "github.com/smartcontractkit/libocr/offchainreporting" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types" + commonlogger "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox" + txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" @@ -95,7 +95,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] if err != nil { return nil, err } - concreteSpec, err := job.LoadConfigVarsOCR(chain.Config().EVM().OCR(), chain.Config().OCR(), *jb.OCROracleSpec) + concreteSpec, err := job.LoadConfigVarsOCR(chain.Config().EVM().OCR(), d.cfg.OCR(), *jb.OCROracleSpec) if err != nil { return nil, err } @@ -156,11 +156,11 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] v2Bootstrappers = peerWrapper.P2PConfig().V2().DefaultBootstrappers() } - ocrLogger := commonlogger.NewOCRWrapper(lggr, chain.Config().OCR().TraceLogging(), func(msg string) { + ocrLogger := commonlogger.NewOCRWrapper(lggr, d.cfg.OCR().TraceLogging(), func(msg string) { d.jobORM.TryRecordError(jb.ID, msg) }) - lc := toLocalConfig(chain.Config().EVM(), chain.Config().EVM().OCR(), chain.Config().Insecure(), *concreteSpec, chain.Config().OCR()) + lc := toLocalConfig(chain.Config().EVM(), chain.Config().EVM().OCR(), d.cfg.Insecure(), *concreteSpec, d.cfg.OCR()) if err = ocr.SanityCheckLocalConfig(lc); err != nil { return nil, err } @@ -196,11 +196,10 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] return nil, errors.Wrap(err, "could not get contract ABI JSON") } - cfg := chain.Config() - strategy := txmgrcommon.NewQueueingTxStrategy(jb.ExternalJobID, cfg.OCR().DefaultTransactionQueueDepth()) + strategy := txmgrcommon.NewQueueingTxStrategy(jb.ExternalJobID, d.cfg.OCR().DefaultTransactionQueueDepth()) var checker txmgr.TransmitCheckerSpec - if chain.Config().OCR().SimulateTransactions() { + if d.cfg.OCR().SimulateTransactions() { checker.CheckerType = txmgr.TransmitCheckerTypeSimulate } @@ -254,8 +253,8 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] saver := ocrcommon.NewResultRunSaver( d.pipelineRunner, lggr, - cfg.JobPipeline().MaxSuccessfulRuns(), - cfg.JobPipeline().ResultWriteQueueDepth(), + d.cfg.JobPipeline().MaxSuccessfulRuns(), + d.cfg.JobPipeline().ResultWriteQueueDepth(), ) var configOverrider ocrtypes.ConfigOverrider @@ -277,7 +276,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] configOverrider = configOverriderService } - jb.OCROracleSpec.CaptureEATelemetry = chain.Config().OCR().CaptureEATelemetry() + jb.OCROracleSpec.CaptureEATelemetry = d.cfg.OCR().CaptureEATelemetry() enhancedTelemChan := make(chan ocrcommon.EnhancedTelemetryData, 100) if ocrcommon.ShouldCollectEnhancedTelemetry(&jb) { enhancedTelemService := ocrcommon.NewEnhancedTelemetryService(&jb, enhancedTelemChan, make(chan struct{}), d.monitoringEndpointGen.GenMonitoringEndpoint("EVM", chain.ID().String(), concreteSpec.ContractAddress.String(), synchronization.EnhancedEA), lggr.Named("EnhancedTelemetry")) diff --git a/core/services/ocr/validate.go b/core/services/ocr/validate.go index a0f2353eac1..a31994f891a 100644 --- a/core/services/ocr/validate.go +++ b/core/services/ocr/validate.go @@ -14,10 +14,16 @@ import ( evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" + coreconfig "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon" ) +type GeneralConfig interface { + OCR() coreconfig.OCR + Insecure() coreconfig.Insecure +} + type ValidationConfig interface { ChainType() config.ChainType } @@ -37,8 +43,8 @@ type insecureConfig interface { } // ValidatedOracleSpecToml validates an oracle spec that came from TOML -func ValidatedOracleSpecToml(legacyChains legacyevm.LegacyChainContainer, tomlString string) (job.Job, error) { - return ValidatedOracleSpecTomlCfg(func(id *big.Int) (evmconfig.ChainScopedConfig, error) { +func ValidatedOracleSpecToml(gcfg GeneralConfig, legacyChains legacyevm.LegacyChainContainer, tomlString string) (job.Job, error) { + return ValidatedOracleSpecTomlCfg(gcfg, func(id *big.Int) (evmconfig.ChainScopedConfig, error) { c, err := legacyChains.Get(id.String()) if err != nil { return nil, err @@ -47,7 +53,7 @@ func ValidatedOracleSpecToml(legacyChains legacyevm.LegacyChainContainer, tomlSt }, tomlString) } -func ValidatedOracleSpecTomlCfg(configFn func(id *big.Int) (evmconfig.ChainScopedConfig, error), tomlString string) (job.Job, error) { +func ValidatedOracleSpecTomlCfg(gcfg GeneralConfig, configFn func(id *big.Int) (evmconfig.ChainScopedConfig, error), tomlString string) (job.Job, error) { var jb = job.Job{} var spec job.OCROracleSpec tree, err := toml.Load(tomlString) @@ -94,10 +100,10 @@ func ValidatedOracleSpecTomlCfg(configFn func(id *big.Int) (evmconfig.ChainScope if err := validateBootstrapSpec(tree); err != nil { return jb, err } - } else if err := validateNonBootstrapSpec(tree, jb, cfg.OCR().ObservationTimeout()); err != nil { + } else if err := validateNonBootstrapSpec(tree, jb, gcfg.OCR().ObservationTimeout()); err != nil { return jb, err } - if err := validateTimingParameters(cfg.EVM(), cfg.EVM().OCR(), cfg.Insecure(), spec, cfg.OCR()); err != nil { + if err := validateTimingParameters(cfg.EVM(), cfg.EVM().OCR(), gcfg.Insecure(), spec, gcfg.OCR()); err != nil { return jb, err } return jb, nil diff --git a/core/services/ocr/validate_test.go b/core/services/ocr/validate_test.go index e55c5d1a484..6e68559d09d 100644 --- a/core/services/ocr/validate_test.go +++ b/core/services/ocr/validate_test.go @@ -373,7 +373,7 @@ answer1 [type=median index=0]; } }) - s, err := ocr.ValidatedOracleSpecTomlCfg(func(id *big.Int) (evmconfig.ChainScopedConfig, error) { + s, err := ocr.ValidatedOracleSpecTomlCfg(c, func(id *big.Int) (evmconfig.ChainScopedConfig, error) { return evmtest.NewChainScopedConfig(t, c), nil }, tc.toml) tc.assertion(t, s, err) diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index da6d6a1b6e7..22c655b6230 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -185,7 +185,9 @@ type ocr2Config interface { ContractPollInterval() time.Duration ContractTransmitterTransmitTimeout() time.Duration DatabaseTimeout() time.Duration + DefaultTransactionQueueDepth() uint32 KeyBundleID() (string, error) + SimulateTransactions() bool TraceLogging() bool CaptureAutomationCustomTelemetry() bool } @@ -399,6 +401,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) ([]job.Servi } } spec.RelayConfig["effectiveTransmitterID"] = effectiveTransmitterID + spec.RelayConfig.ApplyDefaultsOCR2(d.cfg.OCR2()) ocrDB := NewDB(d.db, spec.ID, 0, lggr, d.cfg.Database()) if d.peerWrapper == nil { diff --git a/core/services/ocr2/validate/config.go b/core/services/ocr2/validate/config.go index 0084a18308b..980933e7d97 100644 --- a/core/services/ocr2/validate/config.go +++ b/core/services/ocr2/validate/config.go @@ -19,6 +19,8 @@ type OCR2Config interface { ContractPollInterval() time.Duration ContractTransmitterTransmitTimeout() time.Duration DatabaseTimeout() time.Duration + DefaultTransactionQueueDepth() uint32 + SimulateTransactions() bool TraceLogging() bool } diff --git a/core/services/ocrbootstrap/delegate.go b/core/services/ocrbootstrap/delegate.go index 2d87cf80346..bd8f7765119 100644 --- a/core/services/ocrbootstrap/delegate.go +++ b/core/services/ocrbootstrap/delegate.go @@ -101,6 +101,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, jb job.Job) (services [] if spec.FeedID != nil { spec.RelayConfig["feedID"] = *spec.FeedID } + spec.RelayConfig.ApplyDefaultsOCR2(d.ocr2Cfg) ctxVals := loop.ContextValues{ JobID: jb.ID, diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 4f31110fda1..e9aaa7e0a8e 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -520,11 +520,10 @@ func newOnChainContractTransmitter(ctx context.Context, lggr logger.Logger, rarg if opts.subjectID != nil { subject = *opts.subjectID } - scoped := configWatcher.chain.Config() - strategy := txmgrcommon.NewQueueingTxStrategy(subject, scoped.OCR2().DefaultTransactionQueueDepth()) + strategy := txmgrcommon.NewQueueingTxStrategy(subject, relayConfig.DefaultTransactionQueueDepth) var checker txm.TransmitCheckerSpec - if configWatcher.chain.Config().OCR2().SimulateTransactions() { + if relayConfig.SimulateTransactions { checker.CheckerType = txm.TransmitCheckerTypeSimulate } diff --git a/core/services/relay/evm/functions.go b/core/services/relay/evm/functions.go index 9444ab4164d..f10874da149 100644 --- a/core/services/relay/evm/functions.go +++ b/core/services/relay/evm/functions.go @@ -182,11 +182,10 @@ func newFunctionsContractTransmitter(ctx context.Context, contractVersion uint32 fromAddresses = append(fromAddresses, common.HexToAddress(s)) } - scoped := configWatcher.chain.Config() - strategy := txmgrcommon.NewQueueingTxStrategy(rargs.ExternalJobID, scoped.OCR2().DefaultTransactionQueueDepth()) + strategy := txmgrcommon.NewQueueingTxStrategy(rargs.ExternalJobID, relayConfig.DefaultTransactionQueueDepth) var checker txm.TransmitCheckerSpec - if configWatcher.chain.Config().OCR2().SimulateTransactions() { + if relayConfig.SimulateTransactions { checker.CheckerType = txm.TransmitCheckerTypeSimulate } diff --git a/core/services/relay/evm/request_round_tracker_test.go b/core/services/relay/evm/request_round_tracker_test.go index 3421004ccf5..6af6c593a2b 100644 --- a/core/services/relay/evm/request_round_tracker_test.go +++ b/core/services/relay/evm/request_round_tracker_test.go @@ -17,7 +17,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" htmocks "github.com/smartcontractkit/chainlink/v2/common/headtracker/mocks" evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" - evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" logmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/log/mocks" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" @@ -53,13 +52,10 @@ type contractTrackerUni struct { } func newContractTrackerUni(t *testing.T, opts ...interface{}) (uni contractTrackerUni) { - var chain evmconfig.ChainScopedConfig var filterer *ocr2aggregator.OCR2AggregatorFilterer var contract *offchain_aggregator_wrapper.OffchainAggregator for _, opt := range opts { switch v := opt.(type) { - case evmconfig.ChainScopedConfig: - chain = v case *ocr2aggregator.OCR2AggregatorFilterer: filterer = v case *offchain_aggregator_wrapper.OffchainAggregator: @@ -68,9 +64,8 @@ func newContractTrackerUni(t *testing.T, opts ...interface{}) (uni contractTrack t.Fatalf("unrecognised option type %T", v) } } - if chain == nil { - chain = evmtest.NewChainScopedConfig(t, configtest.NewTestGeneralConfig(t)) - } + config := configtest.NewTestGeneralConfig(t) + chain := evmtest.NewChainScopedConfig(t, config) if filterer == nil { filterer = mustNewFilterer(t, testutils.NewAddress()) } diff --git a/core/services/relay/evm/types/types.go b/core/services/relay/evm/types/types.go index ea794262bd4..26e1c6f7128 100644 --- a/core/services/relay/evm/types/types.go +++ b/core/services/relay/evm/types/types.go @@ -113,6 +113,9 @@ type RelayConfig struct { ChainReader *ChainReaderConfig `json:"chainReader"` Codec *CodecConfig `json:"codec"` + DefaultTransactionQueueDepth uint32 `json:"defaultTransactionQueueDepth"` + SimulateTransactions bool `json:"simulateTransactions"` + // Contract-specific SendingKeys pq.StringArray `json:"sendingKeys"` diff --git a/core/web/jobs_controller.go b/core/web/jobs_controller.go index 5226d7dd7d6..0808422cca7 100644 --- a/core/web/jobs_controller.go +++ b/core/web/jobs_controller.go @@ -222,7 +222,7 @@ func (jc *JobsController) validateJobSpec(ctx context.Context, tomlString string config := jc.App.GetConfig() switch jobType { case job.OffchainReporting: - jb, err = ocr.ValidatedOracleSpecToml(jc.App.GetRelayers().LegacyEVMChains(), tomlString) + jb, err = ocr.ValidatedOracleSpecToml(config, jc.App.GetRelayers().LegacyEVMChains(), tomlString) if !config.OCR().Enabled() { return jb, http.StatusNotImplemented, errors.New("The Offchain Reporting feature is disabled by configuration") } diff --git a/core/web/resolver/mutation.go b/core/web/resolver/mutation.go index 9b0f5e50a03..9663f9dfe82 100644 --- a/core/web/resolver/mutation.go +++ b/core/web/resolver/mutation.go @@ -1019,7 +1019,7 @@ func (r *Resolver) CreateJob(ctx context.Context, args struct { config := r.App.GetConfig() switch jbt { case job.OffchainReporting: - jb, err = ocr.ValidatedOracleSpecToml(r.App.GetRelayers().LegacyEVMChains(), args.Input.TOML) + jb, err = ocr.ValidatedOracleSpecToml(config, r.App.GetRelayers().LegacyEVMChains(), args.Input.TOML) if !config.OCR().Enabled() { return nil, errors.New("The Offchain Reporting feature is disabled by configuration") }