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

Added check to not fetch mercury prices when trigger capability is enabled #13888

Merged
merged 23 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8183dfc
add check to not fetch mercury prices when trigger capability is enabled
karen-stepanyan Jul 18, 2024
5e5cab3
changeset
karen-stepanyan Jul 18, 2024
96bb990
fix lint issues
karen-stepanyan Jul 18, 2024
9d98ced
address PR comments
karen-stepanyan Jul 18, 2024
5bfc247
Merge branch 'develop' into feature/DF-20169
austinborn Jul 18, 2024
bd24a23
Merge branch 'develop' into feature/DF-20169
austinborn Sep 15, 2024
189cc9a
Ensure pluginConfig can be omitted for keystone Streams jobs
austinborn Sep 16, 2024
2c36639
Add capability flag check for Mercury V2 jobs
austinborn Sep 16, 2024
3a4e98f
Update V2 spec tests
austinborn Sep 16, 2024
13c9175
Merge branch 'develop' into feature/DF-20169
austinborn Sep 16, 2024
150b24b
Linting fixes
austinborn Sep 16, 2024
40b94b5
Remove changes for Mercury v2 schema
austinborn Sep 16, 2024
088b84a
Merge branch 'develop' into feature/DF-20169
austinborn Sep 16, 2024
2820f3f
Merge branch 'develop' into feature/DF-20169
austinborn Sep 16, 2024
6d3a5af
Update linkFeedId and nativeFeedId checks without enableTriggerCapabi…
austinborn Sep 16, 2024
104a308
Update .changeset/wise-bears-end.md
austinborn Sep 16, 2024
e7df7fd
Remove inaccurate comments
austinborn Sep 16, 2024
1e51ffd
Add PluginConfig!=nil check to Mercury v2 schema
austinborn Sep 16, 2024
1b7d581
Linting fix
austinborn Sep 16, 2024
439f065
Update mercury v2 tests
austinborn Sep 16, 2024
473261e
Merge branch 'develop' into feature/DF-20169
austinborn Sep 16, 2024
1cb7a45
Set price feeds to -1 if plugin config is nil
austinborn Sep 17, 2024
eda8db2
Add base pluginConfig to test_dataSource files
austinborn Sep 17, 2024
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
5 changes: 5 additions & 0 deletions .changeset/wise-bears-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#updated v3/data_source Observe method to skip calling LatestPrice when EnableTriggerCapability relay config is true
austinborn marked this conversation as resolved.
Show resolved Hide resolved
Empty file modified core/services/job/validate_test.go
100644 → 100755
Empty file.
26 changes: 20 additions & 6 deletions core/services/ocr2/plugins/mercury/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
mercuryv2 "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v2"
mercuryv3 "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v3"
mercuryv4 "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v4"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
"github.com/smartcontractkit/chainlink/v2/plugins"
)

Expand Down Expand Up @@ -78,15 +79,28 @@ func NewServices(
return nil, errors.New("expected job to have a non-nil PipelineSpec")
}

var pluginConfig config.PluginConfig
err := json.Unmarshal(jb.OCR2OracleSpec.PluginConfig.Bytes(), &pluginConfig)
var relayConfig evmtypes.RelayConfig
err := json.Unmarshal(jb.OCR2OracleSpec.RelayConfig.Bytes(), &relayConfig)
if err != nil {
return nil, errors.WithStack(err)
return nil, fmt.Errorf("error while unmarshalling relay config: %w", err)
}
err = config.ValidatePluginConfig(pluginConfig, feedID)
if err != nil {
return nil, err

var pluginConfig config.PluginConfig
if jb.OCR2OracleSpec.PluginConfig == nil {
if !relayConfig.EnableTriggerCapability {
return nil, fmt.Errorf("at least one transmission option must be configured")
}
} else {
err = json.Unmarshal(jb.OCR2OracleSpec.PluginConfig.Bytes(), &pluginConfig)
if err != nil {
return nil, errors.WithStack(err)
}
err = config.ValidatePluginConfig(pluginConfig, feedID)
if err != nil {
return nil, err
}
}

lggr = lggr.Named("MercuryPlugin").With("jobID", jb.ID, "jobName", jb.Name.ValueOrZero())

// encapsulate all the subservices and ensure we close them all if any fail to start
Expand Down
23 changes: 18 additions & 5 deletions core/services/ocr2/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
"github.com/smartcontractkit/chainlink/v2/plugins"
)

