Skip to content

Commit

Permalink
Revert "Add wasm spec factory (#14458)"
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 542f9d9
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 542f9d9

Please sign in to comment.