Skip to content

Commit

Permalink
Remote CapabilityID type
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Jul 19, 2024
1 parent 846c426 commit 3eab4d7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
48 changes: 24 additions & 24 deletions core/capabilities/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ func TestLauncher_WiresUpExternalCapabilities(t *testing.T) {
AcceptsWorkflows: true,
Members: nodes,
},
CapabilityConfigurations: map[registrysyncer.CapabilityID]capabilities.CapabilityConfiguration{
registrysyncer.CapabilityID(fullTriggerCapID): {},
registrysyncer.CapabilityID(fullTargetID): {},
CapabilityConfigurations: map[string]capabilities.CapabilityConfiguration{
fullTriggerCapID: {},
fullTargetID: {},
},
},
},
IDsToCapabilities: map[registrysyncer.CapabilityID]registrysyncer.Capability{
registrysyncer.CapabilityID(fullTriggerCapID): {
IDsToCapabilities: map[string]registrysyncer.Capability{
fullTriggerCapID: {
ID: "[email protected]",
CapabilityType: capabilities.CapabilityTypeTrigger,
},
registrysyncer.CapabilityID(fullTargetID): {
fullTargetID: {
ID: "[email protected]",
CapabilityType: capabilities.CapabilityTypeTarget,
},
Expand Down Expand Up @@ -203,9 +203,9 @@ func TestSyncer_IgnoresCapabilitiesForPrivateDON(t *testing.T) {
}

dID := uint32(1)
triggerID := registrysyncer.CapabilityID("[email protected]")
triggerID := "[email protected]"
hashedTriggerID := randomWord()
targetID := registrysyncer.CapabilityID("[email protected]")
targetID := "[email protected]"
hashedTargetID := randomWord()

// The below state describes a Workflow DON (AcceptsWorkflows = true),
Expand All @@ -223,13 +223,13 @@ func TestSyncer_IgnoresCapabilitiesForPrivateDON(t *testing.T) {
AcceptsWorkflows: true,
Members: nodes,
},
CapabilityConfigurations: map[registrysyncer.CapabilityID]capabilities.CapabilityConfiguration{
CapabilityConfigurations: map[string]capabilities.CapabilityConfiguration{
triggerID: {},
targetID: {},
},
},
},
IDsToCapabilities: map[registrysyncer.CapabilityID]registrysyncer.Capability{
IDsToCapabilities: map[string]registrysyncer.Capability{
triggerID: {
ID: triggerID,
CapabilityType: capabilities.CapabilityTypeTrigger,
Expand Down Expand Up @@ -314,8 +314,8 @@ func TestLauncher_WiresUpClientsForPublicWorkflowDON(t *testing.T) {
randomWord(),
}

fullTriggerCapID := registrysyncer.CapabilityID("[email protected]")
fullTargetID := registrysyncer.CapabilityID("[email protected]")
fullTriggerCapID := "[email protected]"
fullTargetID := "[email protected]"
triggerCapID := randomWord()
targetCapID := randomWord()
dID := uint32(1)
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestLauncher_WiresUpClientsForPublicWorkflowDON(t *testing.T) {
AcceptsWorkflows: false,
Members: capabilityDonNodes,
},
CapabilityConfigurations: map[registrysyncer.CapabilityID]capabilities.CapabilityConfiguration{
CapabilityConfigurations: map[string]capabilities.CapabilityConfiguration{
fullTriggerCapID: {
RemoteTriggerConfig: rtc,
},
Expand All @@ -357,7 +357,7 @@ func TestLauncher_WiresUpClientsForPublicWorkflowDON(t *testing.T) {
},
},
},
IDsToCapabilities: map[registrysyncer.CapabilityID]registrysyncer.Capability{
IDsToCapabilities: map[string]registrysyncer.Capability{
fullTriggerCapID: {
ID: fullTriggerCapID,
CapabilityType: capabilities.CapabilityTypeTrigger,
Expand Down Expand Up @@ -465,8 +465,8 @@ func TestLauncher_WiresUpClientsForPublicWorkflowDONButIgnoresPrivateCapabilitie
randomWord(),
}

fullTriggerCapID := registrysyncer.CapabilityID("[email protected]")
fullTargetID := registrysyncer.CapabilityID("[email protected]")
fullTriggerCapID := "[email protected]"
fullTargetID := "[email protected]"
triggerCapID := randomWord()
targetCapID := randomWord()
dID := uint32(1)
Expand Down Expand Up @@ -496,7 +496,7 @@ func TestLauncher_WiresUpClientsForPublicWorkflowDONButIgnoresPrivateCapabilitie
AcceptsWorkflows: false,
Members: capabilityDonNodes,
},
CapabilityConfigurations: map[registrysyncer.CapabilityID]capabilities.CapabilityConfiguration{
CapabilityConfigurations: map[string]capabilities.CapabilityConfiguration{
fullTriggerCapID: {},
},
},
Expand All @@ -509,12 +509,12 @@ func TestLauncher_WiresUpClientsForPublicWorkflowDONButIgnoresPrivateCapabilitie
AcceptsWorkflows: false,
Members: capabilityDonNodes,
},
CapabilityConfigurations: map[registrysyncer.CapabilityID]capabilities.CapabilityConfiguration{
CapabilityConfigurations: map[string]capabilities.CapabilityConfiguration{
fullTargetID: {},
},
},
},
IDsToCapabilities: map[registrysyncer.CapabilityID]registrysyncer.Capability{
IDsToCapabilities: map[string]registrysyncer.Capability{
fullTriggerCapID: {
ID: fullTriggerCapID,
CapabilityType: capabilities.CapabilityTypeTrigger,
Expand Down Expand Up @@ -653,14 +653,14 @@ func TestLauncher_SucceedsEvenIfDispatcherAlreadyHasReceiver(t *testing.T) {
AcceptsWorkflows: false,
Members: capabilityDonNodes,
},
CapabilityConfigurations: map[registrysyncer.CapabilityID]capabilities.CapabilityConfiguration{
registrysyncer.CapabilityID(fullTriggerCapID): {},
CapabilityConfigurations: map[string]capabilities.CapabilityConfiguration{
fullTriggerCapID: {},
},
},
},
IDsToCapabilities: map[registrysyncer.CapabilityID]registrysyncer.Capability{
registrysyncer.CapabilityID(fullTriggerCapID): {
ID: registrysyncer.CapabilityID(fullTriggerCapID),
IDsToCapabilities: map[string]registrysyncer.Capability{
fullTriggerCapID: {
ID: fullTriggerCapID,
CapabilityType: capabilities.CapabilityTypeTrigger,
},
},
Expand Down
9 changes: 4 additions & 5 deletions core/services/registrysyncer/local_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ import (
p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types"
)

type CapabilityID string
type DonID uint32

type DON struct {
capabilities.DON
CapabilityConfigurations map[CapabilityID]capabilities.CapabilityConfiguration
CapabilityConfigurations map[string]capabilities.CapabilityConfiguration
}

type Capability struct {
ID CapabilityID
ID string
CapabilityType capabilities.CapabilityType
}

Expand All @@ -30,7 +29,7 @@ type LocalRegistry struct {
peerWrapper p2ptypes.PeerWrapper
IDsToDONs map[DonID]DON
IDsToNodes map[p2ptypes.PeerID]kcr.CapabilitiesRegistryNodeInfo
IDsToCapabilities map[CapabilityID]Capability
IDsToCapabilities map[string]Capability
}

func (l *LocalRegistry) LocalNode(ctx context.Context) (capabilities.Node, error) {
Expand Down Expand Up @@ -77,7 +76,7 @@ func (l *LocalRegistry) ConfigForCapability(ctx context.Context, capabilityID st
return capabilities.CapabilityConfiguration{}, fmt.Errorf("could not find don %d", donID)
}

cc, ok := d.CapabilityConfigurations[CapabilityID(capabilityID)]
cc, ok := d.CapabilityConfigurations[capabilityID]
if !ok {
return capabilities.CapabilityConfiguration{}, fmt.Errorf("could not find capability configuration for capability %s and donID %d", capabilityID, donID)
}
Expand Down
8 changes: 4 additions & 4 deletions core/services/registrysyncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ func (s *registrySyncer) localRegistry(ctx context.Context) (*LocalRegistry, err
return nil, err
}

idsToCapabilities := map[CapabilityID]Capability{}
hashedIDsToCapabilityIDs := map[[32]byte]CapabilityID{}
idsToCapabilities := map[string]Capability{}
hashedIDsToCapabilityIDs := map[[32]byte]string{}
for _, c := range caps {
cid := CapabilityID(fmt.Sprintf("%s@%s", c.LabelledName, c.Version))
cid := fmt.Sprintf("%s@%s", c.LabelledName, c.Version)
idsToCapabilities[cid] = Capability{
ID: cid,
CapabilityType: toCapabilityType(c.CapabilityType),
Expand All @@ -203,7 +203,7 @@ func (s *registrySyncer) localRegistry(ctx context.Context) (*LocalRegistry, err

idsToDONs := map[DonID]DON{}
for _, d := range dons {
cc := map[CapabilityID]capabilities.CapabilityConfiguration{}
cc := map[string]capabilities.CapabilityConfiguration{}
for _, dc := range d.CapabilityConfigurations {
cid, ok := hashedIDsToCapabilityIDs[dc.CapabilityId]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions core/services/registrysyncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestReader_Integration(t *testing.T) {
require.NoError(t, err, "AddCapability failed for %s", writeChainCapability.LabelledName)
sim.Commit()

cid := CapabilityID(fmt.Sprintf("%s@%s", writeChainCapability.LabelledName, writeChainCapability.Version))
cid := fmt.Sprintf("%s@%s", writeChainCapability.LabelledName, writeChainCapability.Version)

hid, err := reg.GetHashedCapabilityId(&bind.CallOpts{}, writeChainCapability.LabelledName, writeChainCapability.Version)
require.NoError(t, err)
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestReader_Integration(t *testing.T) {
F: 1,
Members: toPeerIDs(nodeSet),
},
CapabilityConfigurations: map[CapabilityID]capabilities.CapabilityConfiguration{
CapabilityConfigurations: map[string]capabilities.CapabilityConfiguration{
cid: {
DefaultConfig: values.EmptyMap(),
RemoteTriggerConfig: rtc,
Expand Down
2 changes: 1 addition & 1 deletion core/services/workflows/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ func (e *Engine) executeStep(ctx context.Context, msg stepRequest) (*values.Map,
return nil, nil, err
}

config, err := e.configForStep(ctx, step)
config, err := e.configForStep(ctx, msg.state.ExecutionID, step)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 3eab4d7

Please sign in to comment.