Skip to content

Commit

Permalink
core/config: add EVM.OCR OverrideDeltaC and OverrideDeltaCJitter
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Nov 16, 2023
1 parent af2f919 commit 43bff4a
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 10 deletions.
8 changes: 8 additions & 0 deletions core/chains/evm/config/chain_scoped_ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ func (o *ocrConfig) ObservationGracePeriod() time.Duration {
func (o *ocrConfig) DatabaseTimeout() time.Duration {
return o.c.DatabaseTimeout.Duration()
}

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

func (o *ocrConfig) DeltaCJitterOverride() time.Duration {
return o.c.DeltaCJitterOverride.Duration()
}
2 changes: 2 additions & 0 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type OCR interface {
ContractTransmitterTransmitTimeout() time.Duration
ObservationGracePeriod() time.Duration
DatabaseTimeout() time.Duration
DeltaCOverride() time.Duration
DeltaCJitterOverride() time.Duration
}

type OCR2 interface {
Expand Down
11 changes: 10 additions & 1 deletion core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,10 @@ type OCR struct {
ContractConfirmations *uint16
ContractTransmitterTransmitTimeout *models.Duration
DatabaseTimeout *models.Duration
ObservationGracePeriod *models.Duration
//TODO validate
DeltaCOverride *models.Duration
DeltaCJitterOverride *models.Duration
ObservationGracePeriod *models.Duration
}

func (o *OCR) setFrom(f *OCR) {
Expand All @@ -727,6 +730,12 @@ func (o *OCR) setFrom(f *OCR) {
if v := f.DatabaseTimeout; v != nil {
o.DatabaseTimeout = v
}
if v := f.DeltaCOverride; v != nil {
o.DeltaCOverride = v
}
if v := f.DeltaCJitterOverride; v != nil {
o.DeltaCJitterOverride = v
}
if v := f.ObservationGracePeriod; v != nil {
o.ObservationGracePeriod = v
}
Expand Down
2 changes: 2 additions & 0 deletions core/chains/evm/config/toml/defaults/fallback.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ LeaseDuration = '0s'
ContractConfirmations = 4
ContractTransmitterTransmitTimeout = '10s'
DatabaseTimeout = '10s'
DeltaCOverride = '168h'
DeltaCJitterOverride = '1h'
ObservationGracePeriod = '1s'

[OCR2.Automation]
Expand Down
4 changes: 4 additions & 0 deletions core/config/docs/chains-evm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ ContractConfirmations = 4 # Default
ContractTransmitterTransmitTimeout = '10s' # Default
# DatabaseTimeout sets `OCR.DatabaseTimeout` for this EVM chain.
DatabaseTimeout = '10s' # Default
# DeltaCOverride TODO Default is 168h (7 days).
DeltaCOverride = "168h" # Default
# DeltaCJitterOverride TODO
DeltaCJitterOverride = "1h" # Default
# ObservationGracePeriod sets `OCR.ObservationGracePeriod` for this EVM chain.
ObservationGracePeriod = '1s' # Default

Expand Down
4 changes: 4 additions & 0 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ func TestConfig_Marshal(t *testing.T) {
ContractConfirmations: ptr[uint16](11),
ContractTransmitterTransmitTimeout: &minute,
DatabaseTimeout: &second,
DeltaCOverride: models.MustNewDuration(time.Hour),
DeltaCJitterOverride: models.MustNewDuration(time.Second),
ObservationGracePeriod: &second,
},
OCR2: evmcfg.OCR2{
Expand Down Expand Up @@ -1007,6 +1009,8 @@ LeaseDuration = '0s'
ContractConfirmations = 11
ContractTransmitterTransmitTimeout = '1m0s'
DatabaseTimeout = '1s'
DeltaCOverride = '1h0m0s'
DeltaCJitterOverride = '1s'
ObservationGracePeriod = '1s'
[EVM.OCR2]
Expand Down
2 changes: 2 additions & 0 deletions core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ LeaseDuration = '0s'
ContractConfirmations = 11
ContractTransmitterTransmitTimeout = '1m0s'
DatabaseTimeout = '1s'
DeltaCOverride = '1h0m0s'
DeltaCJitterOverride = '1s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ LeaseDuration = '0s'
ContractConfirmations = 4
ContractTransmitterTransmitTimeout = '10s'
DatabaseTimeout = '10s'
DeltaCOverride = '168h0m0s'
DeltaCJitterOverride = '1h0m0s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down Expand Up @@ -388,6 +390,8 @@ LeaseDuration = '0s'
ContractConfirmations = 4
ContractTransmitterTransmitTimeout = '10s'
DatabaseTimeout = '10s'
DeltaCOverride = '168h0m0s'
DeltaCJitterOverride = '1h0m0s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down Expand Up @@ -467,6 +471,8 @@ LeaseDuration = '0s'
ContractConfirmations = 4
ContractTransmitterTransmitTimeout = '10s'
DatabaseTimeout = '10s'
DeltaCOverride = '168h0m0s'
DeltaCJitterOverride = '1h0m0s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down
12 changes: 10 additions & 2 deletions core/services/ocr/config_overrider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types"

"github.com/smartcontractkit/chainlink-relay/pkg/services"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/utils"
Expand Down Expand Up @@ -40,8 +41,14 @@ type ConfigOverriderImpl struct {
// InitialHibernationStatus - hibernation state set until the first successful update from the chain
const InitialHibernationStatus = false

type DeltaCConfig interface {
DeltaCOverride() time.Duration
DeltaCJitterOverride() time.Duration
}

func NewConfigOverriderImpl(
logger logger.Logger,
cfg DeltaCConfig,
contractAddress ethkey.EIP55Address,
flags *ContractFlags,
pollTicker utils.TickerBase,
Expand All @@ -53,8 +60,9 @@ func NewConfigOverriderImpl(
}

addressBig := contractAddress.Big()
addressSeconds := addressBig.Mod(addressBig, big.NewInt(3600)).Uint64()
deltaC := 23*time.Hour + time.Duration(addressSeconds)*time.Second
jitterSeconds := int64(cfg.DeltaCJitterOverride() / time.Second)
addressSeconds := addressBig.Mod(addressBig, big.NewInt(jitterSeconds)).Uint64()
deltaC := cfg.DeltaCOverride() + time.Duration(addressSeconds)*time.Second

ctx, cancel := context.WithCancel(context.Background())
co := ConfigOverriderImpl{
Expand Down
21 changes: 15 additions & 6 deletions core/services/ocr/config_overrider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

Expand All @@ -27,6 +28,12 @@ type configOverriderUni struct {
contractAddress ethkey.EIP55Address
}

type deltaCConfig struct{}

func (d deltaCConfig) DeltaCOverride() time.Duration { return time.Hour * 24 * 7 }

func (d deltaCConfig) DeltaCJitterOverride() time.Duration { return time.Hour }

func newConfigOverriderUni(t *testing.T, pollITicker utils.TickerBase, flagsContract *mocks.Flags) (uni configOverriderUni) {
var testLogger = logger.TestLogger(t)
contractAddress := cltest.NewEIP55Address()
Expand All @@ -35,6 +42,7 @@ func newConfigOverriderUni(t *testing.T, pollITicker utils.TickerBase, flagsCont
var err error
uni.overrider, err = ocr.NewConfigOverriderImpl(
testLogger,
deltaCConfig{},
contractAddress,
flags,
pollITicker,
Expand Down Expand Up @@ -141,6 +149,7 @@ func Test_OCRConfigOverrider(t *testing.T) {
flags := &ocr.ContractFlags{FlagsInterface: nil}
_, err := ocr.NewConfigOverriderImpl(
testLogger,
deltaCConfig{},
contractAddress,
flags,
nil,
Expand All @@ -160,18 +169,18 @@ func Test_OCRConfigOverrider(t *testing.T) {
address2, err := ethkey.NewEIP55Address(common.BigToAddress(big.NewInt(1234567890)).Hex())
require.NoError(t, err)

overrider1a, err := ocr.NewConfigOverriderImpl(testLogger, address1, flags, nil)
overrider1a, err := ocr.NewConfigOverriderImpl(testLogger, deltaCConfig{}, address1, flags, nil)
require.NoError(t, err)

overrider1b, err := ocr.NewConfigOverriderImpl(testLogger, address1, flags, nil)
overrider1b, err := ocr.NewConfigOverriderImpl(testLogger, deltaCConfig{}, address1, flags, nil)
require.NoError(t, err)

overrider2, err := ocr.NewConfigOverriderImpl(testLogger, address2, flags, nil)
overrider2, err := ocr.NewConfigOverriderImpl(testLogger, deltaCConfig{}, address2, flags, nil)
require.NoError(t, err)

require.Equal(t, overrider1a.DeltaCFromAddress, time.Duration(85600000000000))
require.Equal(t, overrider1b.DeltaCFromAddress, time.Duration(85600000000000))
require.Equal(t, overrider2.DeltaCFromAddress, time.Duration(84690000000000))
assert.Equal(t, cltest.MustParseDuration(t, "168h46m40s"), overrider1a.DeltaCFromAddress)
assert.Equal(t, cltest.MustParseDuration(t, "168h46m40s"), overrider1b.DeltaCFromAddress)
assert.Equal(t, cltest.MustParseDuration(t, "168h31m30s"), overrider2.DeltaCFromAddress)
})
}

Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (d *Delegate) maybeCreateConfigOverrider(logger logger.Logger, chain evm.Ch
}

ticker := utils.NewPausableTicker(ConfigOverriderPollInterval)
return NewConfigOverriderImpl(logger, contractAddress, flags, &ticker)
return NewConfigOverriderImpl(logger, chain.Config().EVM().OCR(), contractAddress, flags, &ticker)
}
return nil, nil
}
2 changes: 2 additions & 0 deletions core/web/resolver/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ LeaseDuration = '0s'
ContractConfirmations = 11
ContractTransmitterTransmitTimeout = '1m0s'
DatabaseTimeout = '1s'
DeltaCOverride = '1h0m0s'
DeltaCJitterOverride = '1s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down
6 changes: 6 additions & 0 deletions core/web/resolver/testdata/config-multi-chain-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ LeaseDuration = '0s'
ContractConfirmations = 4
ContractTransmitterTransmitTimeout = '10s'
DatabaseTimeout = '10s'
DeltaCOverride = '168h0m0s'
DeltaCJitterOverride = '1h0m0s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down Expand Up @@ -388,6 +390,8 @@ LeaseDuration = '0s'
ContractConfirmations = 4
ContractTransmitterTransmitTimeout = '10s'
DatabaseTimeout = '10s'
DeltaCOverride = '168h0m0s'
DeltaCJitterOverride = '1h0m0s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down Expand Up @@ -467,6 +471,8 @@ LeaseDuration = '0s'
ContractConfirmations = 4
ContractTransmitterTransmitTimeout = '10s'
DatabaseTimeout = '10s'
DeltaCOverride = '168h0m0s'
DeltaCJitterOverride = '1h0m0s'
ObservationGracePeriod = '1s'

[EVM.OCR2]
Expand Down
Loading

0 comments on commit 43bff4a

Please sign in to comment.