Skip to content
Draft
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
19 changes: 19 additions & 0 deletions core/capabilities/localcapmgr/offchain_cutover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ func TestReconcile_EffectiveSpecConfigPrecedence(t *testing.T) {
}))
assert.Empty(t, rec.all())
})

t.Run("gate on: capability only in the offchain payload is not launched", func(t *testing.T) {
t.Parallel()
// The payload configures consensus on DON 7, but the on-chain registry only has cron there.
// The on-chain registry (plus the allowlist) decides what runs; the payload supplies config.
gc := globalconfig.New()
storeOffchain(t, gc, 1, map[uint32]map[string]*capabilitiespb.CapabilityConfig{
7: {
"cron@1.0.0": specConfigCap(t, map[string]any{"interval": "30"}),
"consensus@1.0.0": specConfigCap(t, map[string]any{"k": "v"}),
},
})
m, rec := newCutoverManager(t, localCfg(), gc, true)
require.NoError(t, m.reconcile(t.Context(), []registry.DON{
onchainDONWith(7, map[string]registry.CapabilityConfiguration{"cron@1.0.0": onchain}),
}))
assert.Equal(t, map[string]any{"interval": "30"}, rec.configFor(t, "cron@1.0.0", 7))
assert.Len(t, rec.all(), 1)
})
}

// TestReconcile_OCR3StaysOnchain asserts that with the gate on, the OCR3 config handed to the
Expand Down
41 changes: 41 additions & 0 deletions core/services/standardcapabilities/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package standardcapabilities
import (
"context"
"crypto"
"encoding/json"
"fmt"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -311,6 +313,13 @@ func (d *Delegate) NewServices(
}
}

// Registry-launched EVM capabilities share one spec_config across the DON, so the per-node
// nodeAddress monitoring label is filled in here from this node's OCR3 transmitter.
configJSON, err = withEVMNodeAddress(configJSON, capabilityID, transmitter)
if err != nil {
return nil, fmt.Errorf("failed to set EVM nodeAddress: %w", err)
}

// Always resolve the oracle factory config to fill in any missing fields
// (contract address, chain ID, key bundle, transmitter, signing strategy).
// Job spec values take precedence; empty fields are resolved from the
Expand Down Expand Up @@ -413,6 +422,38 @@ func (d *Delegate) NewServices(
return []job.ServiceCtx{standardCapability}, nil
}

// withEVMNodeAddress sets "nodeAddress" in an EVM capability's config JSON to transmitter when the
// config does not already provide one. It is a no-op for other capabilities, an empty transmitter,
// empty config, or an explicitly configured nodeAddress. Other keys are preserved untouched.
func withEVMNodeAddress(configJSON, capabilityID, transmitter string) (string, error) {
const key = "nodeAddress"
if !strings.HasPrefix(capabilityID, "evm:") || transmitter == "" {
return configJSON, nil
}

cfg := map[string]json.RawMessage{}
if strings.TrimSpace(configJSON) != "" {
if err := json.Unmarshal([]byte(configJSON), &cfg); err != nil {
return "", fmt.Errorf("config is not a JSON object: %w", err)
}
}
var existing string
if raw, ok := cfg[key]; ok && json.Unmarshal(raw, &existing) == nil && existing != "" {
return configJSON, nil
}

addr, err := json.Marshal(transmitter)
if err != nil {
return "", err
}
cfg[key] = addr
out, err := json.Marshal(cfg)
if err != nil {
return "", err
}
return string(out), nil
}

