From 207b0d502a9cadb600873cce9602bdfacca0e177 Mon Sep 17 00:00:00 2001 From: Rafael Felix Correa Date: Thu, 26 Sep 2024 14:20:18 +0200 Subject: [PATCH] Revert "Add wasm spec factory (#14458)" (#14569) This reverts commit 02982e328bce2180b408f3e9db30d57c8c3cb6bc. --- .gitignore | 1 - core/scripts/go.mod | 2 - core/scripts/go.sum | 4 - core/services/job/models.go | 19 ++-- core/services/job/models_test.go | 37 ++---- .../job/testdata/wasm/test_workflow_spec.go | 33 ------ core/services/job/wasm_file_spec_factory.go | 90 --------------- .../job/wasm_file_spec_factory_test.go | 56 --------- core/services/job/workflow_spec_factory.go | 45 ++++++-- .../job/workflow_spec_factory_test.go | 106 ++++++++++++++++++ core/services/job/yaml_spec_factory.go | 15 ++- core/services/job/yaml_spec_factory_test.go | 15 ++- core/services/workflows/delegate.go | 4 +- core/services/workflows/engine_test.go | 2 +- core/services/workflows/models_test.go | 5 +- go.mod | 2 - go.sum | 4 - integration-tests/go.mod | 2 - integration-tests/go.sum | 4 - integration-tests/load/go.mod | 2 - integration-tests/load/go.sum | 4 - 21 files changed, 180 insertions(+), 272 deletions(-) delete mode 100644 core/services/job/testdata/wasm/test_workflow_spec.go delete mode 100644 core/services/job/wasm_file_spec_factory.go delete mode 100644 core/services/job/wasm_file_spec_factory_test.go create mode 100644 core/services/job/workflow_spec_factory_test.go diff --git a/.gitignore b/.gitignore index a843d7b8773..4c4e76bee98 100644 --- a/.gitignore +++ b/.gitignore @@ -52,7 +52,6 @@ race.* golangci-lint-output.txt /golangci-lint/ .covdata -core/services/job/testdata/wasm/testmodule.wasm # DB state ./db/ diff --git a/core/scripts/go.mod b/core/scripts/go.mod index d082e1ef2c1..26714eb3d14 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -59,7 +59,6 @@ require ( github.com/NethermindEth/starknet.go v0.7.1-0.20240401080518-34a506f3cfdb // indirect github.com/VictoriaMetrics/fastcache v1.12.1 // indirect github.com/XSAM/otelsql v0.27.0 // indirect - github.com/andybalholm/brotli v1.1.0 // indirect github.com/armon/go-metrics v0.4.1 // indirect github.com/avast/retry-go/v4 v4.6.0 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect @@ -71,7 +70,6 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/buger/jsonparser v1.1.1 // indirect - github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 // indirect github.com/bytedance/sonic v1.10.1 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index a7d44e811ec..2ca81055186 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -115,8 +115,6 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= @@ -180,8 +178,6 @@ github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZ github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 h1:NJvU4S8KEk1GnF6+FvlnzMD/8wXTj/mYJSG6Q4yu3Pw= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0/go.mod h1:5YIL+Ouiww2zpO7u+iZ1U1G5NvmwQYaXdmCZQGjQM0U= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc= diff --git a/core/services/job/models.go b/core/services/job/models.go index 90408df6c41..b9ec8e726f4 100644 --- a/core/services/job/models.go +++ b/core/services/job/models.go @@ -19,8 +19,8 @@ import ( commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets" "github.com/smartcontractkit/chainlink-common/pkg/types" + pkgworkflows "github.com/smartcontractkit/chainlink-common/pkg/workflows" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/relay" "github.com/smartcontractkit/chainlink/v2/core/bridges" @@ -865,8 +865,7 @@ type WorkflowSpecType string const ( YamlSpec WorkflowSpecType = "yaml" - WASMFile WorkflowSpecType = "wasm_file" - DefaultSpecType = "" + DefaultSpecType = YamlSpec ) type WorkflowSpec struct { @@ -895,8 +894,12 @@ const ( // Validate checks the workflow spec for correctness func (w *WorkflowSpec) Validate(ctx context.Context) error { - s, err := w.SDKSpec(ctx, logger.NullLogger) + s, err := pkgworkflows.ParseWorkflowSpecYaml(w.Workflow) if err != nil { + return fmt.Errorf("%w: failed to parse workflow spec %s: %w", ErrInvalidWorkflowYAMLSpec, w.Workflow, err) + } + + if _, err = w.SDKSpec(ctx); err != nil { return err } @@ -910,16 +913,12 @@ func (w *WorkflowSpec) Validate(ctx context.Context) error { return nil } -func (w *WorkflowSpec) SDKSpec(ctx context.Context, lggr logger.Logger) (sdk.WorkflowSpec, error) { +func (w *WorkflowSpec) SDKSpec(ctx context.Context) (sdk.WorkflowSpec, error) { if w.sdkWorkflow != nil { return *w.sdkWorkflow, nil } - workflowSpecFactory, ok := workflowSpecFactories[w.SpecType] - if !ok { - return sdk.WorkflowSpec{}, fmt.Errorf("unknown spec type %s", w.SpecType) - } - spec, cid, err := workflowSpecFactory.Spec(ctx, lggr, w.Workflow, []byte(w.Config)) + spec, cid, err := workflowSpecFactory.Spec(ctx, w.Workflow, []byte(w.Config), w.SpecType) if err != nil { return sdk.WorkflowSpec{}, err } diff --git a/core/services/job/models_test.go b/core/services/job/models_test.go index 02aaff79317..49bd29c9959 100644 --- a/core/services/job/models_test.go +++ b/core/services/job/models_test.go @@ -1,8 +1,7 @@ -package job_test +package job import ( _ "embed" - "encoding/json" "reflect" "testing" "time" @@ -12,10 +11,8 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink-common/pkg/types" pkgworkflows "github.com/smartcontractkit/chainlink-common/pkg/workflows" - "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/relay" "github.com/stretchr/testify/assert" @@ -30,7 +27,7 @@ func TestOCR2OracleSpec_RelayIdentifier(t *testing.T) { type fields struct { Relay string ChainID string - RelayConfig job.JSONConfig + RelayConfig JSONConfig } tests := []struct { name string @@ -74,7 +71,7 @@ func TestOCR2OracleSpec_RelayIdentifier(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - s := &job.OCR2OracleSpec{ + s := &OCR2OracleSpec{ Relay: tt.fields.Relay, ChainID: tt.fields.ChainID, RelayConfig: tt.fields.RelayConfig, @@ -99,7 +96,7 @@ var ( ) func TestOCR2OracleSpec(t *testing.T) { - val := job.OCR2OracleSpec{ + val := OCR2OracleSpec{ Relay: relay.NetworkEVM, PluginType: types.Median, ContractID: "foo", @@ -262,13 +259,13 @@ func TestOCR2OracleSpec(t *testing.T) { }) t.Run("round-trip", func(t *testing.T) { - var gotVal job.OCR2OracleSpec + var gotVal OCR2OracleSpec require.NoError(t, toml.Unmarshal([]byte(compact), &gotVal)) gotB, err := toml.Marshal(gotVal) require.NoError(t, err) require.Equal(t, compact, string(gotB)) t.Run("pretty", func(t *testing.T) { - var gotVal job.OCR2OracleSpec + var gotVal OCR2OracleSpec require.NoError(t, toml.Unmarshal([]byte(pretty), &gotVal)) gotB, err := toml.Marshal(gotVal) require.NoError(t, err) @@ -324,7 +321,7 @@ func TestWorkflowSpec_Validate(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - w := &job.WorkflowSpec{ + w := &WorkflowSpec{ Workflow: tt.fields.Workflow, } err := w.Validate(testutils.Context(t)) @@ -336,24 +333,4 @@ func TestWorkflowSpec_Validate(t *testing.T) { } }) } - - t.Run("WASM can validate", func(t *testing.T) { - config, err := json.Marshal(sdk.NewWorkflowParams{ - Owner: "owner", - Name: "name", - }) - require.NoError(t, err) - - w := &job.WorkflowSpec{ - Workflow: createTestBinary(t), - SpecType: job.WASMFile, - Config: string(config), - } - - err = w.Validate(testutils.Context(t)) - require.NoError(t, err) - assert.Equal(t, "owner", w.WorkflowOwner) - assert.Equal(t, "name", w.WorkflowName) - require.NotEmpty(t, w.WorkflowID) - }) } diff --git a/core/services/job/testdata/wasm/test_workflow_spec.go b/core/services/job/testdata/wasm/test_workflow_spec.go deleted file mode 100644 index 40b9c0bbb67..00000000000 --- a/core/services/job/testdata/wasm/test_workflow_spec.go +++ /dev/null @@ -1,33 +0,0 @@ -//go:build wasip1 - -package main - -import ( - "encoding/json" - "log" - - "github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm" - - "github.com/smartcontractkit/chainlink-common/pkg/capabilities/cli/cmd/testdata/fixtures/capabilities/basictrigger" - "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" -) - -func BuildWorkflow(config []byte) *sdk.WorkflowSpecFactory { - params := sdk.NewWorkflowParams{} - if err := json.Unmarshal(config, ¶ms); err != nil { - log.Fatal(err) - } - - workflow := sdk.NewWorkflowSpecFactory(params) - - triggerCfg := basictrigger.TriggerConfig{Name: "trigger", Number: 100} - _ = triggerCfg.New(workflow) - - return workflow -} - -func main() { - runner := wasm.NewRunner() - workflow := BuildWorkflow(runner.Config()) - runner.Run(workflow) -} diff --git a/core/services/job/wasm_file_spec_factory.go b/core/services/job/wasm_file_spec_factory.go deleted file mode 100644 index d5fca2fc721..00000000000 --- a/core/services/job/wasm_file_spec_factory.go +++ /dev/null @@ -1,90 +0,0 @@ -package job - -import ( - "bytes" - "context" - "crypto/sha256" - "errors" - "fmt" - "io" - "os" - "path" - "strings" - - "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" - "github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm/host" - - "github.com/smartcontractkit/chainlink/v2/core/logger" - - "github.com/andybalholm/brotli" -) - -type WasmFileSpecFactory struct{} - -func (w WasmFileSpecFactory) Spec(ctx context.Context, lggr logger.Logger, workflow string, config []byte) (sdk.WorkflowSpec, string, error) { - compressedBinary, sha, err := w.rawSpecAndSha(workflow, config) - if err != nil { - return sdk.WorkflowSpec{}, "", err - } - - moduleConfig := &host.ModuleConfig{Logger: lggr} - spec, err := host.GetWorkflowSpec(moduleConfig, compressedBinary, config) - if err != nil { - return sdk.WorkflowSpec{}, "", err - } else if spec == nil { - return sdk.WorkflowSpec{}, "", errors.New("workflow spec not found when running wasm") - } - - return *spec, sha, nil -} - -// rawSpecAndSha returns the brotli compressed version of the raw wasm file, alongside the sha256 hash of the raw wasm file -func (w WasmFileSpecFactory) rawSpecAndSha(wf string, config []byte) ([]byte, string, error) { - read, err := os.ReadFile(wf) - if err != nil { - return nil, "", err - } - - extension := strings.ToLower(path.Ext(wf)) - switch extension { - case ".wasm", "": - return w.rawSpecAndShaFromWasm(read, config) - case ".br": - return w.rawSpecAndShaFromBrotli(read, config) - default: - return nil, "", fmt.Errorf("unsupported file type %s", extension) - } -} - -func (w WasmFileSpecFactory) rawSpecAndShaFromBrotli(wasm, config []byte) ([]byte, string, error) { - brr := brotli.NewReader(bytes.NewReader(wasm)) - rawWasm, err := io.ReadAll(brr) - if err != nil { - return nil, "", err - } - - return wasm, w.sha(rawWasm, config), nil -} - -func (w WasmFileSpecFactory) rawSpecAndShaFromWasm(wasm, config []byte) ([]byte, string, error) { - var b bytes.Buffer - bwr := brotli.NewWriter(&b) - if _, err := bwr.Write(wasm); err != nil { - return nil, "", err - } - - if err := bwr.Close(); err != nil { - return nil, "", err - } - - return b.Bytes(), w.sha(wasm, config), nil -} - -func (w WasmFileSpecFactory) sha(wasm, config []byte) string { - sum := sha256.New() - sum.Write(wasm) - sum.Write(config) - return fmt.Sprintf("%x", sum.Sum(nil)) -} - -var _ WorkflowSpecFactory = (*WasmFileSpecFactory)(nil) diff --git a/core/services/job/wasm_file_spec_factory_test.go b/core/services/job/wasm_file_spec_factory_test.go deleted file mode 100644 index f58ee81297a..00000000000 --- a/core/services/job/wasm_file_spec_factory_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package job_test - -import ( - "crypto/sha256" - "encoding/json" - "fmt" - "os" - "os/exec" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" - "github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm/host" - - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/logger" - "github.com/smartcontractkit/chainlink/v2/core/services/job" -) - -func TestWasmFileSpecFactory(t *testing.T) { - binaryLocation := createTestBinary(t) - config, err := json.Marshal(sdk.NewWorkflowParams{ - Owner: "owner", - Name: "name", - }) - require.NoError(t, err) - - factory := job.WasmFileSpecFactory{} - actual, actualSha, err := factory.Spec(testutils.Context(t), logger.NullLogger, binaryLocation, config) - require.NoError(t, err) - - rawBinary, err := os.ReadFile(binaryLocation) - require.NoError(t, err) - expected, err := host.GetWorkflowSpec(&host.ModuleConfig{Logger: logger.NullLogger, IsUncompressed: true}, rawBinary, config) - require.NoError(t, err) - - expectedSha := sha256.New() - expectedSha.Write(rawBinary) - expectedSha.Write(config) - require.Equal(t, fmt.Sprintf("%x", expectedSha.Sum(nil)), actualSha) - - require.Equal(t, *expected, actual) -} - -func createTestBinary(t *testing.T) string { - const testBinaryLocation = "testdata/wasm/testmodule.wasm" - - cmd := exec.Command("go", "build", "-o", testBinaryLocation, "github.com/smartcontractkit/chainlink/v2/core/services/job/testdata/wasm") - cmd.Env = append(os.Environ(), "GOOS=wasip1", "GOARCH=wasm") - - output, err := cmd.CombinedOutput() - require.NoError(t, err, string(output)) - - return testBinaryLocation -} diff --git a/core/services/job/workflow_spec_factory.go b/core/services/job/workflow_spec_factory.go index f1dc524bf11..565e6a9fce1 100644 --- a/core/services/job/workflow_spec_factory.go +++ b/core/services/job/workflow_spec_factory.go @@ -2,21 +2,50 @@ package job import ( "context" + "crypto/sha256" "errors" + "fmt" "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" - - "github.com/smartcontractkit/chainlink/v2/core/logger" ) var ErrInvalidWorkflowType = errors.New("invalid workflow type") -type WorkflowSpecFactory interface { - Spec(ctx context.Context, lggr logger.Logger, workflow string, config []byte) (sdk.WorkflowSpec, string, error) +type SDKWorkflowSpecFactory interface { + Spec(ctx context.Context, rawSpec, config []byte) (sdk.WorkflowSpec, error) + RawSpec(ctx context.Context, wf string) ([]byte, error) +} + +type WorkflowSpecFactory map[WorkflowSpecType]SDKWorkflowSpecFactory + +func (wsf WorkflowSpecFactory) Spec( + ctx context.Context, workflow string, config []byte, tpe WorkflowSpecType) (sdk.WorkflowSpec, string, error) { + if tpe == "" { + tpe = DefaultSpecType + } + + factory, ok := wsf[tpe] + if !ok { + return sdk.WorkflowSpec{}, "", ErrInvalidWorkflowType + } + + rawSpec, err := factory.RawSpec(ctx, workflow) + if err != nil { + return sdk.WorkflowSpec{}, "", err + } + + spec, err := factory.Spec(ctx, rawSpec, config) + if err != nil { + return sdk.WorkflowSpec{}, "", err + } + + sum := sha256.New() + sum.Write(rawSpec) + sum.Write(config) + + return spec, fmt.Sprintf("%x", sum.Sum(nil)), nil } -var workflowSpecFactories = map[WorkflowSpecType]WorkflowSpecFactory{ - YamlSpec: YAMLSpecFactory{}, - WASMFile: WasmFileSpecFactory{}, - DefaultSpecType: YAMLSpecFactory{}, +var workflowSpecFactory = WorkflowSpecFactory{ + YamlSpec: YAMLSpecFactory{}, } diff --git a/core/services/job/workflow_spec_factory_test.go b/core/services/job/workflow_spec_factory_test.go new file mode 100644 index 00000000000..dc2ff3bac9b --- /dev/null +++ b/core/services/job/workflow_spec_factory_test.go @@ -0,0 +1,106 @@ +package job_test + +import ( + "context" + "crypto/sha256" + "errors" + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" + + "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" + "github.com/smartcontractkit/chainlink/v2/core/services/job" +) + +func TestWorkflowSpecFactory_ToSpec(t *testing.T) { + t.Parallel() + + anyData := "any data" + anyConfig := []byte("any config") + anySpec := sdk.WorkflowSpec{Name: "name", Owner: "owner"} + + t.Run("delegates to factory and calculates CID", func(t *testing.T) { + runYamlSpecTest(t, anySpec, anyData, anyConfig, job.YamlSpec) + }) + + t.Run("delegates default", func(t *testing.T) { + runYamlSpecTest(t, anySpec, anyData, anyConfig, "") + }) + + t.Run("CID without config matches", func(t *testing.T) { + factory := job.WorkflowSpecFactory{ + job.YamlSpec: mockSdkSpecFactory{t: t, noConfig: true, SpecVal: anySpec}, + } + results, cid, err := factory.Spec(testutils.Context(t), anyData, nil, job.YamlSpec) + require.NoError(t, err) + + assert.Equal(t, anySpec, results) + + sha256Hash := sha256.New() + sha256Hash.Write([]byte(anyData)) + expectedCid := fmt.Sprintf("%x", sha256Hash.Sum(nil)) + assert.Equal(t, expectedCid, cid) + }) + + t.Run("returns errors from sdk factory", func(t *testing.T) { + anyErr := errors.New("nope") + factory := job.WorkflowSpecFactory{ + job.YamlSpec: mockSdkSpecFactory{t: t, Err: anyErr}, + } + + _, _, err := factory.Spec(testutils.Context(t), anyData, anyConfig, job.YamlSpec) + assert.Equal(t, anyErr, err) + }) + + t.Run("returns an error if the type is not supported", func(t *testing.T) { + factory := job.WorkflowSpecFactory{ + job.YamlSpec: mockSdkSpecFactory{t: t, SpecVal: anySpec}, + } + + _, _, err := factory.Spec(testutils.Context(t), anyData, anyConfig, "unsupported") + assert.Error(t, err) + }) +} + +func runYamlSpecTest(t *testing.T, anySpec sdk.WorkflowSpec, anyData string, anyConfig []byte, specType job.WorkflowSpecType) { + factory := job.WorkflowSpecFactory{ + job.YamlSpec: mockSdkSpecFactory{t: t, SpecVal: anySpec}, + } + + results, cid, err := factory.Spec(testutils.Context(t), anyData, anyConfig, specType) + + require.NoError(t, err) + assert.Equal(t, anySpec, results) + + sha256Hash := sha256.New() + sha256Hash.Write([]byte(anyData)) + sha256Hash.Write(anyConfig) + expectedCid := fmt.Sprintf("%x", sha256Hash.Sum(nil)) + assert.Equal(t, expectedCid, cid) +} + +type mockSdkSpecFactory struct { + t *testing.T + noConfig bool + SpecVal sdk.WorkflowSpec + Err error +} + +func (f mockSdkSpecFactory) RawSpec(_ context.Context, wf string) ([]byte, error) { + return []byte(wf), nil +} + +func (f mockSdkSpecFactory) Spec(_ context.Context, rawSpec, config []byte) (sdk.WorkflowSpec, error) { + assert.ElementsMatch(f.t, rawSpec, []byte("any data")) + if f.noConfig { + assert.Nil(f.t, config) + } else { + assert.ElementsMatch(f.t, config, []byte("any config")) + } + + return f.SpecVal, f.Err +} diff --git a/core/services/job/yaml_spec_factory.go b/core/services/job/yaml_spec_factory.go index 40a26de181e..ea344a3ffc4 100644 --- a/core/services/job/yaml_spec_factory.go +++ b/core/services/job/yaml_spec_factory.go @@ -2,20 +2,19 @@ package job import ( "context" - "crypto/sha256" - "fmt" "github.com/smartcontractkit/chainlink-common/pkg/workflows" "github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk" - - "github.com/smartcontractkit/chainlink/v2/core/logger" ) type YAMLSpecFactory struct{} -var _ WorkflowSpecFactory = (*YAMLSpecFactory)(nil) +var _ SDKWorkflowSpecFactory = (*YAMLSpecFactory)(nil) + +func (y YAMLSpecFactory) Spec(_ context.Context, rawSpec, _ []byte) (sdk.WorkflowSpec, error) { + return workflows.ParseWorkflowSpecYaml(string(rawSpec)) +} -func (y YAMLSpecFactory) Spec(ctx context.Context, lggr logger.Logger, workflow string, config []byte) (sdk.WorkflowSpec, string, error) { - spec, err := workflows.ParseWorkflowSpecYaml(workflow) - return spec, fmt.Sprintf("%x", sha256.Sum256([]byte(workflow))), err +func (y YAMLSpecFactory) RawSpec(_ context.Context, wf string) ([]byte, error) { + return []byte(wf), nil } diff --git a/core/services/job/yaml_spec_factory_test.go b/core/services/job/yaml_spec_factory_test.go index c12d4872d92..4d075fe6e20 100644 --- a/core/services/job/yaml_spec_factory_test.go +++ b/core/services/job/yaml_spec_factory_test.go @@ -1,17 +1,13 @@ package job_test import ( - "crypto/sha256" - "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" commonworkflows "github.com/smartcontractkit/chainlink-common/pkg/workflows" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/job" ) @@ -68,12 +64,19 @@ targets: func TestYamlSpecFactory_GetSpec(t *testing.T) { t.Parallel() - actual, actualSha, err := job.YAMLSpecFactory{}.Spec(testutils.Context(t), logger.NullLogger, anyYamlSpec, []byte{}) + actual, err := job.YAMLSpecFactory{}.Spec(testutils.Context(t), []byte(anyYamlSpec), []byte{}) require.NoError(t, err) expected, err := commonworkflows.ParseWorkflowSpecYaml(anyYamlSpec) require.NoError(t, err) require.Equal(t, expected, actual) - assert.Equal(t, fmt.Sprintf("%x", sha256.Sum256([]byte(anyYamlSpec))), actualSha) +} + +func TestYamlSpecFactory_GetRawSpec(t *testing.T) { + t.Parallel() + + actual, err := job.YAMLSpecFactory{}.RawSpec(testutils.Context(t), anyYamlSpec) + require.NoError(t, err) + require.Equal(t, []byte(anyYamlSpec), actual) } diff --git a/core/services/workflows/delegate.go b/core/services/workflows/delegate.go index fec32852863..2aac9ba97b5 100644 --- a/core/services/workflows/delegate.go +++ b/core/services/workflows/delegate.go @@ -35,7 +35,7 @@ func (d *Delegate) OnDeleteJob(context.Context, job.Job) error { return nil } // ServicesForSpec satisfies the job.Delegate interface. func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) ([]job.ServiceCtx, error) { - sdkSpec, err := spec.WorkflowSpec.SDKSpec(ctx, d.logger) + sdkSpec, err := spec.WorkflowSpec.SDKSpec(ctx) if err != nil { return nil, err } @@ -87,7 +87,7 @@ func ValidatedWorkflowJobSpec(ctx context.Context, tomlString string) (job.Job, return jb, fmt.Errorf("toml unmarshal error on workflow spec: %w", err) } - sdkSpec, err := spec.SDKSpec(ctx, logger.NullLogger) + sdkSpec, err := spec.SDKSpec(ctx) if err != nil { return jb, fmt.Errorf("failed to convert to sdk workflow spec: %w", err) } diff --git a/core/services/workflows/engine_test.go b/core/services/workflows/engine_test.go index 5379a880102..9bd1b285377 100644 --- a/core/services/workflows/engine_test.go +++ b/core/services/workflows/engine_test.go @@ -140,7 +140,7 @@ func newTestEngine(t *testing.T, reg *coreCap.Registry, spec string, opts ...fun sdkSpec, err := (&job.WorkflowSpec{ Workflow: spec, SpecType: job.YamlSpec, - }).SDKSpec(testutils.Context(t), logger.NullLogger) + }).SDKSpec(testutils.Context(t)) require.NoError(t, err) reg.SetLocalRegistry(&testConfigProvider{}) diff --git a/core/services/workflows/models_test.go b/core/services/workflows/models_test.go index c4b6a7bbf11..68944e64bad 100644 --- a/core/services/workflows/models_test.go +++ b/core/services/workflows/models_test.go @@ -9,7 +9,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/workflows" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/job" ) @@ -295,7 +294,7 @@ targets: for _, tc := range testCases { t.Run(tc.name, func(st *testing.T) { - spec, _, err := job.YAMLSpecFactory{}.Spec(testutils.Context(t), logger.NullLogger, tc.yaml, nil) + spec, err := job.YAMLSpecFactory{}.Spec(testutils.Context(t), []byte(tc.yaml), nil) require.NoError(t, err) wf, err := Parse(spec) @@ -324,7 +323,7 @@ targets: } func TestParsesIntsCorrectly(t *testing.T) { - spec, _, err := job.YAMLSpecFactory{}.Spec(testutils.Context(t), logger.NullLogger, hardcodedWorkflow, nil) + spec, err := job.YAMLSpecFactory{}.Spec(testutils.Context(t), []byte(hardcodedWorkflow), nil) require.NoError(t, err) wf, err := Parse(spec) diff --git a/go.mod b/go.mod index 19d5ae71265..552e9750e54 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/NethermindEth/juno v0.3.1 github.com/NethermindEth/starknet.go v0.7.1-0.20240401080518-34a506f3cfdb github.com/XSAM/otelsql v0.27.0 - github.com/andybalholm/brotli v1.1.0 github.com/avast/retry-go/v4 v4.6.0 github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/cometbft/cometbft v0.37.5 @@ -152,7 +151,6 @@ require ( github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/blendle/zapdriver v1.3.1 // indirect github.com/buger/jsonparser v1.1.1 // indirect - github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 // indirect github.com/bytedance/sonic v1.10.1 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect diff --git a/go.sum b/go.sum index 96761f00d17..6b218dabf81 100644 --- a/go.sum +++ b/go.sum @@ -118,8 +118,6 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= @@ -165,8 +163,6 @@ github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZ github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 h1:NJvU4S8KEk1GnF6+FvlnzMD/8wXTj/mYJSG6Q4yu3Pw= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0/go.mod h1:5YIL+Ouiww2zpO7u+iZ1U1G5NvmwQYaXdmCZQGjQM0U= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index b435c1b9051..ba22ea75aee 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -104,7 +104,6 @@ require ( github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30 // indirect github.com/alexflint/go-arg v1.4.2 // indirect github.com/alexflint/go-scalar v1.0.0 // indirect - github.com/andybalholm/brotli v1.1.0 // indirect github.com/armon/go-metrics v0.4.1 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/avast/retry-go v3.0.0+incompatible // indirect @@ -134,7 +133,6 @@ require ( github.com/blendle/zapdriver v1.3.1 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/buger/jsonparser v1.1.1 // indirect - github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 // indirect github.com/bytedance/sonic v1.10.1 // indirect github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b // indirect github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 1f6598256e0..bb9f3809a9a 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -185,8 +185,6 @@ github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2uc github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= @@ -281,8 +279,6 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA= github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 h1:NJvU4S8KEk1GnF6+FvlnzMD/8wXTj/mYJSG6Q4yu3Pw= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0/go.mod h1:5YIL+Ouiww2zpO7u+iZ1U1G5NvmwQYaXdmCZQGjQM0U= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 3f7c219144b..11c0ac7a9da 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -29,8 +29,6 @@ require ( require ( github.com/AlekSi/pointer v1.1.0 // indirect - github.com/andybalholm/brotli v1.1.0 // indirect - github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 // indirect github.com/smartcontractkit/chainlink-automation v1.0.4 // indirect github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925142036-56f243802342 // indirect github.com/smartcontractkit/libocr v0.0.0-20240717100443-f6226e09bee7 // indirect diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 15a90f4d7b0..0278df28ee4 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -183,8 +183,6 @@ github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2uc github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -275,8 +273,6 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA= github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0 h1:NJvU4S8KEk1GnF6+FvlnzMD/8wXTj/mYJSG6Q4yu3Pw= -github.com/bytecodealliance/wasmtime-go/v23 v23.0.0/go.mod h1:5YIL+Ouiww2zpO7u+iZ1U1G5NvmwQYaXdmCZQGjQM0U= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc=