Skip to content

Commit

Permalink
Move EVM config ocr and ocr2 (smartcontractkit#9606)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin authored Jun 16, 2023
1 parent 82ed1c0 commit 97071fb
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 157 deletions.
26 changes: 17 additions & 9 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,30 @@ type ChainScopedOnlyConfig interface {
OperatorFactoryAddress() string
MinIncomingConfirmations() uint32
MinimumContractPayment() *assets.Link

// OCR1 chain specific config
OCRContractConfirmations() uint16
OCRContractTransmitterTransmitTimeout() time.Duration
OCRObservationGracePeriod() time.Duration
OCRDatabaseTimeout() time.Duration

// OCR2 chain specific config
OCR2AutomationGasLimit() uint32
}

type EVM interface {
HeadTracker() HeadTracker
BalanceMonitor() BalanceMonitor
Transactions() Transactions
GasEstimator() GasEstimator
OCR() OCR
OCR2() OCR2
}

type OCR interface {
ContractConfirmations() uint16
ContractTransmitterTransmitTimeout() time.Duration
ObservationGracePeriod() time.Duration
DatabaseTimeout() time.Duration
}

type OCR2 interface {
Automation() OCR2Automation
}

type OCR2Automation interface {
GasLimit() uint32
}

type HeadTracker interface {
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ func TestChainScopedConfig_BSCDefaults(t *testing.T) {
})
cfg := evmtest.NewChainScopedConfig(t, gcfg)

timeout := cfg.OCRDatabaseTimeout()
timeout := cfg.EVM().OCR().DatabaseTimeout()
require.Equal(t, 2*time.Second, timeout)
timeout = cfg.OCRContractTransmitterTransmitTimeout()
timeout = cfg.EVM().OCR().ContractTransmitterTransmitTimeout()
require.Equal(t, 2*time.Second, timeout)
timeout = cfg.OCRObservationGracePeriod()
timeout = cfg.EVM().OCR().ObservationGracePeriod()
require.Equal(t, 500*time.Millisecond, timeout)
}

Expand Down
70 changes: 0 additions & 70 deletions core/chains/evm/config/mocks/chain_scoped_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 12 additions & 24 deletions core/chains/evm/config/v2/chain_scoped.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ 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.OCRContractConfirmations(),
ContractConfigConfirmations: c.EVM().OCR().ContractConfirmations(),
ContractConfigTrackerPollInterval: c.OCR().ContractPollInterval(),
ContractConfigTrackerSubscribeInterval: c.OCR().ContractSubscribeInterval(),
ContractTransmitterTransmitTimeout: c.OCRContractTransmitterTransmitTimeout(),
DatabaseTimeout: c.OCRDatabaseTimeout(),
ContractTransmitterTransmitTimeout: c.EVM().OCR().ContractTransmitterTransmitTimeout(),
DatabaseTimeout: c.EVM().OCR().DatabaseTimeout(),
DataSourceTimeout: c.OCR().ObservationTimeout(),
DataSourceGracePeriod: c.OCRObservationGracePeriod(),
DataSourceGracePeriod: c.EVM().OCR().ObservationGracePeriod(),
}
if ocrerr := ocr.SanityCheckLocalConfig(lc); ocrerr != nil {
err = multierr.Append(err, ocrerr)
Expand All @@ -73,6 +73,14 @@ func (e *evmConfig) HeadTracker() config.HeadTracker {
return &headTrackerConfig{c: e.c.HeadTracker}
}

func (e *evmConfig) OCR() config.OCR {
return &ocrConfig{c: e.c.OCR}
}

func (e *evmConfig) OCR2() config.OCR2 {
return &ocr2Config{c: e.c.OCR2}
}

func (e *evmConfig) GasEstimator() config.GasEstimator {
return &gasEstimatorConfig{c: e.c.GasEstimator, blockDelay: e.c.RPCBlockQueryDelay}
}
Expand Down Expand Up @@ -283,26 +291,6 @@ func (c *ChainScoped) NodeSyncThreshold() uint32 {
return *c.cfg.NodePool.SyncThreshold
}

func (c *ChainScoped) OCRContractConfirmations() uint16 {
return *c.cfg.OCR.ContractConfirmations
}

func (c *ChainScoped) OCRContractTransmitterTransmitTimeout() time.Duration {
return c.cfg.OCR.ContractTransmitterTransmitTimeout.Duration()
}

func (c *ChainScoped) OCRObservationGracePeriod() time.Duration {
return c.cfg.OCR.ObservationGracePeriod.Duration()
}

func (c *ChainScoped) OCRDatabaseTimeout() time.Duration {
return c.cfg.OCR.DatabaseTimeout.Duration()
}

func (c *ChainScoped) OCR2AutomationGasLimit() uint32 {
return *c.cfg.OCR2.Automation.GasLimit
}

type balanceMonitorConfig struct {
c BalanceMonitor
}
Expand Down
23 changes: 23 additions & 0 deletions core/chains/evm/config/v2/config_ocr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v2

import "time"

type ocrConfig struct {
c OCR
}

func (o *ocrConfig) ContractConfirmations() uint16 {
return *o.c.ContractConfirmations
}

func (o *ocrConfig) ContractTransmitterTransmitTimeout() time.Duration {
return o.c.ContractTransmitterTransmitTimeout.Duration()
}

func (o *ocrConfig) ObservationGracePeriod() time.Duration {
return o.c.ObservationGracePeriod.Duration()
}

func (o *ocrConfig) DatabaseTimeout() time.Duration {
return o.c.DatabaseTimeout.Duration()
}
23 changes: 23 additions & 0 deletions core/chains/evm/config/v2/config_ocr2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v2

import "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"

type ocr2Automation struct {
c Automation
}

func (o *ocr2Automation) GasLimit() uint32 {
return *o.c.GasLimit
}

type ocr2Config struct {
c OCR2
}

func (o *ocr2Config) Automation() config.OCR2Automation {
return &ocr2Automation{c: o.c.Automation}
}

func (o *ocr2Config) ContractConfirmations() uint16 {
return uint16(*o.c.Automation.GasLimit)
}
14 changes: 14 additions & 0 deletions core/chains/evm/config/v2/config_ocr2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package v2_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
)

