Skip to content
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

Refactor DefaultCapConfig into multiple funcs #15882

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
325c42c
Refactors `DefaultCapConfig` into multiple funcs
vyzaldysanchez Jan 9, 2025
6bf725d
Fixes lint
vyzaldysanchez Jan 9, 2025
fc3075b
Merge branch 'develop' into task/CRE-58/generalize-default-cap-config
vyzaldysanchez Jan 9, 2025
eecfd33
Expects a `config` on `FromCapabilitiesRegistryCapability` calls
vyzaldysanchez Jan 9, 2025
56b82c7
Exposes `RegisteredCapabilityConfig` to consumers
vyzaldysanchez Jan 9, 2025
1a39088
Fixes lint
vyzaldysanchez Jan 9, 2025
940ec37
Exposes more needed types
vyzaldysanchez Jan 9, 2025
9333162
Expects bytes config as part of the `RegisteredCapability` struct
vyzaldysanchez Jan 10, 2025
1961f95
Uses bytes cap config on `RegisterDons()` calls
vyzaldysanchez Jan 10, 2025
c97ed1e
Fixes test
vyzaldysanchez Jan 10, 2025
e406844
Fixes CI
vyzaldysanchez Jan 10, 2025
c74668e
Fixes CI
vyzaldysanchez Jan 10, 2025
66ec891
Takes proto object instead of bytes on `FromCapabilitiesRegistryCapab…
vyzaldysanchez Jan 10, 2025
64e9222
Exposes `DONCapabilityWithConfig`
vyzaldysanchez Jan 10, 2025
c33ab50
Fixes lint
vyzaldysanchez Jan 13, 2025
8536b9e
Merge branch 'develop' into task/CRE-58/generalize-default-cap-config
vyzaldysanchez Jan 13, 2025
efed678
Fixes lint
vyzaldysanchez Jan 13, 2025
73c2aff
gomods tidy
vyzaldysanchez Jan 13, 2025
391ce07
Fixes CI
vyzaldysanchez Jan 14, 2025
67680f8
Fixes CI
vyzaldysanchez Jan 14, 2025
2ff2c55
gomods tidy
vyzaldysanchez Jan 14, 2025
03239d3
Merge remote-tracking branch 'origin/develop' into task/CRE-58/genera…
vyzaldysanchez Jan 16, 2025
7d1fc24
Updates typing
vyzaldysanchez Jan 20, 2025
faf902c
Fixes lint
vyzaldysanchez Jan 20, 2025
7107f0a
Fixes lint
vyzaldysanchez Jan 20, 2025
500a0df
Merge remote-tracking branch 'origin/develop' into task/CRE-58/genera…
vyzaldysanchez Jan 20, 2025
faed4ab
Refactors test util
vyzaldysanchez Jan 21, 2025
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
15 changes: 15 additions & 0 deletions deployment/keystone/changeset/compatiblity.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ var RegisterNodes = internal.RegisterNodes
// RegisteredCapability is a wrapper of a capability and its ID
type RegisteredCapability = internal.RegisteredCapability

// RegisteredCapabilityConfig is the configuration of a RegisteredCapability
type RegisteredCapabilityConfig = internal.RegisteredCapabilityConfig

// RegisteredCapabilityRemoteConfig is the remote configuration of a RegisteredCapability
type RegisteredCapabilityRemoteConfig = internal.RegisteredCapabilityRemoteConfig

// RegisteredCapabilityRemoteTargetConfig is the configuration of target capabilities
type RegisteredCapabilityRemoteTargetConfig = internal.RegisteredCapabilityRemoteTargetConfig

// RegisteredCapabilityRemoteTriggerConfig is the configuration of trigger capabilities
type RegisteredCapabilityRemoteTriggerConfig = internal.RegisteredCapabilityRemoteTriggerConfig

// RegisteredCapabilityRemoteExecutableConfig is the configuration of executable capabilities
type RegisteredCapabilityRemoteExecutableConfig = internal.RegisteredCapabilityRemoteExecutableConfig

// FromCapabilitiesRegistryCapability converts a capabilities registry capability to a registered capability
var FromCapabilitiesRegistryCapability = internal.FromCapabilitiesRegistryCapability

Expand Down
144 changes: 98 additions & 46 deletions deployment/keystone/changeset/internal/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,51 @@ type RegisterCapabilitiesResponse struct {

type RegisteredCapability struct {
capabilities_registry.CapabilitiesRegistryCapability
ID [32]byte
ID [32]byte
Config RegisteredCapabilityConfig
}

func FromCapabilitiesRegistryCapability(cap *capabilities_registry.CapabilitiesRegistryCapability, e deployment.Environment, registryChainSelector uint64) (*RegisteredCapability, error) {
type RegisteredCapabilityConfig struct {
DefaultConfig map[string]any
vyzaldysanchez marked this conversation as resolved.
Show resolved Hide resolved
RemoteConfig RegisteredCapabilityRemoteConfig
}

type RegisteredCapabilityRemoteConfig struct {
TargetConfig *RegisteredCapabilityRemoteTargetConfig
TriggerConfig *RegisteredCapabilityRemoteTriggerConfig
ExecutableConfig *RegisteredCapabilityRemoteExecutableConfig
}

type RegisteredCapabilityRemoteTriggerConfig struct {
vyzaldysanchez marked this conversation as resolved.
Show resolved Hide resolved
RegistrationRefresh time.Duration
RegistrationExpiry time.Duration
MinResponsesToAggregate uint32
MessageExpiry time.Duration
MaxBatchSize uint32
BatchCollectionPeriod time.Duration
}

type RegisteredCapabilityRemoteTargetConfig struct {
vyzaldysanchez marked this conversation as resolved.
Show resolved Hide resolved
RequestHashExcludedAttributes []string
}

type RegisteredCapabilityRemoteExecutableConfig struct {
RequestHashExcludedAttributes []string
}

func FromCapabilitiesRegistryCapability(capReg *capabilities_registry.CapabilitiesRegistryCapability, e deployment.Environment, registryChainSelector uint64, cfg RegisteredCapabilityConfig) (*RegisteredCapability, error) {
registry, _, err := GetRegistryContract(&e, registryChainSelector)
if err != nil {
return nil, fmt.Errorf("failed to get registry: %w", err)
}
id, err := registry.GetHashedCapabilityId(&bind.CallOpts{}, cap.LabelledName, cap.Version)
id, err := registry.GetHashedCapabilityId(&bind.CallOpts{}, capReg.LabelledName, capReg.Version)
if err != nil {
return nil, fmt.Errorf("failed to call GetHashedCapabilityId for capability %v: %w", cap, err)
return nil, fmt.Errorf("failed to call GetHashedCapabilityId for capability %v: %w", capReg, err)
}
return &RegisteredCapability{
CapabilitiesRegistryCapability: *cap,
CapabilitiesRegistryCapability: *capReg,
ID: id,
Config: cfg,
}, nil
}

Expand Down Expand Up @@ -575,39 +605,46 @@ func RegisterNOPS(ctx context.Context, lggr logger.Logger, req RegisterNOPSReque
return resp, nil
}

func DefaultCapConfig(capType uint8, nNodes int) *capabilitiespb.CapabilityConfig {
switch capType {
// TODO: use the enum defined in ??
case uint8(0): // trigger
return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(values.EmptyMap()).GetMapValue(),
RemoteConfig: &capabilitiespb.CapabilityConfig_RemoteTriggerConfig{
RemoteTriggerConfig: &capabilitiespb.RemoteTriggerConfig{
RegistrationRefresh: durationpb.New(20 * time.Second),
RegistrationExpiry: durationpb.New(60 * time.Second),
// F + 1; assuming n = 3f+1
MinResponsesToAggregate: uint32(nNodes/3) + 1,
},
},
}
case uint8(2): // consensus
return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(values.EmptyMap()).GetMapValue(),
}
case uint8(3): // target
return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(values.EmptyMap()).GetMapValue(),
RemoteConfig: &capabilitiespb.CapabilityConfig_RemoteTargetConfig{
RemoteTargetConfig: &capabilitiespb.RemoteTargetConfig{
RequestHashExcludedAttributes: []string{"signed_report.Signatures"}, // TODO: const defn in a common place
},
func GetTriggerCapConfig(refresh time.Duration, expiry time.Duration, minResponsesToAggregate uint32, defaultCfg map[string]any) (*capabilitiespb.CapabilityConfig, error) {
dCfg, err := values.WrapMap(defaultCfg)
vyzaldysanchez marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(dCfg).GetMapValue(),
RemoteConfig: &capabilitiespb.CapabilityConfig_RemoteTriggerConfig{
RemoteTriggerConfig: &capabilitiespb.RemoteTriggerConfig{
RegistrationRefresh: durationpb.New(refresh),
RegistrationExpiry: durationpb.New(expiry),
MinResponsesToAggregate: minResponsesToAggregate,
},
}
default:
return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(values.EmptyMap()).GetMapValue(),
}
},
}, nil
}

func GetConsensusCapConfig(defaultCfg map[string]any) (*capabilitiespb.CapabilityConfig, error) {
vyzaldysanchez marked this conversation as resolved.
Show resolved Hide resolved
dCfg, err := values.WrapMap(defaultCfg)
if err != nil {
return nil, err
}
return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(dCfg).GetMapValue(),
}, nil
}

func GetTargetCapConfig(defaultCfg map[string]any) (*capabilitiespb.CapabilityConfig, error) {
dCfg, err := values.WrapMap(defaultCfg)
if err != nil {
return nil, err
}
return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(dCfg).GetMapValue(),
RemoteConfig: &capabilitiespb.CapabilityConfig_RemoteTargetConfig{
RemoteTargetConfig: &capabilitiespb.RemoteTargetConfig{
RequestHashExcludedAttributes: []string{"signed_report.Signatures"}, // TODO: const defn in a common place
},
},
}, nil
}

// register nodes
Expand Down Expand Up @@ -836,24 +873,39 @@ func RegisterDons(lggr logger.Logger, req RegisterDonsRequest) (*RegisterDonsRes
continue
}

caps, ok := req.DonToCapabilities[don.Name]
regCaps, ok := req.DonToCapabilities[don.Name]
if !ok {
return nil, fmt.Errorf("capabilities not found for DON %s", don.Name)
}
wfSupported := false
var cfgs []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration
for _, cap := range caps {
if cap.CapabilityType == 2 { // OCR3 capability => WF supported
wfSupported = true
for _, regCap := range regCaps {
var capErr error
var capCfg *capabilitiespb.CapabilityConfig
switch regCap.CapabilityType {
case uint8(0): // trigger
cfg := regCap.Config.RemoteConfig.TriggerConfig
if cfg == nil {
return nil, fmt.Errorf("no trigger config found for %v", regCap)
}
capCfg, capErr = GetTriggerCapConfig(cfg.RegistrationRefresh, cfg.RegistrationExpiry, cfg.MinResponsesToAggregate, regCap.Config.DefaultConfig)
case uint8(2): // consensus
wfSupported = true // OCR3 capability => WF supported
capCfg, capErr = GetConsensusCapConfig(regCap.Config.DefaultConfig)
case uint8(3): // target
capCfg, capErr = GetTargetCapConfig(regCap.Config.DefaultConfig)
default:
return nil, fmt.Errorf("unsupported capability type %d for %v", regCap.CapabilityType, regCap)
}
// TODO: accept configuration from external source for each (don,capability)
capCfg := DefaultCapConfig(cap.CapabilityType, len(p2pIds))
cfgb, err := proto.Marshal(capCfg)
if err != nil {
return nil, fmt.Errorf("failed to marshal capability config for %v: %w", cap, err)
if capErr != nil {
return nil, fmt.Errorf("failed to get capability config for %v: %w", regCap, capErr)
}
cfgb, capErr := proto.Marshal(capCfg)
if capErr != nil {
return nil, fmt.Errorf("failed to marshal capability config for %v: %w", regCap, capErr)
}
cfgs = append(cfgs, capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{
CapabilityId: cap.ID,
CapabilityId: regCap.ID,
Config: cfgb,
})
}
Expand Down
26 changes: 10 additions & 16 deletions deployment/keystone/changeset/internal/update_don.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"sort"

"github.com/ethereum/go-ethereum/accounts/abi/bind"

"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock"
"google.golang.org/protobuf/proto"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"

"github.com/smartcontractkit/chainlink/deployment"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry_1_1_0"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)

// CapabilityConfig is a struct that holds a capability and its configuration
Expand Down Expand Up @@ -71,7 +70,7 @@ type UpdateDonResponse struct {
Ops *timelock.BatchChainOperation
}

func UpdateDon(lggr logger.Logger, req *UpdateDonRequest) (*UpdateDonResponse, error) {
func UpdateDon(_ logger.Logger, req *UpdateDonRequest) (*UpdateDonResponse, error) {
if err := req.Validate(); err != nil {
return nil, fmt.Errorf("failed to validate request: %w", err)
}
Expand All @@ -86,7 +85,7 @@ func UpdateDon(lggr logger.Logger, req *UpdateDonRequest) (*UpdateDonResponse, e
if err != nil {
return nil, fmt.Errorf("failed to lookup don by p2pIDs: %w", err)
}
cfgs, err := computeConfigs(registry, req.CapabilityConfigs, don)
cfgs, err := computeConfigs(registry, req.CapabilityConfigs)
if err != nil {
return nil, fmt.Errorf("failed to compute configs: %w", err)
}
Expand Down Expand Up @@ -140,22 +139,17 @@ func BytesToPeerIDs(p2pIDs [][32]byte) []p2pkey.PeerID {
return out
}

func computeConfigs(registry *kcr.CapabilitiesRegistry, caps []CapabilityConfig, donInfo kcr.CapabilitiesRegistryDONInfo) ([]kcr.CapabilitiesRegistryCapabilityConfiguration, error) {
out := make([]kcr.CapabilitiesRegistryCapabilityConfiguration, len(caps))
for i, cap := range caps {
func computeConfigs(registry *kcr.CapabilitiesRegistry, capCfgs []CapabilityConfig) ([]kcr.CapabilitiesRegistryCapabilityConfiguration, error) {
out := make([]kcr.CapabilitiesRegistryCapabilityConfiguration, len(capCfgs))
for i, capCfg := range capCfgs {
out[i] = kcr.CapabilitiesRegistryCapabilityConfiguration{}
id, err := registry.GetHashedCapabilityId(&bind.CallOpts{}, cap.Capability.LabelledName, cap.Capability.Version)
id, err := registry.GetHashedCapabilityId(&bind.CallOpts{}, capCfg.Capability.LabelledName, capCfg.Capability.Version)
if err != nil {
return nil, fmt.Errorf("failed to get capability id: %w", err)
}
out[i].CapabilityId = id
if out[i].Config == nil {
c := DefaultCapConfig(cap.Capability.CapabilityType, int(donInfo.F))
cb, err := proto.Marshal(c)
if err != nil {
return nil, fmt.Errorf("failed to marshal capability config for %v: %w", c, err)
}
out[i].Config = cb
return nil, fmt.Errorf("config is required for capability %s", capCfg.Capability.LabelledName)
}
}
return out, nil
Expand Down
Loading