/
types.go
974 lines (877 loc) · 23.1 KB
/
types.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
package v2
import (
_ "embed"
"errors"
"fmt"
"log"
"net"
"net/url"
"strings"
uuid "github.com/satori/go.uuid"
"go.uber.org/multierr"
"go.uber.org/zap/zapcore"
ocrcommontypes "github.com/smartcontractkit/libocr/commontypes"
ocrnetworking "github.com/smartcontractkit/libocr/networking"
"github.com/smartcontractkit/chainlink/core/config"
"github.com/smartcontractkit/chainlink/core/logger/audit"
"github.com/smartcontractkit/chainlink/core/services/chainlink/cfgtest"
"github.com/smartcontractkit/chainlink/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/core/services/keystore/keys/p2pkey"
"github.com/smartcontractkit/chainlink/core/store/dialects"
"github.com/smartcontractkit/chainlink/core/store/models"
"github.com/smartcontractkit/chainlink/core/utils"
)
var ErrUnsupported = errors.New("unsupported with config v2")
// Core holds the core configuration. See chainlink.Config for more information.
type Core struct {
// General/misc
AppID uuid.UUID `toml:"-"` // random or test
DevMode bool `toml:"-"` // from environment
ExplorerURL *models.URL
InsecureFastScrypt *bool
RootDir *string
ShutdownGracePeriod *models.Duration
Feature Feature `toml:",omitempty"`
Database Database `toml:",omitempty"`
TelemetryIngress TelemetryIngress `toml:",omitempty"`
AuditLogger audit.AuditLoggerConfig `toml:",omitempty"`
Log Log `toml:",omitempty"`
WebServer WebServer `toml:",omitempty"`
JobPipeline JobPipeline `toml:",omitempty"`
FluxMonitor FluxMonitor `toml:",omitempty"`
OCR2 OCR2 `toml:",omitempty"`
OCR OCR `toml:",omitempty"`
P2P P2P `toml:",omitempty"`
Keeper Keeper `toml:",omitempty"`
AutoPprof AutoPprof `toml:",omitempty"`
Pyroscope Pyroscope `toml:",omitempty"`
Sentry Sentry `toml:",omitempty"`
}
var (
//go:embed docs/core.toml
defaultsTOML string
defaults Core
)
func init() {
if err := cfgtest.DocDefaultsOnly(strings.NewReader(defaultsTOML), &defaults, DecodeTOML); err != nil {
log.Fatalf("Failed to initialize defaults from docs: %v", err)
}
}
func CoreDefaults() (c Core) {
c.SetFrom(&defaults)
c.Database.Dialect = dialects.Postgres // not user visible - overridden for tests only
return
}
// SetFrom updates c with any non-nil values from f. (currently TOML field only!)
func (c *Core) SetFrom(f *Core) {
if v := f.ExplorerURL; v != nil {
c.ExplorerURL = f.ExplorerURL
}
if v := f.InsecureFastScrypt; v != nil {
c.InsecureFastScrypt = v
}
if v := f.RootDir; v != nil {
c.RootDir = v
}
if v := f.ShutdownGracePeriod; v != nil {
c.ShutdownGracePeriod = v
}
c.Feature.setFrom(&f.Feature)
c.Database.setFrom(&f.Database)
c.TelemetryIngress.setFrom(&f.TelemetryIngress)
c.AuditLogger.SetFrom(&f.AuditLogger)
c.Log.setFrom(&f.Log)
c.WebServer.setFrom(&f.WebServer)
c.JobPipeline.setFrom(&f.JobPipeline)
c.FluxMonitor.setFrom(&f.FluxMonitor)
c.OCR2.setFrom(&f.OCR2)
c.OCR.setFrom(&f.OCR)
c.P2P.setFrom(&f.P2P)
c.Keeper.setFrom(&f.Keeper)
c.AutoPprof.setFrom(&f.AutoPprof)
c.Pyroscope.setFrom(&f.Pyroscope)
c.Sentry.setFrom(&f.Sentry)
}
type Secrets struct {
Database DatabaseSecrets `toml:",omitempty"`
Explorer ExplorerSecrets `toml:",omitempty"`
Password Passwords `toml:",omitempty"`
Pyroscope PyroscopeSecrets `toml:",omitempty"`
Mercury MercurySecrets `toml:",omitempty"`
}
func dbURLPasswordComplexity(err error) string {
return fmt.Sprintf("missing or insufficiently complex password: %s. Database should be secured by a password matching the following complexity requirements: "+utils.PasswordComplexityRequirements, err)
}
type DatabaseSecrets struct {
URL *models.SecretURL
BackupURL *models.SecretURL
AllowSimplePasswords bool
}
func (d *DatabaseSecrets) ValidateConfig() (err error) {
if d.URL == nil || (*url.URL)(d.URL).String() == "" {
err = multierr.Append(err, ErrEmpty{Name: "URL", Msg: "must be provided and non-empty"})
} else if !d.AllowSimplePasswords {
if verr := config.ValidateDBURL((url.URL)(*d.URL)); verr != nil {
err = multierr.Append(err, ErrInvalid{Name: "URL", Value: "*****", Msg: dbURLPasswordComplexity(verr)})
}
}
if d.BackupURL != nil && !d.AllowSimplePasswords {
if verr := config.ValidateDBURL((url.URL)(*d.BackupURL)); verr != nil {
err = multierr.Append(err, ErrInvalid{Name: "BackupURL", Value: "*****", Msg: dbURLPasswordComplexity(verr)})
}
}
return err
}
type ExplorerSecrets struct {
AccessKey *models.Secret
Secret *models.Secret
}
type Passwords struct {
Keystore *models.Secret
VRF *models.Secret
}
func (p *Passwords) ValidateConfig() (err error) {
if p.Keystore == nil || *p.Keystore == "" {
err = multierr.Append(err, ErrEmpty{Name: "Keystore", Msg: "must be provided and non-empty"})
}
return err
}
type PyroscopeSecrets struct {
AuthToken *models.Secret
}
type MercuryCredentials struct {
URL *models.SecretURL
Username *models.Secret
Password *models.Secret
}
type MercurySecrets struct {
Credentials []MercuryCredentials
}
func (m *MercurySecrets) ValidateConfig() (err error) {
urls := make(map[string]struct{}, len(m.Credentials))
for _, creds := range m.Credentials {
if creds.URL == nil {
return errors.New("`url` must be set for all mercury credentials")
}
s := creds.URL.String()
if _, exists := urls[s]; exists {
return errors.New("Credentials: may not contain duplicate URLs")
}
urls[s] = struct{}{}
}
return nil
}
type Feature struct {
FeedsManager *bool
LogPoller *bool
UICSAKeys *bool
}
func (f *Feature) setFrom(f2 *Feature) {
if v := f2.FeedsManager; v != nil {
f.FeedsManager = v
}
if v := f2.LogPoller; v != nil {
f.LogPoller = v
}
if v := f2.UICSAKeys; v != nil {
f.UICSAKeys = v
}
}
type Database struct {
DefaultIdleInTxSessionTimeout *models.Duration
DefaultLockTimeout *models.Duration
DefaultQueryTimeout *models.Duration
Dialect dialects.DialectName `toml:"-"`
LogQueries *bool
MaxIdleConns *int64
MaxOpenConns *int64
MigrateOnStartup *bool
Backup DatabaseBackup `toml:",omitempty"`
Listener DatabaseListener `toml:",omitempty"`
Lock DatabaseLock `toml:",omitempty"`
}
func (d *Database) LockingMode() string {
if *d.Lock.Enabled {
return "lease"
}
return "none"
}
func (d *Database) setFrom(f *Database) {
if v := f.DefaultIdleInTxSessionTimeout; v != nil {
d.DefaultIdleInTxSessionTimeout = v
}
if v := f.DefaultLockTimeout; v != nil {
d.DefaultLockTimeout = v
}
if v := f.DefaultQueryTimeout; v != nil {
d.DefaultQueryTimeout = v
}
if v := f.LogQueries; v != nil {
d.LogQueries = v
}
if v := f.MigrateOnStartup; v != nil {
d.MigrateOnStartup = v
}
if v := f.MaxIdleConns; v != nil {
d.MaxIdleConns = v
}
if v := f.MaxOpenConns; v != nil {
d.MaxOpenConns = v
}
d.Backup.setFrom(&f.Backup)
d.Listener.setFrom(&f.Listener)
d.Lock.setFrom(&f.Lock)
}
type DatabaseListener struct {
MaxReconnectDuration *models.Duration
MinReconnectInterval *models.Duration
FallbackPollInterval *models.Duration
}
func (d *DatabaseListener) setFrom(f *DatabaseListener) {
if v := f.MaxReconnectDuration; v != nil {
d.MaxReconnectDuration = v
}
if v := f.MinReconnectInterval; v != nil {
d.MinReconnectInterval = v
}
if v := f.FallbackPollInterval; v != nil {
d.FallbackPollInterval = v
}
}
type DatabaseLock struct {
Enabled *bool
LeaseDuration *models.Duration
LeaseRefreshInterval *models.Duration
}
func (l *DatabaseLock) ValidateConfig() (err error) {
if l.LeaseRefreshInterval.Duration() > l.LeaseDuration.Duration()/2 {
err = multierr.Append(err, ErrInvalid{Name: "LeaseRefreshInterval", Value: l.LeaseRefreshInterval.String(),
Msg: fmt.Sprintf("must be less than or equal to half of LeaseDuration (%s)", l.LeaseDuration.String())})
}
return
}
func (l *DatabaseLock) setFrom(f *DatabaseLock) {
if v := f.Enabled; v != nil {
l.Enabled = v
}
if v := f.LeaseDuration; v != nil {
l.LeaseDuration = v
}
if v := f.LeaseRefreshInterval; v != nil {
l.LeaseRefreshInterval = v
}
}
// DatabaseBackup
//
// Note: url is stored in Secrets.DatabaseBackupURL
type DatabaseBackup struct {
Dir *string
Frequency *models.Duration
Mode *config.DatabaseBackupMode
OnVersionUpgrade *bool
}
func (d *DatabaseBackup) setFrom(f *DatabaseBackup) {
if v := f.Dir; v != nil {
d.Dir = v
}
if v := f.Frequency; v != nil {
d.Frequency = v
}
if v := f.Mode; v != nil {
d.Mode = v
}
if v := f.OnVersionUpgrade; v != nil {
d.OnVersionUpgrade = v
}
}
type TelemetryIngress struct {
UniConn *bool
Logging *bool
ServerPubKey *string
URL *models.URL
BufferSize *uint16
MaxBatchSize *uint16
SendInterval *models.Duration
SendTimeout *models.Duration
UseBatchSend *bool
}
func (t *TelemetryIngress) setFrom(f *TelemetryIngress) {
if v := f.UniConn; v != nil {
t.UniConn = v
}
if v := f.Logging; v != nil {
t.Logging = v
}
if v := f.ServerPubKey; v != nil {
t.ServerPubKey = v
}
if v := f.URL; v != nil {
t.URL = v
}
if v := f.BufferSize; v != nil {
t.BufferSize = v
}
if v := f.MaxBatchSize; v != nil {
t.MaxBatchSize = v
}
if v := f.SendInterval; v != nil {
t.SendInterval = v
}
if v := f.SendTimeout; v != nil {
t.SendTimeout = v
}
if v := f.UseBatchSend; v != nil {
t.UseBatchSend = v
}
}
// LogLevel replaces dpanic with crit/CRIT
type LogLevel zapcore.Level
func (l LogLevel) String() string {
zl := zapcore.Level(l)
if zl == zapcore.DPanicLevel {
return "crit"
}
return zl.String()
}
func (l LogLevel) CapitalString() string {
zl := zapcore.Level(l)
if zl == zapcore.DPanicLevel {
return "CRIT"
}
return zl.CapitalString()
}
func (l LogLevel) MarshalText() ([]byte, error) {
return []byte(l.String()), nil
}
func (l *LogLevel) UnmarshalText(text []byte) error {
switch string(text) {
case "crit", "CRIT":
*l = LogLevel(zapcore.DPanicLevel)
return nil
}
return (*zapcore.Level)(l).UnmarshalText(text)
}
type Log struct {
Level *LogLevel
JSONConsole *bool
UnixTS *bool
File LogFile `toml:",omitempty"`
}
func (l *Log) setFrom(f *Log) {
if v := f.Level; v != nil {
l.Level = v
}
if v := f.JSONConsole; v != nil {
l.JSONConsole = v
}
if v := f.UnixTS; v != nil {
l.UnixTS = v
}
l.File.setFrom(&f.File)
}
type LogFile struct {
Dir *string
MaxSize *utils.FileSize
MaxAgeDays *int64
MaxBackups *int64
}
func (l *LogFile) setFrom(f *LogFile) {
if v := f.Dir; v != nil {
l.Dir = v
}
if v := f.MaxSize; v != nil {
l.MaxSize = v
}
if v := f.MaxAgeDays; v != nil {
l.MaxAgeDays = v
}
if v := f.MaxBackups; v != nil {
l.MaxBackups = v
}
}
type WebServer struct {
AllowOrigins *string
BridgeResponseURL *models.URL
BridgeCacheTTL *models.Duration
HTTPWriteTimeout *models.Duration
HTTPPort *uint16
SecureCookies *bool
SessionTimeout *models.Duration
SessionReaperExpiration *models.Duration
MFA WebServerMFA `toml:",omitempty"`
RateLimit WebServerRateLimit `toml:",omitempty"`
TLS WebServerTLS `toml:",omitempty"`
}
func (w *WebServer) setFrom(f *WebServer) {
if v := f.AllowOrigins; v != nil {
w.AllowOrigins = v
}
if v := f.BridgeResponseURL; v != nil {
w.BridgeResponseURL = v
}
if v := f.BridgeCacheTTL; v != nil {
w.BridgeCacheTTL = v
}
if v := f.HTTPWriteTimeout; v != nil {
w.HTTPWriteTimeout = v
}
if v := f.HTTPPort; v != nil {
w.HTTPPort = v
}
if v := f.SecureCookies; v != nil {
w.SecureCookies = v
}
if v := f.SessionTimeout; v != nil {
w.SessionTimeout = v
}
if v := f.SessionReaperExpiration; v != nil {
w.SessionReaperExpiration = v
}
w.MFA.setFrom(&f.MFA)
w.RateLimit.setFrom(&f.RateLimit)
w.TLS.setFrom(&f.TLS)
}
type WebServerMFA struct {
RPID *string
RPOrigin *string
}
func (w *WebServerMFA) setFrom(f *WebServerMFA) {
if v := f.RPID; v != nil {
w.RPID = v
}
if v := f.RPOrigin; v != nil {
w.RPOrigin = v
}
}
type WebServerRateLimit struct {
Authenticated *int64
AuthenticatedPeriod *models.Duration
Unauthenticated *int64
UnauthenticatedPeriod *models.Duration
}
func (w *WebServerRateLimit) setFrom(f *WebServerRateLimit) {
if v := f.Authenticated; v != nil {
w.Authenticated = v
}
if v := f.AuthenticatedPeriod; v != nil {
w.AuthenticatedPeriod = v
}
if v := f.Unauthenticated; v != nil {
w.Unauthenticated = v
}
if v := f.UnauthenticatedPeriod; v != nil {
w.UnauthenticatedPeriod = v
}
}
type WebServerTLS struct {
CertPath *string
ForceRedirect *bool
Host *string
HTTPSPort *uint16
KeyPath *string
}
func (w *WebServerTLS) setFrom(f *WebServerTLS) {
if v := f.CertPath; v != nil {
w.CertPath = v
}
if v := f.ForceRedirect; v != nil {
w.ForceRedirect = v
}
if v := f.Host; v != nil {
w.Host = v
}
if v := f.HTTPSPort; v != nil {
w.HTTPSPort = v
}
if v := f.KeyPath; v != nil {
w.KeyPath = v
}
}
type JobPipeline struct {
ExternalInitiatorsEnabled *bool
MaxRunDuration *models.Duration
MaxSuccessfulRuns *uint64
ReaperInterval *models.Duration
ReaperThreshold *models.Duration
ResultWriteQueueDepth *uint32
HTTPRequest JobPipelineHTTPRequest `toml:",omitempty"`
}
func (j *JobPipeline) setFrom(f *JobPipeline) {
if v := f.ExternalInitiatorsEnabled; v != nil {
j.ExternalInitiatorsEnabled = v
}
if v := f.MaxRunDuration; v != nil {
j.MaxRunDuration = v
}
if v := f.MaxSuccessfulRuns; v != nil {
j.MaxSuccessfulRuns = v
}
if v := f.ReaperInterval; v != nil {
j.ReaperInterval = v
}
if v := f.ReaperThreshold; v != nil {
j.ReaperThreshold = v
}
if v := f.ResultWriteQueueDepth; v != nil {
j.ResultWriteQueueDepth = v
}
j.HTTPRequest.setFrom(&f.HTTPRequest)
}
type JobPipelineHTTPRequest struct {
DefaultTimeout *models.Duration
MaxSize *utils.FileSize
}
func (j *JobPipelineHTTPRequest) setFrom(f *JobPipelineHTTPRequest) {
if v := f.DefaultTimeout; v != nil {
j.DefaultTimeout = v
}
if v := f.MaxSize; v != nil {
j.MaxSize = v
}
}
type FluxMonitor struct {
DefaultTransactionQueueDepth *uint32
SimulateTransactions *bool
}
func (m *FluxMonitor) setFrom(f *FluxMonitor) {
if v := f.DefaultTransactionQueueDepth; v != nil {
m.DefaultTransactionQueueDepth = v
}
if v := f.SimulateTransactions; v != nil {
m.SimulateTransactions = v
}
}
type OCR2 struct {
Enabled *bool
ContractConfirmations *uint32
BlockchainTimeout *models.Duration
ContractPollInterval *models.Duration
ContractSubscribeInterval *models.Duration
ContractTransmitterTransmitTimeout *models.Duration
DatabaseTimeout *models.Duration
KeyBundleID *models.Sha256Hash
}
func (o *OCR2) setFrom(f *OCR2) {
if v := f.Enabled; v != nil {
o.Enabled = v
}
if v := f.ContractConfirmations; v != nil {
o.ContractConfirmations = v
}
if v := f.BlockchainTimeout; v != nil {
o.BlockchainTimeout = v
}
if v := f.ContractPollInterval; v != nil {
o.ContractPollInterval = v
}
if v := f.ContractSubscribeInterval; v != nil {
o.ContractSubscribeInterval = v
}
if v := f.ContractTransmitterTransmitTimeout; v != nil {
o.ContractTransmitterTransmitTimeout = v
}
if v := f.DatabaseTimeout; v != nil {
o.DatabaseTimeout = v
}
if v := f.KeyBundleID; v != nil {
o.KeyBundleID = v
}
}
type OCR struct {
Enabled *bool
ObservationTimeout *models.Duration
BlockchainTimeout *models.Duration
ContractPollInterval *models.Duration
ContractSubscribeInterval *models.Duration
DefaultTransactionQueueDepth *uint32
// Optional
KeyBundleID *models.Sha256Hash
SimulateTransactions *bool
TransmitterAddress *ethkey.EIP55Address
}
func (o *OCR) setFrom(f *OCR) {
if v := f.Enabled; v != nil {
o.Enabled = v
}
if v := f.ObservationTimeout; v != nil {
o.ObservationTimeout = v
}
if v := f.BlockchainTimeout; v != nil {
o.BlockchainTimeout = v
}
if v := f.ContractPollInterval; v != nil {
o.ContractPollInterval = v
}
if v := f.ContractSubscribeInterval; v != nil {
o.ContractSubscribeInterval = v
}
if v := f.DefaultTransactionQueueDepth; v != nil {
o.DefaultTransactionQueueDepth = v
}
if v := f.KeyBundleID; v != nil {
o.KeyBundleID = v
}
if v := f.SimulateTransactions; v != nil {
o.SimulateTransactions = v
}
if v := f.TransmitterAddress; v != nil {
o.TransmitterAddress = v
}
}
type P2P struct {
IncomingMessageBufferSize *int64
OutgoingMessageBufferSize *int64
PeerID *p2pkey.PeerID
TraceLogging *bool
V1 P2PV1 `toml:",omitempty"`
V2 P2PV2 `toml:",omitempty"`
}
func (p *P2P) NetworkStack() ocrnetworking.NetworkingStack {
v1, v2 := *p.V1.Enabled, *p.V2.Enabled
switch {
case v1 && v2:
return ocrnetworking.NetworkingStackV1V2
case v2:
return ocrnetworking.NetworkingStackV2
case v1:
return ocrnetworking.NetworkingStackV1
}
return ocrnetworking.NetworkingStack(0)
}
func (p *P2P) setFrom(f *P2P) {
if v := f.IncomingMessageBufferSize; v != nil {
p.IncomingMessageBufferSize = v
}
if v := f.OutgoingMessageBufferSize; v != nil {
p.OutgoingMessageBufferSize = v
}
if v := f.PeerID; v != nil {
p.PeerID = v
}
if v := f.TraceLogging; v != nil {
p.TraceLogging = v
}
p.V1.setFrom(&f.V1)
p.V2.setFrom(&f.V2)
}
type P2PV1 struct {
Enabled *bool
AnnounceIP *net.IP
AnnouncePort *uint16
BootstrapCheckInterval *models.Duration
DefaultBootstrapPeers *[]string
DHTAnnouncementCounterUserPrefix *uint32
DHTLookupInterval *int64
ListenIP *net.IP
ListenPort *uint16
NewStreamTimeout *models.Duration
PeerstoreWriteInterval *models.Duration
}
func (p *P2PV1) ValidateConfig() (err error) {
//TODO or empty?
if p.AnnouncePort != nil && p.AnnounceIP == nil {
err = multierr.Append(err, ErrMissing{Name: "AnnounceIP", Msg: fmt.Sprintf("required when AnnouncePort is set: %d", *p.AnnouncePort)})
}
return
}
func (p *P2PV1) setFrom(f *P2PV1) {
if v := f.Enabled; v != nil {
p.Enabled = v
}
if v := f.AnnounceIP; v != nil {
p.AnnounceIP = v
}
if v := f.AnnouncePort; v != nil {
p.AnnouncePort = v
}
if v := f.BootstrapCheckInterval; v != nil {
p.BootstrapCheckInterval = v
}
if v := f.DefaultBootstrapPeers; v != nil {
p.DefaultBootstrapPeers = v
}
if v := f.DHTAnnouncementCounterUserPrefix; v != nil {
p.DHTAnnouncementCounterUserPrefix = v
}
if v := f.DHTLookupInterval; v != nil {
p.DHTLookupInterval = v
}
if v := f.ListenIP; v != nil {
p.ListenIP = v
}
if v := f.ListenPort; v != nil {
p.ListenPort = v
}
if v := f.NewStreamTimeout; v != nil {
p.NewStreamTimeout = v
}
if v := f.PeerstoreWriteInterval; v != nil {
p.PeerstoreWriteInterval = v
}
}
type P2PV2 struct {
Enabled *bool
AnnounceAddresses *[]string
DefaultBootstrappers *[]ocrcommontypes.BootstrapperLocator
DeltaDial *models.Duration
DeltaReconcile *models.Duration
ListenAddresses *[]string
}
func (p *P2PV2) setFrom(f *P2PV2) {
if v := f.Enabled; v != nil {
p.Enabled = v
}
if v := f.AnnounceAddresses; v != nil {
p.AnnounceAddresses = v
}
if v := f.DefaultBootstrappers; v != nil {
p.DefaultBootstrappers = v
}
if v := f.DeltaDial; v != nil {
p.DeltaDial = v
}
if v := f.DeltaReconcile; v != nil {
p.DeltaReconcile = v
}
if v := f.ListenAddresses; v != nil {
p.ListenAddresses = v
}
}
type Keeper struct {
DefaultTransactionQueueDepth *uint32
GasPriceBufferPercent *uint16
GasTipCapBufferPercent *uint16
BaseFeeBufferPercent *uint16
MaxGracePeriod *int64
TurnLookBack *int64
Registry KeeperRegistry `toml:",omitempty"`
}
func (k *Keeper) setFrom(f *Keeper) {
if v := f.DefaultTransactionQueueDepth; v != nil {
k.DefaultTransactionQueueDepth = v
}
if v := f.GasPriceBufferPercent; v != nil {
k.GasPriceBufferPercent = v
}
if v := f.GasTipCapBufferPercent; v != nil {
k.GasTipCapBufferPercent = v
}
if v := f.BaseFeeBufferPercent; v != nil {
k.BaseFeeBufferPercent = v
}
if v := f.MaxGracePeriod; v != nil {
k.MaxGracePeriod = v
}
if v := f.TurnLookBack; v != nil {
k.TurnLookBack = v
}
k.Registry.setFrom(&f.Registry)
}
type KeeperRegistry struct {
CheckGasOverhead *uint32
PerformGasOverhead *uint32
MaxPerformDataSize *uint32
SyncInterval *models.Duration
SyncUpkeepQueueSize *uint32
}
func (k *KeeperRegistry) setFrom(f *KeeperRegistry) {
if v := f.CheckGasOverhead; v != nil {
k.CheckGasOverhead = v
}
if v := f.PerformGasOverhead; v != nil {
k.PerformGasOverhead = v
}
if v := f.MaxPerformDataSize; v != nil {
k.MaxPerformDataSize = v
}
if v := f.SyncInterval; v != nil {
k.SyncInterval = v
}
if v := f.SyncUpkeepQueueSize; v != nil {
k.SyncUpkeepQueueSize = v
}
}
type AutoPprof struct {
Enabled *bool
ProfileRoot *string
PollInterval *models.Duration
GatherDuration *models.Duration
GatherTraceDuration *models.Duration
MaxProfileSize *utils.FileSize
CPUProfileRate *int64 // runtime.SetCPUProfileRate
MemProfileRate *int64 // runtime.MemProfileRate
BlockProfileRate *int64 // runtime.SetBlockProfileRate
MutexProfileFraction *int64 // runtime.SetMutexProfileFraction
MemThreshold *utils.FileSize
GoroutineThreshold *int64
}
func (p *AutoPprof) setFrom(f *AutoPprof) {
if v := f.Enabled; v != nil {
p.Enabled = v
}
if v := f.ProfileRoot; v != nil {
p.ProfileRoot = v
}
if v := f.PollInterval; v != nil {
p.PollInterval = v
}
if v := f.GatherDuration; v != nil {
p.GatherDuration = v
}
if v := f.GatherTraceDuration; v != nil {
p.GatherTraceDuration = v
}
if v := f.MaxProfileSize; v != nil {
p.MaxProfileSize = v
}
if v := f.CPUProfileRate; v != nil {
p.CPUProfileRate = v
}
if v := f.MemProfileRate; v != nil {
p.MemProfileRate = v
}
if v := f.BlockProfileRate; v != nil {
p.BlockProfileRate = v
}
if v := f.MutexProfileFraction; v != nil {
p.MutexProfileFraction = v
}
if v := f.MemThreshold; v != nil {
p.MemThreshold = v
}
if v := f.GoroutineThreshold; v != nil {
p.GoroutineThreshold = v
}
}
type Pyroscope struct {
ServerAddress *string
Environment *string
}
func (p *Pyroscope) setFrom(f *Pyroscope) {
if v := f.ServerAddress; v != nil {
p.ServerAddress = v
}
if v := f.Environment; v != nil {
p.Environment = v
}
}
type Sentry struct {
Debug *bool
DSN *string
Environment *string
Release *string
}
func (s *Sentry) setFrom(f *Sentry) {
if v := f.Debug; v != nil {
s.Debug = f.Debug
}
if v := f.DSN; v != nil {
s.DSN = f.DSN
}
if v := f.Environment; v != nil {
s.Environment = f.Environment
}
if v := f.Release; v != nil {
s.Release = f.Release
}
}