Skip to content

Commit 0e5ebb4

Browse files
authored
pkg/config: add func SizeOf; pkg/settings: defaults/types/comments (#1558)
1 parent ae45911 commit 0e5ebb4

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

pkg/capabilities/capabilities.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"google.golang.org/protobuf/proto"
1212
"google.golang.org/protobuf/types/known/anypb"
1313

14+
"github.com/smartcontractkit/chainlink-common/pkg/contexts"
1415
"github.com/smartcontractkit/chainlink-protos/cre/go/values"
1516
)
1617

@@ -108,13 +109,27 @@ type RequestMetadata struct {
108109
WorkflowTag string
109110
}
110111

112+
func (m *RequestMetadata) ContextWithCRE(ctx context.Context) context.Context {
113+
return contexts.WithCRE(ctx, contexts.CRE{
114+
Owner: m.WorkflowOwner,
115+
Workflow: m.WorkflowID,
116+
})
117+
}
118+
111119
type RegistrationMetadata struct {
112120
WorkflowID string
113121
WorkflowOwner string
114122
// The step reference ID of the workflow
115123
ReferenceID string
116124
}
117125

126+
func (m *RegistrationMetadata) ContextWithCRE(ctx context.Context) context.Context {
127+
return contexts.WithCRE(ctx, contexts.CRE{
128+
Owner: m.WorkflowOwner,
129+
Workflow: m.WorkflowID,
130+
})
131+
}
132+
118133
// CapabilityRequest is a struct for the Execute request of a capability.
119134
type CapabilityRequest struct {
120135
Metadata RequestMetadata

pkg/config/bytes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ var (
3232
}
3333
)
3434

35+
// SizeOf returns the cumulative len of the byte slice arguments as a Size.
36+
func SizeOf[B ~[]byte](bs ...B) (s Size) {
37+
for _, b := range bs {
38+
s += Size(len(b))
39+
}
40+
return
41+
}
42+
3543
func (b Size) MarshalText() ([]byte, error) {
3644
if b >= TByte {
3745
d := decimal.NewFromInt(int64(b)).Div(decimal.NewFromInt(int64(TByte)))

pkg/settings/cresettings/defaults.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"LogTrigger": {
4343
"RateLimit": "every10s:-1",
4444
"Limit": "5",
45-
"EventRateLimit": "every-1s:-1",
45+
"EventRateLimit": "every6s:10",
4646
"FilterAddressLimit": "5",
4747
"FilterTopicsPerSlotLimit": "10"
4848
},
@@ -58,7 +58,7 @@
5858
"TargetsLimit": "3",
5959
"ReportSizeLimit": "1kb",
6060
"EVM": {
61-
"TransactionGasLimit": "-1"
61+
"TransactionGasLimit": "500000"
6262
}
6363
},
6464
"ChainRead": {

pkg/settings/cresettings/defaults.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ RateLimit = 'every30s:3'
4343
[PerWorkflow.LogTrigger]
4444
RateLimit = 'every10s:-1'
4545
Limit = '5'
46-
EventRateLimit = 'every-1s:-1'
46+
EventRateLimit = 'every6s:10'
4747
FilterAddressLimit = '5'
4848
FilterTopicsPerSlotLimit = '10'
4949

@@ -60,7 +60,7 @@ TargetsLimit = '3'
6060
ReportSizeLimit = '1kb'
6161

6262
[PerWorkflow.ChainWrite.EVM]
63-
TransactionGasLimit = '-1'
63+
TransactionGasLimit = '500000'
6464

6565
[PerWorkflow.ChainRead]
6666
CallLimit = '3'

pkg/settings/cresettings/settings.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var Default = Schema{
7575
LogTrigger: logTrigger{
7676
RateLimit: Rate(rate.Every(10*time.Second), -1), //TODO
7777
Limit: Int(5),
78-
EventRateLimit: Rate(-1, -1), //TODO
78+
EventRateLimit: Rate(rate.Every(time.Minute/10), 10), // TODO
7979
FilterAddressLimit: Int(5),
8080
FilterTopicsPerSlotLimit: Int(10),
8181
},
@@ -91,12 +91,12 @@ var Default = Schema{
9191
TargetsLimit: Int(3),
9292
ReportSizeLimit: Size(config.KByte),
9393
EVM: evmChainWrite{
94-
TransactionGasLimit: Int(-1), //TODO
94+
TransactionGasLimit: Uint64(500_000), //TODO
9595
},
9696
},
9797
ChainRead: chainRead{
9898
CallLimit: Int(3),
99-
LogQueryBlockLimit: Int(100),
99+
LogQueryBlockLimit: Uint64(100),
100100
PayloadSizeLimit: Size(5 * config.KByte),
101101
},
102102
},
@@ -187,11 +187,11 @@ type chainWrite struct {
187187
EVM evmChainWrite
188188
}
189189
type evmChainWrite struct {
190-
TransactionGasLimit Setting[int] `unit:"{gas}"`
190+
TransactionGasLimit Setting[uint64] `unit:"{gas}"`
191191
}
192192

193193
type chainRead struct {
194-
CallLimit Setting[int] `unit:"{call}"`
195-
LogQueryBlockLimit Setting[int] `unit:"{block}"`
194+
CallLimit Setting[int] `unit:"{call}"`
195+
LogQueryBlockLimit Setting[uint64] `unit:"{block}"`
196196
PayloadSizeLimit Setting[config.Size]
197197
}

pkg/settings/cresettings/settings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ func TestSchema_Unmarshal(t *testing.T) {
109109
assert.Equal(t, config.Rate{Limit: rate.Every(13 * time.Second), Burst: 6}, cfg.PerWorkflow.LogTrigger.EventRateLimit.DefaultValue)
110110
assert.Equal(t, config.Rate{Limit: rate.Every(3 * time.Second), Burst: 5}, cfg.PerWorkflow.HTTPAction.RateLimit.DefaultValue)
111111
assert.Equal(t, 5*time.Minute, cfg.PerWorkflow.HTTPAction.CacheAgeLimit.DefaultValue)
112-
assert.Equal(t, 500000, cfg.PerWorkflow.ChainWrite.EVM.TransactionGasLimit.DefaultValue)
112+
assert.Equal(t, uint64(500000), cfg.PerWorkflow.ChainWrite.EVM.TransactionGasLimit.DefaultValue)
113113
assert.Equal(t, 3, cfg.PerWorkflow.ChainRead.CallLimit.DefaultValue)
114114
}

pkg/settings/limits/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type ResourceLimiter[N Number] interface {
2424
Use(ctx context.Context, amount N) error
2525
// Free is the counterpart to Use and releases amount of resources from use.
2626
Free(ctx context.Context, amount N) error
27-
// Available returns
27+
// Available returns the available remaining capacity.
2828
Available(ctx context.Context) (N, error)
2929
}
3030

0 commit comments

Comments
 (0)