Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick: enable jpfc cache by default #12973

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Enable jpfc cache by default (#12966)
* Draft

* Check JuelsPerFeeCoinCache before checking Disable param

* Add test

* Update NewInMemoryDataSourceCache

* Update NewInMemoryDataSourceCache
  • Loading branch information
george-dorin committed Apr 25, 2024
commit 12007626ab55831ea446e4a3c7d452a942cb19fa
5 changes: 5 additions & 0 deletions .changeset/warm-impalas-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#added JuelsPerFeeCoinCache is enabled by default for OCR2 jobs, added `Disable` field under [pluginConfig.JuelsPerFeeCoinCache] tag to disable this feature (e.g. Disable=true)
1 change: 1 addition & 0 deletions core/services/ocr2/plugins/median/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type PluginConfig struct {
}

type JuelsPerFeeCoinCache struct {
Disable bool `json:"disable"`
UpdateInterval models.Interval `json:"updateInterval"`
StalenessAlertThreshold models.Interval `json:"stalenessAlertThreshold"`
}
Expand Down
5 changes: 2 additions & 3 deletions core/services/ocr2/plugins/median/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-feeds/median"

"github.com/smartcontractkit/chainlink/v2/core/config/env"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services"
Expand Down Expand Up @@ -127,9 +126,9 @@ func NewMedianServices(ctx context.Context,
CreatedAt: time.Now(),
}, lggr)

if pluginConfig.JuelsPerFeeCoinCache != nil {
if pluginConfig.JuelsPerFeeCoinCache == nil || (pluginConfig.JuelsPerFeeCoinCache != nil && !pluginConfig.JuelsPerFeeCoinCache.Disable) {
lggr.Infof("juelsPerFeeCoin data source caching is enabled")
juelsPerFeeCoinSourceCache, err2 := ocrcommon.NewInMemoryDataSourceCache(juelsPerFeeCoinSource, kvStore, *pluginConfig.JuelsPerFeeCoinCache)
juelsPerFeeCoinSourceCache, err2 := ocrcommon.NewInMemoryDataSourceCache(juelsPerFeeCoinSource, kvStore, pluginConfig.JuelsPerFeeCoinCache)
if err2 != nil {
return nil, err2
}
Expand Down
41 changes: 41 additions & 0 deletions core/services/ocr2/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,47 @@ Command="some random command"
require.Error(t, err)
require.ErrorContains(t, err, "failed to find binary")
},
}, {
name: "minimal OCR2 oracle spec with JuelsPerFeeCoinCache",
toml: `
type = "offchainreporting2"
pluginType = "median"
schemaVersion = 1
relay = "evm"
contractID = "0x613a38AC1659769640aaE063C651F48E0250454C"
observationSource = """
ds1 [type=bridge name=voter_turnout];
ds1_parse [type=jsonparse path="one,two"];
ds1_multiply [type=multiply times=1.23];
ds1 -> ds1_parse -> ds1_multiply -> answer1;
answer1 [type=median index=0];
"""
[relayConfig]
chainID = 1337
[pluginConfig]
juelsPerFeeCoinSource = """
ds1 [type=bridge name=voter_turnout];
ds1_parse [type=jsonparse path="one,two"];
ds1_multiply [type=multiply times=1.23];
ds1 -> ds1_parse -> ds1_multiply -> answer1;
answer1 [type=median index=0];
"""
[pluginConfig.JuelsPerFeeCoinCache]
Disable=false
UpdateInterval="1m"
`,
assertion: func(t *testing.T, os job.Job, err error) {
require.NoError(t, err)
b, err := jsonapi.Marshal(os.OCR2OracleSpec)
require.NoError(t, err)
var r job.OCR2OracleSpec
err = jsonapi.Unmarshal(b, &r)
require.NoError(t, err)
assert.Equal(t, "median", string(r.PluginType))
var pc medianconfig.PluginConfig
require.NoError(t, json.Unmarshal(r.PluginConfig.Bytes(), &pc))
require.NoError(t, medianconfig.ValidatePluginConfig(pc))
},
},
}

Expand Down
17 changes: 11 additions & 6 deletions core/services/ocrcommon/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,23 @@ type DataSourceCacheService interface {
median.DataSource
}

func NewInMemoryDataSourceCache(ds median.DataSource, kvStore job.KVStore, cacheCfg config.JuelsPerFeeCoinCache) (DataSourceCacheService, error) {
func NewInMemoryDataSourceCache(ds median.DataSource, kvStore job.KVStore, cacheCfg *config.JuelsPerFeeCoinCache) (DataSourceCacheService, error) {
inMemoryDS, ok := ds.(*inMemoryDataSource)
if !ok {
return nil, errors.Errorf("unsupported data source type: %T, only inMemoryDataSource supported", ds)
}

updateInterval, stalenessAlertThreshold := cacheCfg.UpdateInterval.Duration(), cacheCfg.StalenessAlertThreshold.Duration()
if updateInterval == 0 {
var updateInterval, stalenessAlertThreshold time.Duration
if cacheCfg == nil {
updateInterval = defaultUpdateInterval
}
if stalenessAlertThreshold == 0 {
stalenessAlertThreshold = defaultStalenessAlertThreshold
} else {
updateInterval, stalenessAlertThreshold = cacheCfg.UpdateInterval.Duration(), cacheCfg.StalenessAlertThreshold.Duration()
if updateInterval == 0 {
updateInterval = defaultUpdateInterval
}
if stalenessAlertThreshold == 0 {
stalenessAlertThreshold = defaultStalenessAlertThreshold
}
}

dsCache := &inMemoryDataSourceCache{
Expand Down
6 changes: 3 additions & 3 deletions core/services/ocrcommon/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Test_CachedInMemoryDataSourceErrHandling(t *testing.T) {
mockKVStore := mocks.KVStore{}
mockKVStore.On("Store", mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockKVStore.On("Get", mock.Anything, mock.Anything).Return(nil, nil)
dsCache, err := ocrcommon.NewInMemoryDataSourceCache(ds, &mockKVStore, config.JuelsPerFeeCoinCache{UpdateInterval: models.Interval(time.Second * 2)})
dsCache, err := ocrcommon.NewInMemoryDataSourceCache(ds, &mockKVStore, &config.JuelsPerFeeCoinCache{UpdateInterval: models.Interval(time.Second * 2)})
require.NoError(t, err)
servicetest.Run(t, dsCache)

Expand Down Expand Up @@ -114,7 +114,7 @@ func Test_CachedInMemoryDataSourceErrHandling(t *testing.T) {
mockKVStore.On("Get", mock.Anything, mock.Anything).Return(result, nil)

// set updater to a long time so that it doesn't log errors after the test is done
dsCache, err := ocrcommon.NewInMemoryDataSourceCache(ds, &mockKVStore, config.JuelsPerFeeCoinCache{UpdateInterval: models.Interval(time.Hour * 100)})
dsCache, err := ocrcommon.NewInMemoryDataSourceCache(ds, &mockKVStore, &config.JuelsPerFeeCoinCache{UpdateInterval: models.Interval(time.Hour * 100)})
require.NoError(t, err)
changeResultValue(runner, "-1", true, false)
servicetest.Run(t, dsCache)
Expand All @@ -133,7 +133,7 @@ func Test_CachedInMemoryDataSourceErrHandling(t *testing.T) {
mockKVStore.On("Get", mock.Anything, mock.Anything).Return(nil, assert.AnError)

// set updater to a long time so that it doesn't log errors after the test is done
dsCache, err := ocrcommon.NewInMemoryDataSourceCache(ds, &mockKVStore, config.JuelsPerFeeCoinCache{UpdateInterval: models.Interval(time.Hour * 100)})
dsCache, err := ocrcommon.NewInMemoryDataSourceCache(ds, &mockKVStore, &config.JuelsPerFeeCoinCache{UpdateInterval: models.Interval(time.Hour * 100)})
require.NoError(t, err)
changeResultValue(runner, "-1", true, false)
servicetest.Run(t, dsCache)
Expand Down
Loading