Skip to content

Commit

Permalink
Validate keystone workflows + Enforce full semver on capabilities (#1…
Browse files Browse the repository at this point in the history
…3328)

* Enable workflow validation against JSON spec

* Merge version field with ID

* Use full capability versioning in workflow yaml

* Update gomod

* fixup! Update gomod

* fixup! Enable workflow validation against JSON spec

* fixup! Update gomod

---------

Co-authored-by: Bolek <[email protected]>
  • Loading branch information
HenryNguyen5 and bolekk authored Jun 7, 2024
1 parent 066afc0 commit 0d95942
Show file tree
Hide file tree
Showing 28 changed files with 289 additions and 154 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-knives-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal [Keystone] Merge version field with ID
5 changes: 5 additions & 0 deletions .changeset/happy-oranges-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal Add workflow validation
2 changes: 1 addition & 1 deletion core/capabilities/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (r *Registry) Add(ctx context.Context, c capabilities.BaseCapability) error
}

r.m[id] = c
r.lggr.Infow("capability added", "id", id, "type", info.CapabilityType, "description", info.Description, "version", info.Version)
r.lggr.Infow("capability added", "id", id, "type", info.CapabilityType, "description", info.Description, "version", info.Version())
return nil
}

Expand Down
19 changes: 7 additions & 12 deletions core/capabilities/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package capabilities_test