Expand Down Expand Up @@ -84,7 +85,6 @@ var (
"relay": {},
"relayConfig": {},
"pluginType": {},
"pluginConfig": {},
}
notExpectedParams = map[string]struct{}{
"isBootstrapPeer": {},
Expand Down Expand Up @@ -117,7 +117,7 @@ func validateSpec(ctx context.Context, tree *toml.Tree, spec job.Job, rc plugins
// TODO validator for DR-OCR spec: https://smartcontract-it.atlassian.net/browse/FUN-112
return nil
case types.Mercury:
return validateOCR2MercurySpec(spec.OCR2OracleSpec.PluginConfig, *spec.OCR2OracleSpec.FeedID)
return validateOCR2MercurySpec(spec.OCR2OracleSpec, *spec.OCR2OracleSpec.FeedID)
case types.CCIPExecution:
return validateOCR2CCIPExecutionSpec(spec.OCR2OracleSpec.PluginConfig)
case types.CCIPCommit:
Expand Down Expand Up @@ -297,13 +297,26 @@ func validateOCR2KeeperSpec(jsonConfig job.JSONConfig) error {
return nil
}

func validateOCR2MercurySpec(jsonConfig job.JSONConfig, feedId [32]byte) error {
func validateOCR2MercurySpec(spec *job.OCR2OracleSpec, feedID [32]byte) error {
var relayConfig evmtypes.RelayConfig
err := json.Unmarshal(spec.RelayConfig.Bytes(), &relayConfig)
if err != nil {
return pkgerrors.Wrap(err, "error while unmarshalling relay config")
}

if spec.PluginConfig == nil {
if !relayConfig.EnableTriggerCapability {
return pkgerrors.Wrap(err, "at least one transmission option must be configured")
}
return nil
}

var pluginConfig mercuryconfig.PluginConfig
err := json.Unmarshal(jsonConfig.Bytes(), &pluginConfig)
err = json.Unmarshal(spec.PluginConfig.Bytes(), &pluginConfig)
if err != nil {
return pkgerrors.Wrap(err, "error while unmarshalling plugin config")
}
return pkgerrors.Wrap(mercuryconfig.ValidatePluginConfig(pluginConfig, feedId), "Mercury PluginConfig is invalid")
return pkgerrors.Wrap(mercuryconfig.ValidatePluginConfig(pluginConfig, feedID), "Mercury PluginConfig is invalid")
}

func validateOCR2CCIPExecutionSpec(jsonConfig job.JSONConfig) error {
Expand Down
14 changes: 12 additions & 2 deletions core/services/relay/evm/mercury/v3/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v3

import (
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
Expand All @@ -22,6 +23,7 @@ import (
mercurytypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/types"
mercuryutils "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/utils"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v3/reportcodec"
relayTypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down Expand Up @@ -63,6 +65,12 @@ func NewDataSource(orm types.DataSourceORM, pr pipeline.Runner, jb job.Job, spec

func (ds *datasource) Observe(ctx context.Context, repts ocrtypes.ReportTimestamp, fetchMaxFinalizedTimestamp bool) (obs v3types.Observation, pipelineExecutionErr error) {
var wg sync.WaitGroup
var relayConfig relayTypes.RelayConfig
err := json.Unmarshal(ds.jb.OCR2OracleSpec.RelayConfig.Bytes(), &relayConfig)
if err != nil {
pipelineExecutionErr = fmt.Errorf("failed to deserialize relay config: %w", err)
return
}
ctx, cancel := context.WithCancel(ctx)

if fetchMaxFinalizedTimestamp {
Expand Down Expand Up @@ -114,7 +122,8 @@ func (ds *datasource) Observe(ctx context.Context, repts ocrtypes.ReportTimestam
var isLink, isNative bool
if ds.feedID == ds.linkFeedID {
isLink = true
} else {
} else if ds.jb.OCR2OracleSpec.PluginConfig != nil {
// If the triggerCapability is enabled, we don't need to fetch the price
wg.Add(1)
go func() {
defer wg.Done()
Expand All @@ -132,7 +141,8 @@ func (ds *datasource) Observe(ctx context.Context, repts ocrtypes.ReportTimestam

if ds.feedID == ds.nativeFeedID {
isNative = true
} else {
} else if ds.jb.OCR2OracleSpec.PluginConfig != nil {
// If the triggerCapability is enabled, we don't need to fetch the price
wg.Add(1)
go func() {
defer wg.Done()
Expand Down
25 changes: 22 additions & 3 deletions core/services/relay/evm/mercury/v3/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import (
"math/big"
"testing"

relaymercuryv3 "github.com/smartcontractkit/chainlink-data-streams/mercury/v3"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline/eautils"

"github.com/pkg/errors"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/stretchr/testify/assert"

mercurytypes "github.com/smartcontractkit/chainlink-common/pkg/types/mercury"
relaymercuryv3 "github.com/smartcontractkit/chainlink-data-streams/mercury/v3"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline/eautils"
mercurymocks "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/utils"
reportcodecv3 "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/v3/reportcodec"
Expand Down Expand Up @@ -360,6 +361,24 @@ func Test_Datasource(t *testing.T) {
assert.EqualError(t, obs.NativePrice.Err, "some error fetching native price")
})

t.Run("when PluginConfig=nil skips fetching link and native prices", func(t *testing.T) {
t.Cleanup(func() {
fetcher.linkPriceErr = nil
fetcher.nativePriceErr = nil
})

fetcher.linkPriceErr = errors.New("some error fetching link price")
fetcher.nativePriceErr = errors.New("some error fetching native price")

ds.jb.OCR2OracleSpec.PluginConfig = nil

obs, err := ds.Observe(ctx, repts, false)
assert.NoError(t, err)
assert.Nil(t, obs.LinkPrice.Err)
assert.Nil(t, obs.NativePrice.Err)
assert.Equal(t, big.NewInt(122), obs.BenchmarkPrice.Val)
})

t.Run("when succeeds to fetch linkPrice or nativePrice but got nil (new feed)", func(t *testing.T) {
obs, err := ds.Observe(ctx, repts, false)
assert.NoError(t, err)
Expand Down
Loading