Skip to content

Commit

Permalink
Revert "Add wasm spec factory (#14458)" (#14569)
Browse files Browse the repository at this point in the history
This reverts commit 02982e3.
  • Loading branch information
rafaelfelix authored Sep 26, 2024
1 parent 2440917 commit 207b0d5
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 272 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ race.*
golangci-lint-output.txt
/golangci-lint/
.covdata
core/services/job/testdata/wasm/testmodule.wasm

# DB state
./db/
Expand Down
2 changes: 0 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
19 changes: 9 additions & 10 deletions core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -865,8 +865,7 @@ type WorkflowSpecType string

const (
YamlSpec WorkflowSpecType = "yaml"
WASMFile WorkflowSpecType = "wasm_file"
DefaultSpecType = ""
DefaultSpecType = YamlSpec
)

type WorkflowSpec struct {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
37 changes: 7 additions & 30 deletions core/services/job/models_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package job_test
package job

import (
_ "embed"
"encoding/json"
"reflect"
"testing"
"time"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -99,7 +96,7 @@ var (
)

func TestOCR2OracleSpec(t *testing.T) {
val := job.OCR2OracleSpec{
val := OCR2OracleSpec{
Relay: relay.NetworkEVM,
PluginType: types.Median,
ContractID: "foo",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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)
})
}
33 changes: 0 additions & 33 deletions core/services/job/testdata/wasm/test_workflow_spec.go

This file was deleted.

90 changes: 0 additions & 90 deletions core/services/job/wasm_file_spec_factory.go

This file was deleted.

56 changes: 0 additions & 56 deletions core/services/job/wasm_file_spec_factory_test.go

This file was deleted.

Loading

0 comments on commit 207b0d5

Please sign in to comment.