func Test_ocr2Config(t *testing.T) {
evmOcrCfg := cltest.NewTestChainScopedConfig(t) //fallback.toml values
require.Equal(t, uint32(5300000), evmOcrCfg.EVM().OCR2().Automation().GasLimit())
}
17 changes: 17 additions & 0 deletions core/chains/evm/config/v2/config_ocr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v2_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
)

func Test_ocrConfig(t *testing.T) {
evmOcrCfg := cltest.NewTestChainScopedConfig(t) //fallback.toml values
require.Equal(t, uint16(4), evmOcrCfg.EVM().OCR().ContractConfirmations())
require.Equal(t, cltest.MustParseDuration(t, "10s"), evmOcrCfg.EVM().OCR().ContractTransmitterTransmitTimeout())
require.Equal(t, cltest.MustParseDuration(t, "10s"), evmOcrCfg.EVM().OCR().DatabaseTimeout())
require.Equal(t, cltest.MustParseDuration(t, "1s"), evmOcrCfg.EVM().OCR().ObservationGracePeriod())
}
24 changes: 9 additions & 15 deletions core/services/job/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/null"
Expand Down Expand Up @@ -653,7 +654,7 @@ func (o *orm) LoadEnvConfigVars(jb *Job) error {
if err != nil {
return err
}
newSpec, err := LoadEnvConfigVarsOCR(ch.Config(), ch.Config().OCR(), *jb.OCROracleSpec)
newSpec, err := LoadEnvConfigVarsOCR(ch.Config().EVM().OCR(), ch.Config().OCR(), *jb.OCROracleSpec)
if err != nil {
return err
}
Expand Down Expand Up @@ -698,13 +699,6 @@ func LoadEnvConfigVarsDR(cfg DRSpecConfig, drs DirectRequestSpec) *DirectRequest
return &drs
}

type OCRSpecConfig interface {
OCRContractConfirmations() uint16
OCRContractTransmitterTransmitTimeout() time.Duration
OCRDatabaseTimeout() time.Duration
OCRObservationGracePeriod() time.Duration
}

