Skip to content

Commit

Permalink
Merge branch 'develop' into rtinianov_delegateWorkflowSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
nolag authored Sep 17, 2024
2 parents 926ffb4 + 37c5a2f commit b581fa6
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 19 deletions.
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": minor
---

#updated mercury plugin to consider PluginConfig as optional if EnableTriggerCapability relay config is true. Then if PluginConfig is nil, skip fetching latestPrice for linkFeedId and nativeFeedId.
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
16 changes: 14 additions & 2 deletions core/services/relay/evm/mercury/v2/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2

import (
"context"
"encoding/json"
"fmt"
"math/big"
"sync"
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/v2/reportcodec"
relayTypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down Expand Up @@ -61,6 +63,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 v2types.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 @@ -108,7 +116,9 @@ func (ds *datasource) Observe(ctx context.Context, repts ocrtypes.ReportTimestam
}()

var isLink, isNative bool
if ds.feedID == ds.linkFeedID {
if ds.jb.OCR2OracleSpec.PluginConfig == nil {
obs.LinkPrice.Val = v2.MissingPrice
} else if ds.feedID == ds.linkFeedID {
isLink = true
} else {
wg.Add(1)
Expand All @@ -126,7 +136,9 @@ func (ds *datasource) Observe(ctx context.Context, repts ocrtypes.ReportTimestam
}()
}

if ds.feedID == ds.nativeFeedID {
if ds.jb.OCR2OracleSpec.PluginConfig == nil {
obs.NativePrice.Val = v2.MissingPrice
} else if ds.feedID == ds.nativeFeedID {
isNative = true
} else {
wg.Add(1)
Expand Down
31 changes: 30 additions & 1 deletion core/services/relay/evm/mercury/v2/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"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/pipeline"
mercurymocks "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/utils"
Expand Down Expand Up @@ -72,7 +73,16 @@ func (ms *mockSaver) Save(r *pipeline.Run) {

func Test_Datasource(t *testing.T) {
orm := &mockORM{}
ds := &datasource{orm: orm, lggr: logger.TestLogger(t)}
jb := job.Job{
Type: job.Type(pipeline.OffchainReporting2JobType),
OCR2OracleSpec: &job.OCR2OracleSpec{
CaptureEATelemetry: true,
PluginConfig: map[string]interface{}{
"serverURL": "a",
},
},
}
ds := &datasource{orm: orm, lggr: logger.TestLogger(t), jb: jb}
ctx := testutils.Context(t)
repts := ocrtypes.ReportTimestamp{}

Expand Down Expand Up @@ -274,6 +284,25 @@ 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() {
ds.jb = jb
})

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.Equal(t, obs.LinkPrice.Val, v2.MissingPrice)
assert.Nil(t, obs.NativePrice.Err)
assert.Equal(t, obs.NativePrice.Val, v2.MissingPrice)
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
16 changes: 14 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 @@ -112,7 +120,9 @@ func (ds *datasource) Observe(ctx context.Context, repts ocrtypes.ReportTimestam
}()

var isLink, isNative bool
if ds.feedID == ds.linkFeedID {
if ds.jb.OCR2OracleSpec.PluginConfig == nil {
obs.LinkPrice.Val = v3.MissingPrice
} else if ds.feedID == ds.linkFeedID {
isLink = true
} else {
wg.Add(1)
Expand All @@ -130,7 +140,9 @@ func (ds *datasource) Observe(ctx context.Context, repts ocrtypes.ReportTimestam
}()
}

if ds.feedID == ds.nativeFeedID {
if ds.jb.OCR2OracleSpec.PluginConfig == nil {
obs.NativePrice.Val = v3.MissingPrice
} else if ds.feedID == ds.nativeFeedID {
isNative = true
} else {
wg.Add(1)
Expand Down
29 changes: 26 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 @@ -77,6 +78,9 @@ func Test_Datasource(t *testing.T) {
Type: job.Type(pipeline.OffchainReporting2JobType),
OCR2OracleSpec: &job.OCR2OracleSpec{
CaptureEATelemetry: true,
PluginConfig: map[string]interface{}{
"serverURL": "a",
},
},
}
ds := &datasource{orm: orm, lggr: logger.TestLogger(t), jb: jb}
Expand Down Expand Up @@ -360,6 +364,25 @@ 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() {
ds.jb = jb
})

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.Equal(t, obs.LinkPrice.Val, relaymercuryv3.MissingPrice)
assert.Nil(t, obs.NativePrice.Err)
assert.Equal(t, obs.NativePrice.Val, relaymercuryv3.MissingPrice)
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

0 comments on commit b581fa6

Please sign in to comment.