Skip to content

Commit 160c608

Browse files
authored
[CAPPL-732] Detect NoDAG WASM via specific import (#1143)
1 parent 5ca460a commit 160c608

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/workflows/wasm/host/module.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
wasmpb "github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm/pb"
2929
)
3030

31+
const v2ImportPrefix = "version_v2"
32+
3133
type RequestData struct {
3234
fetchRequestsCounter int
3335
response *wasmpb.Response
@@ -120,6 +122,8 @@ type Module struct {
120122

121123
wg sync.WaitGroup
122124
stopCh chan struct{}
125+
126+
isLegacyDAG bool
123127
}
124128

125129
// WithDeterminism sets the Determinism field to a deterministic seed from a known time.
@@ -238,6 +242,15 @@ func NewModule(modCfg *ModuleConfig, binary []byte, opts ...func(*ModuleConfig))
238242
return nil, fmt.Errorf("error creating wasi linker: %w", err)
239243
}
240244

245+
isLegacyDAG := true
246+
for _, modImport := range mod.Imports() {
247+
name := modImport.Name()
248+
if modImport.Module() == "env" && name != nil && strings.HasPrefix(*name, v2ImportPrefix) {
249+
isLegacyDAG = false
250+
break
251+
}
252+
}
253+
241254
requestStore := &store{
242255
m: map[string]*RequestData{},
243256
}
@@ -289,6 +302,8 @@ func NewModule(modCfg *ModuleConfig, binary []byte, opts ...func(*ModuleConfig))
289302
cfg: modCfg,
290303

291304
stopCh: make(chan struct{}),
305+
306+
isLegacyDAG: isLegacyDAG,
292307
}
293308

294309
return m, nil
@@ -321,6 +336,10 @@ func (m *Module) Close() {
321336
m.wconfig.Close()
322337
}
323338

339+
func (m *Module) IsLegacyDAG() bool {
340+
return m.isLegacyDAG
341+
}
342+
324343
func (m *Module) Run(ctx context.Context, request *wasmpb.Request) (*wasmpb.Response, error) {
325344
ctxWithTimeout, cancel := context.WithTimeout(ctx, *m.cfg.Timeout)
326345
defer cancel()

0 commit comments

Comments
 (0)