func (d *Delegate) newServicesV2(ctx context.Context, log logger.Logger, command, app, configJSON string, capabilityDonID uint32) ([]job.ServiceCtx, error) {
// The capability ID depends on the capability, not on how it runs, so look it up by app name.
capabilityID := conversions.GetCapabilityIDFromCommand(app, configJSON)
Expand Down
45 changes: 45 additions & 0 deletions core/services/standardcapabilities/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,48 @@ func (s *stubLocalCapabilities) RegistryBasedLaunchAllowlist() []string { return
func (s *stubLocalCapabilities) IsAllowlisted(capabilityID string) bool {
return s.allowlisted[capabilityID]
}

func TestWithEVMNodeAddress(t *testing.T) {
t.Parallel()
const evmID = "evm:ChainSelector:1@1.0.0"

t.Run("fills nodeAddress when absent and keeps other keys", func(t *testing.T) {
t.Parallel()
out, err := withEVMNodeAddress(`{"chainId":1337,"network":"evm"}`, evmID, "0xabc")
require.NoError(t, err)
assert.JSONEq(t, `{"chainId":1337,"network":"evm","nodeAddress":"0xabc"}`, out)
})
t.Run("fills nodeAddress when empty", func(t *testing.T) {
t.Parallel()
out, err := withEVMNodeAddress(`{"nodeAddress":""}`, evmID, "0xabc")
require.NoError(t, err)
assert.JSONEq(t, `{"nodeAddress":"0xabc"}`, out)
})
t.Run("keeps configured nodeAddress", func(t *testing.T) {
t.Parallel()
in := `{"nodeAddress":"0xconfigured"}`
out, err := withEVMNodeAddress(in, evmID, "0xabc")
require.NoError(t, err)
assert.Equal(t, in, out)
})
t.Run("empty config becomes an object", func(t *testing.T) {
t.Parallel()
out, err := withEVMNodeAddress("", evmID, "0xabc")
require.NoError(t, err)
assert.JSONEq(t, `{"nodeAddress":"0xabc"}`, out)
})
t.Run("no-op for non-EVM capabilities and empty transmitter", func(t *testing.T) {
t.Parallel()
out, err := withEVMNodeAddress(`{"a":1}`, "aptos:ChainSelector:1@1.0.0", "0xabc")
require.NoError(t, err)
assert.Equal(t, `{"a":1}`, out)
out, err = withEVMNodeAddress(`{"a":1}`, evmID, "")
require.NoError(t, err)
assert.Equal(t, `{"a":1}`, out)
})
t.Run("rejects non-object config", func(t *testing.T) {
t.Parallel()
_, err := withEVMNodeAddress(`[1]`, evmID, "0xabc")
require.Error(t, err)
})
}
66 changes: 56 additions & 10 deletions system-tests/lib/cre/don/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"maps"
"math/big"
"regexp"
"slices"
"strconv"
"strings"
Expand All @@ -31,6 +32,7 @@ import (
aptoschain "github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment/blockchains/aptos"
"github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment/blockchains/solana"
stellchain "github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment/blockchains/stellar"
"github.com/smartcontractkit/chainlink/system-tests/lib/cre/flags"
"github.com/smartcontractkit/chainlink/system-tests/lib/infra"
coretoml "github.com/smartcontractkit/chainlink/v2/core/config/toml"
corechainlink "github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
Expand Down Expand Up @@ -475,6 +477,13 @@ func addWorkerNodeConfig(
}
}

// EVM, Aptos and Stellar chain capabilities are launched from their registry spec_config, not job specs.
for _, id := range chainCapabilityAllowlistEntries(donMetadata, commonInputs) {
if !slices.Contains(existingConfig.Capabilities.Local.RegistryBasedLaunchAllowlist, id) {
existingConfig.Capabilities.Local.RegistryBasedLaunchAllowlist = append(existingConfig.Capabilities.Local.RegistryBasedLaunchAllowlist, id)
}
}

for _, evmChain := range commonInputs.evmChains {
appendEVMChain(&existingConfig.EVM, evmChain)
}
Expand Down Expand Up @@ -666,8 +675,9 @@ type versionedAddress struct {
}

type aptosChain struct {
ChainID string
NodeURL string
ChainID string
ChainSelector uint64
NodeURL string
}

type commonInputs struct {
Expand Down Expand Up @@ -800,9 +810,10 @@ func findOneSolanaChain(input cre.GenerateConfigsInput) (*solanaChain, error) {
const stellarMaxResourceFeeStroops = int64(10_000_000)

type stellarChain struct {
Name string
ChainID string
NodeURL string
Name string
ChainID string
ChainSelector uint64
NodeURL string
}

func findOneStellarChain(input cre.GenerateConfigsInput) (*stellarChain, error) {
Expand Down Expand Up @@ -830,15 +841,49 @@ func findOneStellarChain(input cre.GenerateConfigsInput) (*stellarChain, error)
}

stChain = &stellarChain{
Name: fmt.Sprintf("node-%d", stBc.ChainSelector()),
ChainID: stBc.StellarChainID(), // string network id with a corresponding chain selector
NodeURL: nodeURL,
Name: fmt.Sprintf("node-%d", stBc.ChainSelector()),
ChainID: stBc.StellarChainID(), // string network id with a corresponding chain selector
ChainSelector: stBc.ChainSelector(),
NodeURL: nodeURL,
}
}

return stChain, nil
}

// chainCapabilityAllowlistEntries returns the RegistryBasedLaunchAllowlist patterns for the chain
// capabilities enabled on the DON. EVM is allowlisted by family; Aptos and Stellar per chain.
// Solana stays on job specs.
func chainCapabilityAllowlistEntries(donMetadata *cre.DonMetadata, inputs *commonInputs) []string {
entries := make([]string, 0)

for _, evmChain := range inputs.evmChains {
if flags.HasFlagForChain(donMetadata.Flags, cre.EVMCapability, evmChain.ChainID) {
entries = append(entries, "^evm:ChainSelector:")
break
}
}

for _, ac := range inputs.aptosChains {
chainID, err := strconv.ParseUint(ac.ChainID, 10, 64)
if err != nil || !flags.HasFlagForChain(donMetadata.Flags, cre.AptosCapability, chainID) {
continue
}
entries = append(entries, exactCapabilityIDPattern("aptos:ChainSelector:"+strconv.FormatUint(ac.ChainSelector, 10)+"@1.0.0"))
}

if donMetadata.HasFlag(cre.StellarCapability) && inputs.stellarChain != nil {
entries = append(entries, exactCapabilityIDPattern("stellar:ChainSelector:"+strconv.FormatUint(inputs.stellarChain.ChainSelector, 10)+"@1.0.0"))
}

return entries
}

// exactCapabilityIDPattern anchors a capability ID so the allowlist (a regex) matches only it.
func exactCapabilityIDPattern(id string) string {
return "^" + regexp.QuoteMeta(id) + "$"
}

func findAptosChains(input cre.GenerateConfigsInput) ([]*aptosChain, error) {
capabilityChainIDs := input.DonMetadata.MustNodeSet().ChainCapabilityChainIDs()
out := make([]*aptosChain, 0)
Expand All @@ -860,8 +905,9 @@ func findAptosChains(input cre.GenerateConfigsInput) ([]*aptosChain, error) {
}

out = append(out, &aptosChain{
ChainID: strconv.FormatUint(bcOut.ChainID(), 10),
NodeURL: nodeURL,
ChainID: strconv.FormatUint(bcOut.ChainID(), 10),
ChainSelector: aptosBC.ChainSelector(),
NodeURL: nodeURL,
})
}
return out, nil
Expand Down
67 changes: 67 additions & 0 deletions system-tests/lib/cre/don/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"regexp"
"strconv"
"testing"

Expand Down Expand Up @@ -183,6 +184,72 @@ func TestAddWorkerNodeConfig_HTTPRegistryLaunch(t *testing.T) {
assert.Len(t, config.Capabilities.Local.RegistryBasedLaunchAllowlist, 3)
}

func TestAddWorkerNodeConfig_ChainCapabilitiesRegistryLaunch(t *testing.T) {
t.Parallel()
don := capabilitiesDonMetadata()
don.Flags = append(don.Flags, cre.EVMCapability+"-1337", cre.AptosCapability+"-4", cre.StellarCapability)
don.RegistryBasedLaunchAllowlist = []string{"cron-trigger@1.0.0"}
inputs := capabilitiesCommonInputs("chip-router:50051")
inputs.evmChains = []*evmChain{{Name: "evm", ChainID: 1337}, {Name: "evm-other", ChainID: 2337}}
inputs.aptosChains = []*aptosChain{
{ChainID: "4", ChainSelector: 4457093679053095497},
{ChainID: "8", ChainSelector: 999}, // chain without the capability enabled
}
inputs.stellarChain = &stellarChain{Name: "stellar", ChainID: "net", ChainSelector: 7777}
node := &cre.NodeMetadata{Index: 0, Roles: []string{cre.WorkerNode}}

config, err := addWorkerNodeConfig(corechainlink.Config{}, nil, testPeeringData(), inputs, don, node)
require.NoError(t, err)
assert.Equal(t, []string{
"cron-trigger@1.0.0",
"^evm:ChainSelector:",
`^aptos:ChainSelector:4457093679053095497@1\.0\.0$`,
`^stellar:ChainSelector:7777@1\.0\.0$`,
}, config.Capabilities.Local.RegistryBasedLaunchAllowlist)

// Reapplying configuration must not duplicate registry launch entries.
config, err = addWorkerNodeConfig(config, nil, testPeeringData(), inputs, don, node)
require.NoError(t, err)
assert.Len(t, config.Capabilities.Local.RegistryBasedLaunchAllowlist, 4)
}

func TestAddWorkerNodeConfig_ChainCapabilitiesNotAllowlistedWithoutFlags(t *testing.T) {
t.Parallel()
inputs := capabilitiesCommonInputs("chip-router:50051")
inputs.evmChains = []*evmChain{{Name: "evm", ChainID: 1337}}
inputs.aptosChains = []*aptosChain{{ChainID: "4", ChainSelector: 1}}
inputs.stellarChain = &stellarChain{Name: "stellar", ChainID: "net", ChainSelector: 2}

config, err := addWorkerNodeConfig(corechainlink.Config{}, nil, testPeeringData(), inputs, capabilitiesDonMetadata(), &cre.NodeMetadata{Index: 0, Roles: []string{cre.WorkerNode}})
require.NoError(t, err)
assert.Empty(t, config.Capabilities.Local.RegistryBasedLaunchAllowlist)
}

func TestChainCapabilityAllowlistMatchesCapabilityIDs(t *testing.T) {
t.Parallel()
don := capabilitiesDonMetadata()
don.Flags = append(don.Flags, cre.EVMCapability+"-1337", cre.AptosCapability+"-4", cre.StellarCapability)
inputs := capabilitiesCommonInputs("chip-router:50051")
inputs.evmChains = []*evmChain{{ChainID: 1337}}
inputs.aptosChains = []*aptosChain{{ChainID: "4", ChainSelector: 11}}
inputs.stellarChain = &stellarChain{ChainSelector: 22}

matches := func(id string) bool {
for _, p := range chainCapabilityAllowlistEntries(don, inputs) {
if regexp.MustCompile(p).MatchString(id) {
return true
}
}
return false
}
assert.True(t, matches("evm:ChainSelector:12345@1.0.0"))
assert.True(t, matches("aptos:ChainSelector:11@1.0.0"))
assert.True(t, matches("stellar:ChainSelector:22@1.0.0"))
assert.False(t, matches("aptos:ChainSelector:111@1.0.0"), "must not match another selector sharing a prefix")
assert.False(t, matches("aptos:ChainSelector:11@1.0.1"))
assert.False(t, matches("solana:ChainSelector:11@1.0.0"), "solana stays on job specs")
}

// TestAddWorkerNodeConfig_ConsensusQueueRegistryLaunch asserts a DON with the consensus-queue flag gets it on the
// registry launch allowlist exactly once, next to the topology's own entries.
func TestAddWorkerNodeConfig_ConsensusQueueRegistryLaunch(t *testing.T) {
Expand Down
Loading
Loading