-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathconfig.go
1180 lines (1065 loc) · 33.5 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package toml
import (
"errors"
"fmt"
"net/url"
"slices"
"strconv"
"time"
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/pelletier/go-toml/v2"
"github.com/shopspring/decimal"
"go.uber.org/multierr"
"gopkg.in/guregu/null.v4"
commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)
var (
ErrNotFound = errors.New("not found")
)
type HasEVMConfigs interface {
EVMConfigs() EVMConfigs
}
type EVMConfigs []*EVMConfig
func (cs EVMConfigs) ValidateConfig() (err error) {
return cs.validateKeys()
}
func (cs EVMConfigs) validateKeys() (err error) {
// Unique chain IDs
chainIDs := commonconfig.UniqueStrings{}
for i, c := range cs {
if chainIDs.IsDupeFmt(c.ChainID) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), c.ChainID.String()))
}
}
// Unique node names
names := commonconfig.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
if names.IsDupe(n.Name) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
}
}
}
// Unique node WSURLs
wsURLs := commonconfig.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
u := (*url.URL)(n.WSURL)
if wsURLs.IsDupeFmt(u) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.WSURL", i, j), u.String()))
}
}
}
// Unique node HTTPURLs
httpURLs := commonconfig.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
u := (*url.URL)(n.HTTPURL)
if httpURLs.IsDupeFmt(u) {
err = multierr.Append(err, commonconfig.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.HTTPURL", i, j), u.String()))
}
}
}
return
}
func (cs *EVMConfigs) SetFrom(fs *EVMConfigs) (err error) {
if err1 := fs.validateKeys(); err1 != nil {
return err1
}
for _, f := range *fs {
if f.ChainID == nil {
*cs = append(*cs, f)
} else if i := slices.IndexFunc(*cs, func(c *EVMConfig) bool {
return c.ChainID != nil && c.ChainID.Cmp(f.ChainID) == 0
}); i == -1 {
*cs = append(*cs, f)
} else {
(*cs)[i].SetFrom(f)
}
}
return
}
func (cs EVMConfigs) totalChains() int {
total := 0
for _, ch := range cs {
if ch == nil {
continue
}
total++
}
return total
}
func (cs EVMConfigs) Chains(ids ...string) (r []commontypes.ChainStatus, total int, err error) {
total = cs.totalChains()
for _, ch := range cs {
if ch == nil {
continue
}
chainID := ch.ChainID.String()
if len(ids) > 0 {
var match bool
for _, id := range ids {
if id == chainID {
match = true
break
}
}
if !match {
continue
}
}
ch2 := commontypes.ChainStatus{
ID: ch.ChainID.String(),
Enabled: ch.IsEnabled(),
}
ch2.Config, err = ch.TOMLString()
if err != nil {
return
}
r = append(r, ch2)
}
return
}
func (cs EVMConfigs) Node(name string) (types.Node, error) {
for i := range cs {
for _, n := range cs[i].Nodes {
if n.Name != nil && *n.Name == name {
return legacyNode(n, cs[i].ChainID), nil
}
}
}
return types.Node{}, fmt.Errorf("node %s: %w", name, ErrNotFound)
}
func (cs EVMConfigs) NodeStatus(name string) (commontypes.NodeStatus, error) {
for i := range cs {
for _, n := range cs[i].Nodes {
if n.Name != nil && *n.Name == name {
return nodeStatus(n, cs[i].ChainID.String())
}
}
}
return commontypes.NodeStatus{}, fmt.Errorf("node %s: %w", name, ErrNotFound)
}
func legacyNode(n *Node, chainID *big.Big) (v2 types.Node) {
v2.Name = *n.Name
v2.EVMChainID = *chainID
if n.HTTPURL != nil {
v2.HTTPURL = null.StringFrom(n.HTTPURL.String())
}
if n.WSURL != nil {
v2.WSURL = null.StringFrom(n.WSURL.String())
}
if n.SendOnly != nil {
v2.SendOnly = *n.SendOnly
}
if n.Order != nil {
v2.Order = *n.Order
}
return
}
func nodeStatus(n *Node, chainID string) (commontypes.NodeStatus, error) {
var s commontypes.NodeStatus
s.ChainID = chainID
s.Name = *n.Name
b, err := toml.Marshal(n)
if err != nil {
return commontypes.NodeStatus{}, err
}
s.Config = string(b)
return s, nil
}
func (cs EVMConfigs) nodes(id string) (ns EVMNodes) {
for _, c := range cs {
if c.ChainID.String() == id {
return c.Nodes
}
}
return nil
}
func (cs EVMConfigs) Nodes(chainID string) (ns []types.Node, err error) {
evmID, err := ChainIDInt64(chainID)
if err != nil {
return nil, fmt.Errorf("invalid evm chain id %q : %w", chainID, err)
}
nodes := cs.nodes(chainID)
if nodes == nil {
err = fmt.Errorf("no nodes: chain %q: %w", chainID, ErrNotFound)
return
}
for _, n := range nodes {
if n == nil {
continue
}
ns = append(ns, legacyNode(n, big.NewI(evmID)))
}
return
}
func (cs EVMConfigs) NodeStatuses(chainIDs ...string) (ns []commontypes.NodeStatus, err error) {
if len(chainIDs) == 0 {
for i := range cs {
for _, n := range cs[i].Nodes {
if n == nil {
continue
}
n2, err := nodeStatus(n, cs[i].ChainID.String())
if err != nil {
return nil, err
}
ns = append(ns, n2)
}
}
return
}
for _, id := range chainIDs {
for _, n := range cs.nodes(id) {
if n == nil {
continue
}
n2, err := nodeStatus(n, id)
if err != nil {
return nil, err
}
ns = append(ns, n2)
}
}
return
}
type EVMNodes []*Node
func (ns *EVMNodes) SetFrom(fs *EVMNodes) {
for _, f := range *fs {
if f.Name == nil {
*ns = append(*ns, f)
} else if i := slices.IndexFunc(*ns, func(n *Node) bool {
return n.Name != nil && *n.Name == *f.Name
}); i == -1 {
*ns = append(*ns, f)
} else {
(*ns)[i].SetFrom(f)
}
}
}
type EVMConfig struct {
ChainID *big.Big
Enabled *bool
Chain
Nodes EVMNodes
}
func (c *EVMConfig) IsEnabled() bool {
return c.Enabled == nil || *c.Enabled
}
func (c *EVMConfig) SetFrom(f *EVMConfig) {
if f.ChainID != nil {
c.ChainID = f.ChainID
}
if f.Enabled != nil {
c.Enabled = f.Enabled
}
c.Chain.SetFrom(&f.Chain)
c.Nodes.SetFrom(&f.Nodes)
}
func (c *EVMConfig) ValidateConfig() (err error) {
if c.ChainID == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
} else if c.ChainID.String() == "" {
err = multierr.Append(err, commonconfig.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
} else if must, ok := ChainTypeForID(c.ChainID); ok { // known chain id
// Check if the parsed value matched the expected value
is := c.ChainType.ChainType()
if is != must {
if must == "" {
if c.ChainType.ChainType() != chaintype.ChainDualBroadcast {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "ChainType", Value: c.ChainType.ChainType(),
Msg: "must not be set with this chain id"})
}
} else {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "ChainType", Value: c.ChainType.ChainType(),
Msg: fmt.Sprintf("only %q can be used with this chain id", must)})
}
}
}
if len(c.Nodes) == 0 {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
} else {
var hasPrimary bool
var logBroadcasterEnabled bool
var newHeadsPollingInterval commonconfig.Duration
if c.LogBroadcasterEnabled != nil {
logBroadcasterEnabled = *c.LogBroadcasterEnabled
}
if c.NodePool.NewHeadsPollInterval != nil {
newHeadsPollingInterval = *c.NodePool.NewHeadsPollInterval
}
for i, n := range c.Nodes {
if n.SendOnly != nil && *n.SendOnly {
continue
}
hasPrimary = true
// if the node is a primary node, then the WS URL is required when
// 1. LogBroadcaster is enabled
// 2. The http polling is disabled (newHeadsPollingInterval == 0)
if n.WSURL == nil || n.WSURL.IsZero() {
if logBroadcasterEnabled {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes", Msg: fmt.Sprintf("%vth node (primary) must have a valid WSURL when LogBroadcaster is enabled", i)})
} else if newHeadsPollingInterval.Duration() == 0 {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes", Msg: fmt.Sprintf("%vth node (primary) must have a valid WSURL when http polling is disabled", i)})
}
}
}
if !hasPrimary {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes",
Msg: "must have at least one primary node"})
}
}
err = multierr.Append(err, c.Chain.ValidateConfig())
err = multierr.Append(err, c.NodePool.ValidateConfig(c.Chain.FinalityTagEnabled))
return
}
func (c *EVMConfig) TOMLString() (string, error) {
b, err := toml.Marshal(c)
if err != nil {
return "", err
}
return string(b), nil
}
type Chain struct {
AutoCreateKey *bool
BlockBackfillDepth *uint32
BlockBackfillSkip *bool
ChainType *chaintype.Config
FinalityDepth *uint32
FinalityTagEnabled *bool
FlagsContractAddress *types.EIP55Address
LinkContractAddress *types.EIP55Address
LogBackfillBatchSize *uint32
LogPollInterval *commonconfig.Duration
LogKeepBlocksDepth *uint32
LogPrunePageSize *uint32
BackupLogPollerBlockDelay *uint64
MinIncomingConfirmations *uint32
MinContractPayment *commonassets.Link
NonceAutoSync *bool
NoNewHeadsThreshold *commonconfig.Duration
OperatorFactoryAddress *types.EIP55Address
LogBroadcasterEnabled *bool
RPCDefaultBatchSize *uint32
RPCBlockQueryDelay *uint16
FinalizedBlockOffset *uint32
NoNewFinalizedHeadsThreshold *commonconfig.Duration
TxmV2 TxmV2 `toml:",omitempty"`
Transactions Transactions `toml:",omitempty"`
BalanceMonitor BalanceMonitor `toml:",omitempty"`
GasEstimator GasEstimator `toml:",omitempty"`
HeadTracker HeadTracker `toml:",omitempty"`
KeySpecific KeySpecificConfig `toml:",omitempty"`
NodePool NodePool `toml:",omitempty"`
OCR OCR `toml:",omitempty"`
OCR2 OCR2 `toml:",omitempty"`
Workflow Workflow `toml:",omitempty"`
}
func (c *Chain) ValidateConfig() (err error) {
if !c.ChainType.ChainType().IsValid() {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "ChainType", Value: c.ChainType.ChainType(),
Msg: chaintype.ErrInvalid.Error()})
}
if c.GasEstimator.BumpTxDepth != nil && *c.GasEstimator.BumpTxDepth > *c.Transactions.MaxInFlight {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "GasEstimator.BumpTxDepth", Value: *c.GasEstimator.BumpTxDepth,
Msg: "must be less than or equal to Transactions.MaxInFlight"})
}
if *c.FinalityDepth < 1 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FinalityDepth", Value: *c.FinalityDepth,
Msg: "must be greater than or equal to 1"})
}
if *c.MinIncomingConfirmations < 1 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "MinIncomingConfirmations", Value: *c.MinIncomingConfirmations,
Msg: "must be greater than or equal to 1"})
}
if *c.FinalizedBlockOffset > *c.HeadTracker.HistoryDepth {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "HeadTracker.HistoryDepth", Value: *c.HeadTracker.HistoryDepth,
Msg: "must be greater than or equal to FinalizedBlockOffset"})
}
// AutoPurge configs depend on ChainType so handling validation on per chain basis
if c.Transactions.AutoPurge.Enabled != nil && *c.Transactions.AutoPurge.Enabled {
chainType := c.ChainType.ChainType()
switch chainType {
case chaintype.ChainScroll:
if c.Transactions.AutoPurge.DetectionApiUrl == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Transactions.AutoPurge.DetectionApiUrl", Msg: fmt.Sprintf("must be set for %s", chainType)})
} else if c.Transactions.AutoPurge.DetectionApiUrl.IsZero() {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "Transactions.AutoPurge.DetectionApiUrl", Value: c.Transactions.AutoPurge.DetectionApiUrl, Msg: fmt.Sprintf("must be set for %s", chainType)})
} else {
switch c.Transactions.AutoPurge.DetectionApiUrl.Scheme {
case "http", "https":
default:
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "Transactions.AutoPurge.DetectionApiUrl", Value: c.Transactions.AutoPurge.DetectionApiUrl.Scheme, Msg: "must be http or https"})
}
}
case chaintype.ChainZkEvm, chaintype.ChainXLayer:
// MinAttempts is an optional config that can be used to delay the stuck tx detection for zkEVM or XLayer
// If MinAttempts is set, BumpThreshold cannot be 0
if c.Transactions.AutoPurge.MinAttempts != nil && *c.Transactions.AutoPurge.MinAttempts != 0 {
if c.GasEstimator.BumpThreshold == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "GasEstimator.BumpThreshold", Msg: fmt.Sprintf("must be set if Transactions.AutoPurge.MinAttempts is set for %s", chainType)})
} else if *c.GasEstimator.BumpThreshold == 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "GasEstimator.BumpThreshold", Value: 0, Msg: fmt.Sprintf("cannot be 0 if Transactions.AutoPurge.MinAttempts is set for %s", chainType)})
}
}
case chaintype.ChainDualBroadcast:
if c.Transactions.AutoPurge.DetectionApiUrl == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Transactions.AutoPurge.DetectionApiUrl", Msg: fmt.Sprintf("must be set for %s", chainType)})
}
if c.Transactions.AutoPurge.Threshold == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Transactions.AutoPurge.Threshold", Msg: fmt.Sprintf("needs to be set if auto-purge feature is enabled for %s", chainType)})
} else if *c.Transactions.AutoPurge.Threshold == 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "Transactions.AutoPurge.Threshold", Value: 0, Msg: fmt.Sprintf("cannot be 0 if auto-purge feature is enabled for %s", chainType)})
}
if c.TxmV2.Enabled != nil && *c.TxmV2.Enabled {
if c.TxmV2.CustomURL == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "TxmV2.CustomURL", Msg: fmt.Sprintf("must be set for %s", chainType)})
}
}
default:
// Bump Threshold is required because the stuck tx heuristic relies on a minimum number of bump attempts to exist
if c.GasEstimator.BumpThreshold == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "GasEstimator.BumpThreshold", Msg: fmt.Sprintf("must be set if auto-purge feature is enabled for %s", chainType)})
} else if *c.GasEstimator.BumpThreshold == 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "GasEstimator.BumpThreshold", Value: 0, Msg: fmt.Sprintf("cannot be 0 if auto-purge feature is enabled for %s", chainType)})
}
if c.Transactions.AutoPurge.Threshold == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Transactions.AutoPurge.Threshold", Msg: fmt.Sprintf("needs to be set if auto-purge feature is enabled for %s", chainType)})
} else if *c.Transactions.AutoPurge.Threshold == 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "Transactions.AutoPurge.Threshold", Value: 0, Msg: fmt.Sprintf("cannot be 0 if auto-purge feature is enabled for %s", chainType)})
}
if c.Transactions.AutoPurge.MinAttempts == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Transactions.AutoPurge.MinAttempts", Msg: fmt.Sprintf("needs to be set if auto-purge feature is enabled for %s", chainType)})
} else if *c.Transactions.AutoPurge.MinAttempts == 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "Transactions.AutoPurge.MinAttempts", Value: 0, Msg: fmt.Sprintf("cannot be 0 if auto-purge feature is enabled for %s", chainType)})
}
}
}
return
}
type TxmV2 struct {
Enabled *bool `toml:",omitempty"`
BlockTime *commonconfig.Duration `toml:",omitempty"`
CustomURL *commonconfig.URL `toml:",omitempty"`
}
func (t *TxmV2) setFrom(f *TxmV2) {
if v := f.Enabled; v != nil {
t.Enabled = f.Enabled
}
if v := f.BlockTime; v != nil {
t.BlockTime = f.BlockTime
}
if v := f.CustomURL; v != nil {
t.CustomURL = f.CustomURL
}
}
func (t *TxmV2) ValidateConfig() (err error) {
if t.Enabled != nil && *t.Enabled {
if t.BlockTime == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "TxmV2.BlockTime", Msg: "must be set if txmv2 feature is enabled"})
return
}
if t.BlockTime.Duration() < 2*time.Second {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "TxmV2.BlockTime", Msg: "must be equal to or greater than 2 seconds"})
}
}
return
}
type Transactions struct {
Enabled *bool
ForwardersEnabled *bool
MaxInFlight *uint32
MaxQueued *uint32
ReaperInterval *commonconfig.Duration
ReaperThreshold *commonconfig.Duration
ResendAfterThreshold *commonconfig.Duration
AutoPurge AutoPurgeConfig `toml:",omitempty"`
}
func (t *Transactions) setFrom(f *Transactions) {
if v := f.Enabled; v != nil {
t.Enabled = v
}
if v := f.ForwardersEnabled; v != nil {
t.ForwardersEnabled = v
}
if v := f.MaxInFlight; v != nil {
t.MaxInFlight = v
}
if v := f.MaxQueued; v != nil {
t.MaxQueued = v
}
if v := f.ReaperInterval; v != nil {
t.ReaperInterval = v
}
if v := f.ReaperThreshold; v != nil {
t.ReaperThreshold = v
}
if v := f.ResendAfterThreshold; v != nil {
t.ResendAfterThreshold = v
}
t.AutoPurge.setFrom(&f.AutoPurge)
}
type AutoPurgeConfig struct {
Enabled *bool
Threshold *uint32
MinAttempts *uint32
DetectionApiUrl *commonconfig.URL
}
func (a *AutoPurgeConfig) setFrom(f *AutoPurgeConfig) {
if v := f.Enabled; v != nil {
a.Enabled = v
}
if v := f.Threshold; v != nil {
a.Threshold = v
}
if v := f.MinAttempts; v != nil {
a.MinAttempts = v
}
if v := f.DetectionApiUrl; v != nil {
a.DetectionApiUrl = v
}
}
type OCR2 struct {
Automation Automation `toml:",omitempty"`
}
func (o *OCR2) setFrom(f *OCR2) {
o.Automation.setFrom(&f.Automation)
}
type Automation struct {
GasLimit *uint32
}
func (a *Automation) setFrom(f *Automation) {
if v := f.GasLimit; v != nil {
a.GasLimit = v
}
}
type Workflow struct {
FromAddress *types.EIP55Address `toml:",omitempty"`
ForwarderAddress *types.EIP55Address `toml:",omitempty"`
GasLimitDefault *uint64
}
func (m *Workflow) setFrom(f *Workflow) {
if v := f.FromAddress; v != nil {
m.FromAddress = v
}
if v := f.ForwarderAddress; v != nil {
m.ForwarderAddress = v
}
if v := f.GasLimitDefault; v != nil {
m.GasLimitDefault = v
}
}
type BalanceMonitor struct {
Enabled *bool
}
func (m *BalanceMonitor) setFrom(f *BalanceMonitor) {
if v := f.Enabled; v != nil {
m.Enabled = v
}
}
type GasEstimator struct {
Mode *string
PriceDefault *assets.Wei
PriceMax *assets.Wei
PriceMin *assets.Wei
LimitDefault *uint64
LimitMax *uint64
LimitMultiplier *decimal.Decimal
LimitTransfer *uint64
LimitJobType GasLimitJobType `toml:",omitempty"`
EstimateLimit *bool
BumpMin *assets.Wei
BumpPercent *uint16
BumpThreshold *uint32
BumpTxDepth *uint32
EIP1559DynamicFees *bool
FeeCapDefault *assets.Wei
TipCapDefault *assets.Wei
TipCapMin *assets.Wei
BlockHistory BlockHistoryEstimator `toml:",omitempty"`
FeeHistory FeeHistoryEstimator `toml:",omitempty"`
DAOracle DAOracle `toml:",omitempty"`
}
func (e *GasEstimator) ValidateConfig() (err error) {
if uint64(*e.BumpPercent) < legacypool.DefaultConfig.PriceBump {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "BumpPercent", Value: *e.BumpPercent,
Msg: fmt.Sprintf("may not be less than Geth's default of %d", legacypool.DefaultConfig.PriceBump)})
}
if e.TipCapDefault.Cmp(e.TipCapMin) < 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "TipCapDefault", Value: e.TipCapDefault,
Msg: "must be greater than or equal to TipCapMinimum"})
}
if e.FeeCapDefault.Cmp(e.TipCapDefault) < 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.TipCapDefault,
Msg: "must be greater than or equal to TipCapDefault"})
}
if *e.Mode == "FixedPrice" && *e.BumpThreshold == 0 && *e.EIP1559DynamicFees && e.FeeCapDefault.Cmp(e.PriceMax) != 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
Msg: fmt.Sprintf("must be equal to PriceMax (%s) since you are using FixedPrice estimation with gas bumping disabled in "+
"EIP1559 mode - PriceMax will be used as the FeeCap for transactions instead of FeeCapDefault", e.PriceMax)})
} else if e.FeeCapDefault.Cmp(e.PriceMax) > 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
Msg: fmt.Sprintf("must be less than or equal to PriceMax (%s)", e.PriceMax)})
}
if e.PriceMin.Cmp(e.PriceDefault) > 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "PriceMin", Value: e.PriceMin,
Msg: "must be less than or equal to PriceDefault"})
}
if e.PriceMax.Cmp(e.PriceDefault) < 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "PriceMax", Value: e.PriceMin,
Msg: "must be greater than or equal to PriceDefault"})
}
if *e.Mode == "BlockHistory" && *e.BlockHistory.BlockHistorySize <= 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "BlockHistory.BlockHistorySize", Value: *e.BlockHistory.BlockHistorySize,
Msg: "must be greater than or equal to 1 with BlockHistory Mode"})
}
return
}
func (e *GasEstimator) setFrom(f *GasEstimator) {
if v := f.Mode; v != nil {
e.Mode = v
}
if v := f.EIP1559DynamicFees; v != nil {
e.EIP1559DynamicFees = v
}
if v := f.BumpPercent; v != nil {
e.BumpPercent = v
}
if v := f.BumpThreshold; v != nil {
e.BumpThreshold = v
}
if v := f.BumpTxDepth; v != nil {
e.BumpTxDepth = v
}
if v := f.BumpMin; v != nil {
e.BumpMin = v
}
if v := f.FeeCapDefault; v != nil {
e.FeeCapDefault = v
}
if v := f.LimitDefault; v != nil {
e.LimitDefault = v
}
if v := f.LimitMax; v != nil {
e.LimitMax = v
}
if v := f.LimitMultiplier; v != nil {
e.LimitMultiplier = v
}
if v := f.LimitTransfer; v != nil {
e.LimitTransfer = v
}
if v := f.EstimateLimit; v != nil {
e.EstimateLimit = v
}
if v := f.PriceDefault; v != nil {
e.PriceDefault = v
}
if v := f.TipCapDefault; v != nil {
e.TipCapDefault = v
}
if v := f.TipCapMin; v != nil {
e.TipCapMin = v
}
if v := f.PriceMax; v != nil {
e.PriceMax = v
}
if v := f.PriceMin; v != nil {
e.PriceMin = v
}
e.LimitJobType.setFrom(&f.LimitJobType)
e.BlockHistory.setFrom(&f.BlockHistory)
e.FeeHistory.setFrom(&f.FeeHistory)
e.DAOracle.setFrom(&f.DAOracle)
}
type GasLimitJobType struct {
OCR *uint32 `toml:",inline"`
OCR2 *uint32 `toml:",inline"`
DR *uint32 `toml:",inline"`
VRF *uint32 `toml:",inline"`
FM *uint32 `toml:",inline"`
Keeper *uint32 `toml:",inline"`
}
func (t *GasLimitJobType) setFrom(f *GasLimitJobType) {
if f.OCR != nil {
t.OCR = f.OCR
}
if f.OCR2 != nil {
t.OCR2 = f.OCR2
}
if f.DR != nil {
t.DR = f.DR
}
if f.VRF != nil {
t.VRF = f.VRF
}
if f.FM != nil {
t.FM = f.FM
}
if f.Keeper != nil {
t.Keeper = f.Keeper
}
}
type BlockHistoryEstimator struct {
BatchSize *uint32
BlockHistorySize *uint16
CheckInclusionBlocks *uint16
CheckInclusionPercentile *uint16
EIP1559FeeCapBufferBlocks *uint16
TransactionPercentile *uint16
}
func (e *BlockHistoryEstimator) setFrom(f *BlockHistoryEstimator) {
if v := f.BatchSize; v != nil {
e.BatchSize = v
}
if v := f.BlockHistorySize; v != nil {
e.BlockHistorySize = v
}
if v := f.CheckInclusionBlocks; v != nil {
e.CheckInclusionBlocks = v
}
if v := f.CheckInclusionPercentile; v != nil {
e.CheckInclusionPercentile = v
}
if v := f.EIP1559FeeCapBufferBlocks; v != nil {
e.EIP1559FeeCapBufferBlocks = v
}
if v := f.TransactionPercentile; v != nil {
e.TransactionPercentile = v
}
}
type FeeHistoryEstimator struct {
CacheTimeout *commonconfig.Duration
}
func (u *FeeHistoryEstimator) setFrom(f *FeeHistoryEstimator) {
if v := f.CacheTimeout; v != nil {
u.CacheTimeout = v
}
}
type DAOracle struct {
OracleType *DAOracleType
OracleAddress *types.EIP55Address
CustomGasPriceCalldata *string
}
type DAOracleType string
const (
DAOracleOPStack = DAOracleType("opstack")
DAOracleArbitrum = DAOracleType("arbitrum")
DAOracleZKSync = DAOracleType("zksync")
DAOracleCustomCalldata = DAOracleType("custom_calldata")
)
func (o *DAOracle) ValidateConfig() (err error) {
if o.OracleType != nil {
if *o.OracleType == DAOracleOPStack {
if o.OracleAddress == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "OracleAddress", Msg: "required for 'opstack' oracle types"})
}
}
if *o.OracleType == DAOracleCustomCalldata {
if o.OracleAddress == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "OracleAddress", Msg: "required for 'custom_calldata' oracle types"})
}
if o.CustomGasPriceCalldata == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "CustomGasPriceCalldata", Msg: "required for 'custom_calldata' oracle type"})
}
}
}
return
}
func (o DAOracleType) IsValid() bool {
switch o {
case "", DAOracleOPStack, DAOracleArbitrum, DAOracleZKSync, DAOracleCustomCalldata:
return true
}
return false
}
func (d *DAOracle) setFrom(f *DAOracle) {
if v := f.OracleType; v != nil {
d.OracleType = v
}
if v := f.OracleAddress; v != nil {
d.OracleAddress = v
}
if v := f.CustomGasPriceCalldata; v != nil {
d.CustomGasPriceCalldata = v
}
}
type KeySpecificConfig []KeySpecific
func (ks KeySpecificConfig) ValidateConfig() (err error) {
addrs := map[string]struct{}{}
for _, k := range ks {
addr := k.Key.String()
if _, ok := addrs[addr]; ok {
err = multierr.Append(err, commonconfig.NewErrDuplicate("Key", addr))
} else {
addrs[addr] = struct{}{}
}
}
return
}
type KeySpecific struct {
Key *types.EIP55Address
GasEstimator KeySpecificGasEstimator `toml:",omitempty"`
}
type KeySpecificGasEstimator struct {
PriceMax *assets.Wei
}
func (e *KeySpecificGasEstimator) setFrom(f *KeySpecificGasEstimator) {
if v := f.PriceMax; v != nil {
e.PriceMax = v
}
}
type HeadTracker struct {
HistoryDepth *uint32
MaxBufferSize *uint32
SamplingInterval *commonconfig.Duration
MaxAllowedFinalityDepth *uint32
FinalityTagBypass *bool
PersistenceEnabled *bool
}
func (t *HeadTracker) setFrom(f *HeadTracker) {
if v := f.HistoryDepth; v != nil {
t.HistoryDepth = v
}
if v := f.MaxBufferSize; v != nil {
t.MaxBufferSize = v
}
if v := f.SamplingInterval; v != nil {
t.SamplingInterval = v
}
if v := f.MaxAllowedFinalityDepth; v != nil {
t.MaxAllowedFinalityDepth = v
}
if v := f.FinalityTagBypass; v != nil {
t.FinalityTagBypass = v
}
if v := f.PersistenceEnabled; v != nil {
t.PersistenceEnabled = v
}
}
func (t *HeadTracker) ValidateConfig() (err error) {
if *t.MaxAllowedFinalityDepth < 1 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "MaxAllowedFinalityDepth", Value: *t.MaxAllowedFinalityDepth,
Msg: "must be greater than or equal to 1"})
}
return
}
type ClientErrors struct {
NonceTooLow *string `toml:",omitempty"`
NonceTooHigh *string `toml:",omitempty"`
ReplacementTransactionUnderpriced *string `toml:",omitempty"`
LimitReached *string `toml:",omitempty"`
TransactionAlreadyInMempool *string `toml:",omitempty"`
TerminallyUnderpriced *string `toml:",omitempty"`
InsufficientEth *string `toml:",omitempty"`
TxFeeExceedsCap *string `toml:",omitempty"`
L2FeeTooLow *string `toml:",omitempty"`
L2FeeTooHigh *string `toml:",omitempty"`
L2Full *string `toml:",omitempty"`
TransactionAlreadyMined *string `toml:",omitempty"`
Fatal *string `toml:",omitempty"`
ServiceUnavailable *string `toml:",omitempty"`
TooManyResults *string `toml:",omitempty"`
}
func (r *ClientErrors) setFrom(f *ClientErrors) bool {
if v := f.NonceTooLow; v != nil {
r.NonceTooLow = v
}
if v := f.NonceTooHigh; v != nil {
r.NonceTooHigh = v
}
if v := f.ReplacementTransactionUnderpriced; v != nil {
r.ReplacementTransactionUnderpriced = v
}
if v := f.LimitReached; v != nil {
r.LimitReached = v
}
if v := f.TransactionAlreadyInMempool; v != nil {
r.TransactionAlreadyInMempool = v
}
if v := f.TerminallyUnderpriced; v != nil {
r.TerminallyUnderpriced = v
}
if v := f.InsufficientEth; v != nil {
r.InsufficientEth = v
}
if v := f.TxFeeExceedsCap; v != nil {
r.TxFeeExceedsCap = v
}
if v := f.L2FeeTooLow; v != nil {
r.L2FeeTooLow = v
}
if v := f.L2FeeTooHigh; v != nil {
r.L2FeeTooHigh = v
}
if v := f.L2Full; v != nil {