Skip to content

Commit

Permalink
fix: rename limits and place it under [Workflows.Limits]
Browse files Browse the repository at this point in the history
  • Loading branch information
agparadiso committed Feb 17, 2025
1 parent a1dcf8f commit 0dff894
Show file tree
Hide file tree
Showing 31 changed files with 201 additions and 101 deletions.
1 change: 1 addition & 0 deletions core/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type AppConfig interface {
AuditLogger() AuditLogger
AutoPprof() AutoPprof
Capabilities() Capabilities
Workflows() Workflows
Database() Database
Feature() Feature
FluxMonitor() FluxMonitor
Expand Down
2 changes: 0 additions & 2 deletions core/config/capabilities_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type CapabilitiesWorkflowRegistry interface {
MaxBinarySize() utils.FileSize
MaxConfigSize() utils.FileSize
RelayID() types.RelayID
WorkflowsGlobal() int32
WorkflowsPerOwner() int32
}

type GatewayConnector interface {
Expand Down
11 changes: 6 additions & 5 deletions core/config/docs/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,12 @@ MaxEncryptedSecretsSize = '26.40kb' # Default
# MaxConfigSize is the maximum size of a config that can be fetched from the given config url.
MaxConfigSize = '50.00kb' # Default

[Capabilities.WorkflowRegistry.Limits]
# WorkflowsGlobal is the maximum number of workflows that can be registered globally.
WorkflowsGlobal = 50 # Default
# WorkflowsPerOwner is the maximum number of workflows that can be registered per owner.
WorkflowsPerOwner = 5 # Default
[Workflows]
[Workflows.Limits]
# Global is the maximum number of workflows that can be registered globally.
Global = 50 # Default
# PerOwner is the maximum number of workflows that can be registered per owner.
PerOwner = 5 # Default

[Capabilities.ExternalRegistry]
# Address is the address for the capabilities registry contract.
Expand Down
29 changes: 18 additions & 11 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Core struct {
Mercury Mercury `toml:",omitempty"`
Capabilities Capabilities `toml:",omitempty"`
Telemetry Telemetry `toml:",omitempty"`
Workflows Workflows `toml:",omitempty"`
}

// SetFrom updates c with any non-nil values from f. (currently TOML field only!)
Expand Down Expand Up @@ -87,6 +88,7 @@ func (c *Core) SetFrom(f *Core) {
c.Keeper.setFrom(&f.Keeper)
c.Mercury.setFrom(&f.Mercury)
c.Capabilities.setFrom(&f.Capabilities)
c.Workflows.setFrom(&f.Workflows)

c.AutoPprof.setFrom(&f.AutoPprof)
c.Pyroscope.setFrom(&f.Pyroscope)
Expand Down Expand Up @@ -1487,18 +1489,26 @@ func (r *ExternalRegistry) setFrom(f *ExternalRegistry) {
}
}

type WorkflowLimits struct {
WorkflowsGlobal *int32
WorkflowsPerOwner *int32
type Workflows struct {
Limits Limits
}

func (r *WorkflowLimits) setFrom(f *WorkflowLimits) {
if f.WorkflowsGlobal != nil {
r.WorkflowsGlobal = f.WorkflowsGlobal
type Limits struct {
Global *int32
PerOwner *int32
}

func (r *Workflows) setFrom(f *Workflows) {
r.Limits.setFrom(&f.Limits)
}

func (r *Limits) setFrom(f *Limits) {
if f.Global != nil {
r.Global = f.Global
}

if f.WorkflowsPerOwner != nil {
r.WorkflowsPerOwner = f.WorkflowsPerOwner
if f.PerOwner != nil {
r.PerOwner = f.PerOwner
}
}

Expand All @@ -1509,7 +1519,6 @@ type WorkflowRegistry struct {
MaxBinarySize *utils.FileSize
MaxEncryptedSecretsSize *utils.FileSize
MaxConfigSize *utils.FileSize
Limits WorkflowLimits
}

func (r *WorkflowRegistry) setFrom(f *WorkflowRegistry) {
Expand All @@ -1536,8 +1545,6 @@ func (r *WorkflowRegistry) setFrom(f *WorkflowRegistry) {
if f.MaxConfigSize != nil {
r.MaxConfigSize = f.MaxConfigSize
}

r.Limits.setFrom(&f.Limits)
}

type Dispatcher struct {
Expand Down
10 changes: 10 additions & 0 deletions core/config/workflows_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package config

type Workflows interface {
Limits() WorkflowsLimits
}

type WorkflowsLimits interface {
Global() int32
PerOwner() int32
}
4 changes: 2 additions & 2 deletions core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
}

workflowLimits, err := syncerlimiter.NewWorkflowLimits(syncerlimiter.Config{
Global: cfg.Capabilities().WorkflowRegistry().WorkflowsGlobal(),
PerOwner: cfg.Capabilities().WorkflowRegistry().WorkflowsPerOwner(),
Global: cfg.Workflows().Limits().Global(),
PerOwner: cfg.Workflows().Limits().PerOwner(),
})
if err != nil {
return nil, fmt.Errorf("could not instantiate workflow syncer limiter: %w", err)
Expand Down
8 changes: 0 additions & 8 deletions core/services/chainlink/config_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@ func (c *capabilitiesWorkflowRegistry) MaxConfigSize() utils.FileSize {
return *c.c.MaxConfigSize
}

func (c *capabilitiesWorkflowRegistry) WorkflowsGlobal() int32 {
return *c.c.Limits.WorkflowsGlobal
}

func (c *capabilitiesWorkflowRegistry) WorkflowsPerOwner() int32 {
return *c.c.Limits.WorkflowsPerOwner
}

type gatewayConnector struct {
c toml.GatewayConnector
}
Expand Down
4 changes: 4 additions & 0 deletions core/services/chainlink/config_general.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ func (g *generalConfig) Capabilities() config.Capabilities {
return &capabilitiesConfig{c: g.c.Capabilities}
}

func (g *generalConfig) Workflows() config.Workflows {
return &workflowsConfig{c: g.c.Workflows}
}

func (g *generalConfig) Database() coreconfig.Database {
return &databaseConfig{c: g.c.Database, s: g.secrets.Secrets.Database, logSQL: g.logSQL}
}
Expand Down
17 changes: 13 additions & 4 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ var (
AutoPprof: toml.AutoPprof{
CPUProfileRate: ptr[int64](7),
},
Workflows: toml.Workflows{
Limits: toml.Limits{
Global: ptr(int32(50)),
PerOwner: ptr(int32(5)),
},
},
},
EVM: []*evmcfg.EVMConfig{
{
Expand Down Expand Up @@ -478,10 +484,6 @@ func TestConfig_Marshal(t *testing.T) {
MaxBinarySize: ptr(utils.FileSize(20 * utils.MB)),
MaxEncryptedSecretsSize: ptr(utils.FileSize(26.4 * utils.KB)),
MaxConfigSize: ptr(utils.FileSize(50 * utils.KB)),
Limits: toml.WorkflowLimits{
WorkflowsGlobal: ptr(int32(50)),
WorkflowsPerOwner: ptr(int32(5)),
},
},
Dispatcher: toml.Dispatcher{
SupportedVersion: ptr(1),
Expand All @@ -505,6 +507,12 @@ func TestConfig_Marshal(t *testing.T) {
},
},
}
full.Workflows = toml.Workflows{
Limits: toml.Limits{
Global: ptr(int32(50)),
PerOwner: ptr(int32(5)),
},
}
full.Keeper = toml.Keeper{
DefaultTransactionQueueDepth: ptr[uint32](17),
GasPriceBufferPercent: ptr[uint16](12),
Expand Down Expand Up @@ -1696,6 +1704,7 @@ func TestConfig_setDefaults(t *testing.T) {
c.Solana = solcfg.TOMLConfigs{{ChainID: ptr("unknown solana chain")}}
c.Starknet = RawConfigs{{"ChainID": ptr("unknown starknet chain")}}
c.setDefaults()

if s, err := c.TOMLString(); assert.NoError(t, err) {
t.Log(s, err)
}
Expand Down
30 changes: 30 additions & 0 deletions core/services/chainlink/config_workflows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package chainlink

import (
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
)

var _ config.Workflows = (*workflowsConfig)(nil)

type workflowsConfig struct {
c toml.Workflows
}

func (w *workflowsConfig) Limits() config.WorkflowsLimits {
return &limits{
l: w.c.Limits,
}
}

type limits struct {
l toml.Limits
}

func (l *limits) Global() int32 {
return *l.l.Global
}

func (l *limits) PerOwner() int32 {
return *l.l.PerOwner
}
20 changes: 20 additions & 0 deletions core/services/chainlink/config_workflows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package chainlink

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestWorkflowsConfig(t *testing.T) {
opts := GeneralConfigOpts{
ConfigStrings: []string{fullTOML},
}
cfg, err := opts.New()
require.NoError(t, err)

w := cfg.Workflows()
assert.Equal(t, int32(50), w.Limits().Global())
assert.Equal(t, int32(5), w.Limits().PerOwner())
}
9 changes: 5 additions & 4 deletions core/services/chainlink/testdata/config-empty-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ MaxBinarySize = '20.00mb'
MaxEncryptedSecretsSize = '26.40kb'
MaxConfigSize = '50.00kb'

[Capabilities.WorkflowRegistry.Limits]
WorkflowsGlobal = 50
WorkflowsPerOwner = 5

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
NodeAddress = ''
Expand All @@ -311,3 +307,8 @@ InsecureConnection = false
TraceSampleRatio = 0.01
EmitterBatchProcessor = true
EmitterExportTimeout = '1s'

[Workflows]
[Workflows.Limits]
Global = 50
PerOwner = 5
9 changes: 5 additions & 4 deletions core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ MaxBinarySize = '20.00mb'
MaxEncryptedSecretsSize = '26.40kb'
MaxConfigSize = '50.00kb'

[Capabilities.WorkflowRegistry.Limits]
WorkflowsGlobal = 50
WorkflowsPerOwner = 5

[Capabilities.GatewayConnector]
ChainIDForNodeKey = '11155111'
NodeAddress = '0x68902d681c28119f9b2531473a417088bf008e59'
Expand All @@ -326,6 +322,11 @@ EmitterExportTimeout = '1s'
Baz = 'test'
Foo = 'bar'

[Workflows]
[Workflows.Limits]
Global = 50
PerOwner = 5

[[EVM]]
ChainID = '1'
Enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ MaxBinarySize = '20.00mb'
MaxEncryptedSecretsSize = '26.40kb'
MaxConfigSize = '50.00kb'

[Capabilities.WorkflowRegistry.Limits]
WorkflowsGlobal = 50
WorkflowsPerOwner = 5

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
NodeAddress = ''
Expand All @@ -312,6 +308,11 @@ TraceSampleRatio = 0.01
EmitterBatchProcessor = true
EmitterExportTimeout = '1s'

[Workflows]
[Workflows.Limits]
Global = 50
PerOwner = 5

[[EVM]]
ChainID = '1'
AutoCreateKey = true
Expand Down
5 changes: 5 additions & 0 deletions core/services/chainlink/testdata/config-multi-chain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ GasPriceBufferPercent = 10
[AutoPprof]
CPUProfileRate = 7

[Workflows]
[Workflows.Limits]
Global = 50
PerOwner = 5

[[EVM]]
ChainID = '1'
FinalityDepth = 26
Expand Down
8 changes: 4 additions & 4 deletions core/services/workflows/syncerlimiter/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

const (
defaultWorkflowsGlobal = 50
defaultWorkflowsPerOwner = 5
defaultGlobal = 50
defaultPerOwner = 5
)

type Limits struct {
Expand All @@ -23,8 +23,8 @@ type Config struct {

func NewWorkflowLimits(config Config) (*Limits, error) {
if config.Global <= 0 || config.PerOwner <= 0 {
config.Global = defaultWorkflowsGlobal
config.PerOwner = defaultWorkflowsPerOwner
config.Global = defaultGlobal
config.PerOwner = defaultPerOwner
}

return &Limits{
Expand Down
7 changes: 4 additions & 3 deletions core/web/resolver/testdata/config-empty-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ MaxBinarySize = '20.00mb'
MaxEncryptedSecretsSize = '26.40kb'
MaxConfigSize = '50.00kb'

[Capabilities.WorkflowRegistry.Limits]
WorkflowsGlobal = 50
WorkflowsPerOwner = 5
[Workflows]
[Workflows.Limits]
Global = 50
PerOwner = 5

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
Expand Down
9 changes: 5 additions & 4 deletions core/web/resolver/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ MaxBinarySize = '20.00mb'
MaxEncryptedSecretsSize = '26.40kb'
MaxConfigSize = '50.00kb'

[Capabilities.WorkflowRegistry.Limits]
WorkflowsGlobal = 50
WorkflowsPerOwner = 5

[Capabilities.GatewayConnector]
ChainIDForNodeKey = '11155111'
NodeAddress = '0x68902d681c28119f9b2531473a417088bf008e59'
Expand All @@ -326,6 +322,11 @@ EmitterExportTimeout = '1s'
Baz = 'test'
Foo = 'bar'

[Workflows]
[Workflows.Limits]
Global = 50
PerOwner = 5

[[EVM]]
ChainID = '1'
Enabled = false
Expand Down
7 changes: 4 additions & 3 deletions core/web/resolver/testdata/config-multi-chain-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ MaxBinarySize = '20.00mb'
MaxEncryptedSecretsSize = '26.40kb'
MaxConfigSize = '50.00kb'

[Capabilities.WorkflowRegistry.Limits]
WorkflowsGlobal = 50
WorkflowsPerOwner = 5
[Workflows]
[Workflows.Limits]
Global = 50
PerOwner = 5

[Capabilities.GatewayConnector]
ChainIDForNodeKey = ''
Expand Down
Loading

0 comments on commit 0dff894

Please sign in to comment.