Skip to content

DataStreams: Fix LLO job collision #17611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions deployment/data-streams/changeset/jd_distribute_llo_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func generateBootstrapProposals(ctx context.Context, e deployment.Environment, c
Value: pointer.To(devenv.LabelNodeTypeValueBootstrap),
Op: ptypes.SelectorOp_EQ,
},
{
Key: utils.DonIdentifier(cfg.Filter.DONID, cfg.Filter.DONName),
Op: ptypes.SelectorOp_EXIST,
},
})
if err != nil {
return nil, fmt.Errorf("failed to get externalJobID: %w", err)
Expand All @@ -124,6 +128,7 @@ func generateBootstrapProposals(ctx context.Context, e deployment.Environment, c
bootstrapSpec := jobs.NewBootstrapSpec(
cfg.ConfiguratorAddress,
cfg.Filter.DONID,
cfg.Filter.DONName,
jobs.RelayTypeEVM,
jobs.RelayConfig{
ChainID: chainID,
Expand Down Expand Up @@ -211,6 +216,10 @@ func generateOracleProposals(ctx context.Context, e deployment.Environment, cfg
Value: pointer.To(devenv.LabelNodeTypeValuePlugin),
Op: ptypes.SelectorOp_EQ,
},
{
Key: utils.DonIdentifier(cfg.Filter.DONID, cfg.Filter.DONName),
Op: ptypes.SelectorOp_EXIST,
},
})
if err != nil {
return nil, fmt.Errorf("failed to get externalJobID: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ donID = 1
servers = {'mercury-pipeline-testnet-producer.TEST.cldev.cloud:1340' = '0000005187b1498c0ccb2e56d5ee8040a03a4955822ed208749b474058fc3f9c'}
`

bootstrapSpec := `name = 'bootstrap'
bootstrapSpec := `name = 'don | 1'
type = 'bootstrap'
schemaVersion = 1
contractID = '0x4170ed0880ac9a755fd29b2688956bd959f923f4'
Expand Down
6 changes: 4 additions & 2 deletions deployment/data-streams/jobs/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package jobs

import (
"fmt"

"github.com/google/uuid"
"github.com/pelletier/go-toml/v2"
)
Expand Down Expand Up @@ -37,13 +39,13 @@ type RelayConfig struct {
FromBlock uint64 `toml:"fromBlock,omitempty"`
}

func NewBootstrapSpec(contractID string, donID uint64, relay RelayType, relayConfig RelayConfig, externalJobID uuid.UUID) *BootstrapSpec {
func NewBootstrapSpec(contractID string, donID uint64, donName string, relay RelayType, relayConfig RelayConfig, externalJobID uuid.UUID) *BootstrapSpec {
if externalJobID == uuid.Nil {
externalJobID = uuid.New()
}
return &BootstrapSpec{
Base: Base{
Name: "bootstrap",
Name: fmt.Sprintf("%s | %d", donName, donID),
Type: JobSpecTypeBootstrap,
SchemaVersion: 1,
ExternalJobID: externalJobID,
Expand Down
58 changes: 57 additions & 1 deletion deployment/data-streams/jobs/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,63 @@ chainID = '42161'
fromBlock = 283806260
`

func Test_Bootstrap(t *testing.T) {
func TestNewBootstrapSpec(t *testing.T) {
t.Parallel()

externalJobID := uuid.New()

tests := []struct {
name string
contractID string
donID uint64
donName string
relay RelayType
relayConfig RelayConfig
externalJobID uuid.UUID
want *BootstrapSpec
}{
{
name: "success",
contractID: "0x01",
donID: 123,
donName: "don-123",
relay: RelayTypeEVM,
relayConfig: RelayConfig{
ChainID: "234",
FromBlock: 345,
},
externalJobID: externalJobID,
want: &BootstrapSpec{
Base: Base{
Name: "don-123 | 123",
Type: JobSpecTypeBootstrap,
SchemaVersion: 1,
ExternalJobID: externalJobID,
},
ContractID: "0x01",
DonID: 123,
Relay: RelayTypeEVM,
RelayConfig: RelayConfig{
ChainID: "234",
FromBlock: 345,
}},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := NewBootstrapSpec(tc.contractID, tc.donID, tc.donName, tc.relay, tc.relayConfig, tc.externalJobID)
if got == nil {
t.Fatal("got nil")
}
if *got != *tc.want {
t.Errorf("got %v, want %v", got, tc.want)
}
})
}
}

func TestMarshalTOML(t *testing.T) {
t.Parallel()

bootstrapSpec := BootstrapSpec{
Expand Down
6 changes: 5 additions & 1 deletion deployment/data-streams/utils/identifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package utils

import (
"fmt"
"regexp"
)

const (
ProductLabel = "data-streams"
)

// DonIdentifier generates a unique identifier for a DON based on its ID and name.
// All non-alphanumeric characters are replaced with underscores due to the limiting requirements of
// Job Distributor label keys.
func DonIdentifier(donID uint64, donName string) string {
return fmt.Sprintf("don-%d-%s", donID, donName)
cleanDONName := regexp.MustCompile(`[^a-zA-Z0-9]+`).ReplaceAllString(donName, "_")
return fmt.Sprintf("don-%d-%s", donID, cleanDONName)
}
12 changes: 12 additions & 0 deletions deployment/environment/devenv/don.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ import (
"github.com/smartcontractkit/chainlink-protos/job-distributor/v1/shared/ptypes"
)

// All label keys:
// * must be non-empty,
// * must be 63 characters or less,
// * must begin and end with an alphanumeric character ([a-z0-9A-Z]),
// * could contain dashes (-), underscores (_), dots (.), and alphanumerics between.
//
// All label values:
// * must be 63 characters or less (can be empty),
// * unless empty, must begin and end with an alphanumeric character ([a-z0-9A-Z]),
// * could contain dashes (-), underscores (_), dots (.), and alphanumerics between.
//
// Source: https://github.com/smartcontractkit/job-distributor/blob/main/pkg/entities/labels.go
const (
LabelNodeTypeKey = "type"
LabelNodeTypeValueBootstrap = "bootstrap"
Expand Down
Loading