type OCRConfig interface {
BlockchainTimeout() time.Duration
CaptureEATelemetry() bool
Expand All @@ -716,7 +710,7 @@ type OCRConfig interface {
}

// LoadEnvConfigVarsLocalOCR loads local OCR env vars into the OCROracleSpec.
func LoadEnvConfigVarsLocalOCR(cfg OCRSpecConfig, os OCROracleSpec, ocrCfg OCRConfig) *OCROracleSpec {
func LoadEnvConfigVarsLocalOCR(evmOcrCfg evmconfig.OCR, os OCROracleSpec, ocrCfg OCRConfig) *OCROracleSpec {
if os.ObservationTimeout == 0 {
os.ObservationTimeoutEnv = true
os.ObservationTimeout = models.Interval(ocrCfg.ObservationTimeout())
Expand All @@ -735,27 +729,27 @@ func LoadEnvConfigVarsLocalOCR(cfg OCRSpecConfig, os OCROracleSpec, ocrCfg OCRCo
}
if os.ContractConfigConfirmations == 0 {
os.ContractConfigConfirmationsEnv = true
os.ContractConfigConfirmations = cfg.OCRContractConfirmations()
os.ContractConfigConfirmations = evmOcrCfg.ContractConfirmations()
}
if os.DatabaseTimeout == nil {
os.DatabaseTimeoutEnv = true
os.DatabaseTimeout = models.NewInterval(cfg.OCRDatabaseTimeout())
os.DatabaseTimeout = models.NewInterval(evmOcrCfg.DatabaseTimeout())
}
if os.ObservationGracePeriod == nil {
os.ObservationGracePeriodEnv = true
os.ObservationGracePeriod = models.NewInterval(cfg.OCRObservationGracePeriod())
os.ObservationGracePeriod = models.NewInterval(evmOcrCfg.ObservationGracePeriod())
}
if os.ContractTransmitterTransmitTimeout == nil {
os.ContractTransmitterTransmitTimeoutEnv = true
os.ContractTransmitterTransmitTimeout = models.NewInterval(cfg.OCRContractTransmitterTransmitTimeout())
os.ContractTransmitterTransmitTimeout = models.NewInterval(evmOcrCfg.ContractTransmitterTransmitTimeout())
}
os.CaptureEATelemetry = ocrCfg.CaptureEATelemetry()

return &os
}

// LoadEnvConfigVarsOCR loads OCR env vars into the OCROracleSpec.
func LoadEnvConfigVarsOCR(cfg OCRSpecConfig, ocrCfg OCRConfig, os OCROracleSpec) (*OCROracleSpec, error) {
func LoadEnvConfigVarsOCR(evmOcrCfg evmconfig.OCR, ocrCfg OCRConfig, os OCROracleSpec) (*OCROracleSpec, error) {
if os.TransmitterAddress == nil {
ta, err := ocrCfg.TransmitterAddress()
if !errors.Is(errors.Cause(err), config.ErrEnvUnset) {
Expand All @@ -780,7 +774,7 @@ func LoadEnvConfigVarsOCR(cfg OCRSpecConfig, ocrCfg OCRConfig, os OCROracleSpec)
os.EncryptedOCRKeyBundleID = &encryptedOCRKeyBundleID
}

return LoadEnvConfigVarsLocalOCR(cfg, os, ocrCfg), nil
return LoadEnvConfigVarsLocalOCR(evmOcrCfg, os, ocrCfg), nil
}

func (o *orm) FindJobTx(id int32) (Job, error) {
Expand Down
2 changes: 1 addition & 1 deletion core/services/job/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestLoadEnvConfigVarsLocalOCR(t *testing.T) {
chainConfig := evmtest.NewChainScopedConfig(t, config)
jobSpec := &job.OCROracleSpec{}

jobSpec = job.LoadEnvConfigVarsLocalOCR(chainConfig, *jobSpec, chainConfig.OCR())
jobSpec = job.LoadEnvConfigVarsLocalOCR(chainConfig.EVM().OCR(), *jobSpec, chainConfig.OCR())

require.True(t, jobSpec.ObservationTimeoutEnv)
require.True(t, jobSpec.BlockchainTimeoutEnv)
Expand Down
Loading

0 comments on commit 97071fb

Please sign in to comment.