import (
"context"
"fmt"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -36,12 +37,11 @@ func TestRegistry(t *testing.T) {

r := coreCapabilities.NewRegistry(logger.TestLogger(t))

id := "capability-1"
id := "capability-1@1.0.0"
ci, err := capabilities.NewCapabilityInfo(
id,
capabilities.CapabilityTypeAction,
"capability-1-description",
"v1.0.0",
)
require.NoError(t, err)

Expand All @@ -64,12 +64,11 @@ func TestRegistry_NoDuplicateIDs(t *testing.T) {
ctx := testutils.Context(t)
r := coreCapabilities.NewRegistry(logger.TestLogger(t))

id := "capability-1"
id := "capability-1@1.0.0"
ci, err := capabilities.NewCapabilityInfo(
id,
capabilities.CapabilityTypeAction,
"capability-1-description",
"v1.0.0",
)
require.NoError(t, err)

Expand All @@ -81,13 +80,12 @@ func TestRegistry_NoDuplicateIDs(t *testing.T) {
id,
capabilities.CapabilityTypeConsensus,
"capability-2-description",
"v1.0.0",
)
require.NoError(t, err)
c2 := &mockCapability{CapabilityInfo: ci}

err = r.Add(ctx, c2)
assert.ErrorContains(t, err, "capability with id: capability-1 already exists")
assert.ErrorContains(t, err, "capability with id: capability-1@1.0.0 already exists")
}

func TestRegistry_ChecksExecutionAPIByType(t *testing.T) {
Expand All @@ -100,12 +98,11 @@ func TestRegistry_ChecksExecutionAPIByType(t *testing.T) {
{
name: "action",
newCapability: func(ctx context.Context, reg *coreCapabilities.Registry) (string, error) {
id := uuid.New().String()
id := fmt.Sprintf("%s@%s", uuid.New().String(), "1.0.0")
ci, err := capabilities.NewCapabilityInfo(
id,
capabilities.CapabilityTypeAction,
"capability-1-description",
"v1.0.0",
)
require.NoError(t, err)

Expand All @@ -120,12 +117,11 @@ func TestRegistry_ChecksExecutionAPIByType(t *testing.T) {
{
name: "target",
newCapability: func(ctx context.Context, reg *coreCapabilities.Registry) (string, error) {
id := uuid.New().String()
id := fmt.Sprintf("%s@%s", uuid.New().String(), "1.0.0")
ci, err := capabilities.NewCapabilityInfo(
id,
capabilities.CapabilityTypeTarget,
"capability-1-description",
"v1.0.0",
)
require.NoError(t, err)

Expand Down Expand Up @@ -153,12 +149,11 @@ func TestRegistry_ChecksExecutionAPIByType(t *testing.T) {
{
name: "consensus",
newCapability: func(ctx context.Context, reg *coreCapabilities.Registry) (string, error) {
id := uuid.New().String()
id := fmt.Sprintf("%s@%s", uuid.New().String(), "1.0.0")
ci, err := capabilities.NewCapabilityInfo(
id,
capabilities.CapabilityTypeConsensus,
"capability-1-description",
"v1.0.0",
)
require.NoError(t, err)

Expand Down
5 changes: 2 additions & 3 deletions core/capabilities/remote/target/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ func testClient(ctx context.Context, t *testing.T, numWorkflowPeers int, workflo
}

capInfo := commoncap.CapabilityInfo{
ID: "cap_id",
ID: "cap_id@1.0.0",
CapabilityType: commoncap.CapabilityTypeTarget,
Description: "Remote Target",
Version: "0.0.1",
DON: &capDonInfo,
}

Expand Down Expand Up @@ -257,7 +256,7 @@ func (t *clientTestServer) Receive(msg *remotetypes.MessageBody) {

for receiver := range t.messageIDToSenders[messageID] {
var responseMsg = &remotetypes.MessageBody{
CapabilityId: "cap_id",
CapabilityId: "cap_id@1.0.0",
CapabilityDonId: "capability-don",
CallerDonId: t.workflowDonInfo.ID,
Method: remotetypes.MethodExecute,
Expand Down
3 changes: 1 addition & 2 deletions core/capabilities/remote/target/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ func testRemoteTarget(ctx context.Context, t *testing.T, underlying commoncap.Ta
}

capInfo := commoncap.CapabilityInfo{
ID: "cap_id",
ID: "cap_id@1.0.0",
CapabilityType: commoncap.CapabilityTypeTarget,
Description: "Remote Target",
Version: "0.0.1",
DON: &capDonInfo,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ func Test_ClientRequest_MessageValidation(t *testing.T) {
}

capInfo := commoncap.CapabilityInfo{
ID: "cap_id",
ID: "cap_id@1.0.0",
CapabilityType: commoncap.CapabilityTypeTarget,
Description: "Remote Target",
Version: "0.0.1",
DON: &capDonInfo,
}

Expand Down
3 changes: 1 addition & 2 deletions core/capabilities/remote/target/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ func testRemoteTargetServer(ctx context.Context, t *testing.T,
}

capInfo := commoncap.CapabilityInfo{
ID: "cap_id",
ID: "cap_id@1.0.0",
CapabilityType: commoncap.CapabilityTypeTarget,
Description: "Remote Target",
Version: "0.0.1",
DON: &capDonInfo,
}

Expand Down
3 changes: 1 addition & 2 deletions core/capabilities/remote/trigger_publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ func TestTriggerPublisher_Register(t *testing.T) {
lggr := logger.TestLogger(t)
ctx := testutils.Context(t)
capInfo := commoncap.CapabilityInfo{
ID: "cap_id",
ID: "cap_id@1",
CapabilityType: commoncap.CapabilityTypeTrigger,
Description: "Remote Trigger",
Version: "0.0.1",
}
p1 := p2ptypes.PeerID{}
require.NoError(t, p1.UnmarshalText([]byte(peerID1)))
Expand Down
3 changes: 1 addition & 2 deletions core/capabilities/remote/trigger_subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ func TestTriggerSubscriber_RegisterAndReceive(t *testing.T) {
lggr := logger.TestLogger(t)
ctx := testutils.Context(t)
capInfo := commoncap.CapabilityInfo{
ID: "cap_id",
ID: "cap_id@1",
CapabilityType: commoncap.CapabilityTypeTrigger,
Description: "Remote Trigger",
Version: "0.0.1",
}
p1 := p2ptypes.PeerID{}
require.NoError(t, p1.UnmarshalText([]byte(peerID1)))
Expand Down
3 changes: 1 addition & 2 deletions core/capabilities/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ func (s *registrySyncer) Start(ctx context.Context) error {
// that reads the configuration from chain (KS-117).
func (s *registrySyncer) launch(ctx context.Context) {
defer s.wg.Done()
capId := "streams-trigger"
capId := "streams-trigger@0.0.1"
triggerInfo, err := capabilities.NewRemoteCapabilityInfo(
capId,
capabilities.CapabilityTypeTrigger,
"Remote Trigger",
"v0.0.1",
&s.networkSetup.TriggerCapabilityDonInfo,
)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions core/capabilities/targets/write_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ type WriteTarget struct {
lggr logger.Logger
}

func NewWriteTarget(lggr logger.Logger, name string, cr commontypes.ContractReader, cw commontypes.ChainWriter, forwarderAddress string) *WriteTarget {
func NewWriteTarget(lggr logger.Logger, id string, cr commontypes.ContractReader, cw commontypes.ChainWriter, forwarderAddress string) *WriteTarget {
info := capabilities.MustNewCapabilityInfo(
name,
id,
capabilities.CapabilityTypeTarget,
"Write target.",
"v1.0.0",
)

logger := lggr.Named("WriteTarget")
Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/targets/write_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestWriteTarget(t *testing.T) {
forwarderA := testutils.NewAddress()
forwarderAddr := forwarderA.Hex()

writeTarget := targets.NewWriteTarget(lggr, "Test", cr, cw, forwarderAddr)
writeTarget := targets.NewWriteTarget(lggr, "[email protected]", cr, cw, forwarderAddr)
require.NotNil(t, writeTarget)

config, err := values.NewMap(map[string]any{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ func TestScheduledExecutionStrategy_LocalDON(t *testing.T) {
// schedule.
mt := newMockCapability(
capabilities.MustNewCapabilityInfo(
"write_polygon-testnet-mumbai",
"write_polygon-testnet-mumbai@1.0.0",
capabilities.CapabilityTypeTarget,
"a write capability targeting polygon mumbai testnet",
"v1.0.0",
),
func(req capabilities.CapabilityRequest) (capabilities.CapabilityResponse, error) {
gotTime = time.Now()
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-automation v1.0.3
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240606094423-573049c41fa0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240606173949-4d52ba4e3c79
github.com/smartcontractkit/chainlink-vrf v0.0.0-20240222010609-cd67d123c772
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240606094423-573049c41fa0 h1:53zVcdDxrHG3oewhP7AWOiLtwTozcQ0/wzFTsaTBS5M=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240606094423-573049c41fa0/go.mod h1:DUZccDEW98n+J1mhdWGO7wr/Njad9p9Fzks839JN7Rs=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240606173949-4d52ba4e3c79 h1:hs8dNt80KM3iBPBJ4fo6Kp3gsHhdJUe8RVr/JpGBaQM=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240606173949-4d52ba4e3c79/go.mod h1:L32xvCpk84Nglit64OhySPMP1tM3TTBK7Tw0qZl7Sd4=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240524214833-c362c2ebbd2d h1:5tgMC5Gi2UAOKZ+m28W8ubjLeR0pQCAcrz6eQ0rW510=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240524214833-c362c2ebbd2d/go.mod h1:0UNuO3nDt9MFsZPaHJBEUolxVkN0iC69j1ccDp95e8k=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240606130021-a4b7359e1580 h1:nsnLzpBTDAQWkfsOz/qd8BTlb1hUpaow1KmA1tPwTf4=
Expand Down
12 changes: 8 additions & 4 deletions core/services/feeds/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,23 +657,27 @@ func Test_Service_ProposeJob(t *testing.T) {
wfName = "myworkflow" // len 10
specYaml = `
triggers:
- id: "a-trigger"
- id: "[email protected]"
config: {}
actions:
- id: "an-action"
- id: "an-action@1.0.0"
ref: "an-action"
config: {}
inputs:
trigger_output: $(trigger.outputs)
consensus:
- id: "a-consensus"
- id: "a-consensus@1.0.0"
ref: "a-consensus"
config: {}
inputs:
trigger_output: $(trigger.outputs)
an-action_output: $(an-action.outputs)
targets:
- id: "a-target"
- id: "[email protected]"
config: {}
ref: "a-target"
inputs:
consensus_output: $(a-consensus.outputs)
Expand Down
6 changes: 3 additions & 3 deletions core/services/relay/evm/write_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (

func NewWriteTarget(ctx context.Context, relayer *Relayer, chain legacyevm.Chain, lggr logger.Logger) (*targets.WriteTarget, error) {
// generate ID based on chain selector
name := fmt.Sprintf("write_%v", chain.ID())
id := fmt.Sprintf("write_%v@0.0.1", chain.ID())
chainName, err := chainselectors.NameFromChainId(chain.ID().Uint64())
if err == nil {
name = fmt.Sprintf("write_%v", chainName)
id = fmt.Sprintf("write_%v@0.0.1", chainName)
}

// EVM-specific init
Expand Down Expand Up @@ -74,5 +74,5 @@ func NewWriteTarget(ctx context.Context, relayer *Relayer, chain legacyevm.Chain
return nil, err
}

return targets.NewWriteTarget(lggr, name, cr, cw, config.ForwarderAddress().String()), nil
return targets.NewWriteTarget(lggr, id, cr, cw, config.ForwarderAddress().String()), nil
}
Loading

0 comments on commit 0d95942

Please sign in to comment.