-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
config.go
1331 lines (1240 loc) · 45.6 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 config
import (
"fmt"
"math/big"
"os"
"sync"
"time"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/pkg/errors"
"go.uber.org/multierr"
ocr "github.com/smartcontractkit/libocr/offchainreporting"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types"
"github.com/smartcontractkit/chainlink/core/assets"
evmclient "github.com/smartcontractkit/chainlink/core/chains/evm/client"
evmtypes "github.com/smartcontractkit/chainlink/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/core/config"
"github.com/smartcontractkit/chainlink/core/config/envvar"
"github.com/smartcontractkit/chainlink/core/config/parse"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/utils"
)
type ChainScopedOnlyConfig interface {
evmclient.NodeConfig
BalanceMonitorEnabled() bool
BlockEmissionIdleWarningThreshold() time.Duration
BlockHistoryEstimatorBatchSize() (size uint32)
BlockHistoryEstimatorBlockDelay() uint16
BlockHistoryEstimatorBlockHistorySize() uint16
BlockHistoryEstimatorCheckInclusionBlocks() uint16
BlockHistoryEstimatorCheckInclusionPercentile() uint16
BlockHistoryEstimatorEIP1559FeeCapBufferBlocks() uint16
BlockHistoryEstimatorTransactionPercentile() uint16
ChainID() *big.Int
EvmEIP1559DynamicFees() bool
EthTxReaperInterval() time.Duration
EthTxReaperThreshold() time.Duration
EthTxResendAfterThreshold() time.Duration
EvmFinalityDepth() uint32
EvmGasBumpPercent() uint16
EvmGasBumpThreshold() uint64
EvmGasBumpTxDepth() uint16
EvmGasBumpWei() *assets.Wei
EvmGasFeeCapDefault() *assets.Wei
EvmGasLimitDefault() uint32
EvmGasLimitMax() uint32
EvmGasLimitMultiplier() float32
EvmGasLimitTransfer() uint32
EvmGasLimitOCRJobType() *uint32
EvmGasLimitDRJobType() *uint32
EvmGasLimitVRFJobType() *uint32
EvmGasLimitFMJobType() *uint32
EvmGasLimitKeeperJobType() *uint32
EvmGasPriceDefault() *assets.Wei
EvmGasTipCapDefault() *assets.Wei
EvmGasTipCapMinimum() *assets.Wei
EvmHeadTrackerHistoryDepth() uint32
EvmHeadTrackerMaxBufferSize() uint32
EvmHeadTrackerSamplingInterval() time.Duration
EvmLogBackfillBatchSize() uint32
EvmLogKeepBlocksDepth() uint32
EvmLogPollInterval() time.Duration
EvmMaxGasPriceWei() *assets.Wei
EvmMaxInFlightTransactions() uint32
EvmMaxQueuedTransactions() uint64
EvmMinGasPriceWei() *assets.Wei
EvmNonceAutoSync() bool
EvmUseForwarders() bool
EvmRPCDefaultBatchSize() uint32
FlagsContractAddress() string
GasEstimatorMode() string
ChainType() config.ChainType
KeySpecificMaxGasPriceWei(addr gethcommon.Address) *assets.Wei
LinkContractAddress() string
OperatorFactoryAddress() string
MinIncomingConfirmations() uint32
MinimumContractPayment() *assets.Link
// OCR1 chain specific config
OCRContractConfirmations() uint16
OCRContractTransmitterTransmitTimeout() time.Duration
OCRObservationGracePeriod() time.Duration
OCRDatabaseTimeout() time.Duration
// OCR2 chain specific config
OCR2AutomationGasLimit() uint32
SetEvmGasPriceDefault(value *big.Int) error
}
//go:generate mockery --quiet --name ChainScopedConfig --output ./mocks/ --case=underscore
type ChainScopedConfig interface {
config.BasicConfig
ChainScopedOnlyConfig
Validate() error
// Both Configure() and PersistedConfig() should be accessed through ChainSet methods only.
Configure(config evmtypes.ChainCfg)
PersistedConfig() evmtypes.ChainCfg
}
// https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config
type LegacyChainScopedConfig interface {
ChainScopedConfig
config.GeneralConfig
}
var _ ChainScopedConfig = &chainScopedConfig{}
// https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config
type chainScopedConfig struct {
config.GeneralConfig
logger logger.Logger
defaultSet chainSpecificConfigDefaultSet
persistedCfg evmtypes.ChainCfg
persistMu sync.RWMutex
orm *chainScopedConfigORM // calls should be paired with persistedCfg updates while holding write lock
id *big.Int
knownID bool // part of the default set
onceMap map[string]struct{}
onceMapMu sync.RWMutex
}
// https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config
func NewChainScopedConfig(chainID *big.Int, cfg evmtypes.ChainCfg, orm evmtypes.ChainConfigORM, lggr logger.Logger, gcfg config.GeneralConfig) LegacyChainScopedConfig {
csorm := &chainScopedConfigORM{*utils.NewBig(chainID), orm}
defaultSet, exists := chainSpecificConfigDefaultSets[chainID.Int64()]
if !exists {
lggr.Warnf("Unrecognised chain %d, falling back to generic default configuration", chainID)
defaultSet = fallbackDefaultSet
}
css := chainScopedConfig{
GeneralConfig: gcfg,
logger: lggr,
defaultSet: defaultSet,
orm: csorm,
id: chainID,
knownID: exists,
onceMap: make(map[string]struct{})}
css.Configure(cfg)
return &css
}
func (c *chainScopedConfig) Validate() (err error) {
return multierr.Combine(
c.GeneralConfig.Validate(),
c.validate(),
)
}
func (c *chainScopedConfig) Configure(config evmtypes.ChainCfg) {
c.persistMu.Lock()
defer c.persistMu.Unlock()
c.persistedCfg = config
}
func (c *chainScopedConfig) PersistedConfig() evmtypes.ChainCfg {
c.persistMu.RLock()
defer c.persistMu.RUnlock()
return c.persistedCfg
}
func (c *chainScopedConfig) validate() (err error) {
ethGasBumpPercent := c.EvmGasBumpPercent()
if uint64(ethGasBumpPercent) < core.DefaultTxPoolConfig.PriceBump {
err = multierr.Combine(err, errors.Errorf(
"ETH_GAS_BUMP_PERCENT of %v may not be less than Geth's default of %v",
c.EvmGasBumpPercent(),
core.DefaultTxPoolConfig.PriceBump,
))
}
if uint32(c.EvmGasBumpTxDepth()) > c.EvmMaxInFlightTransactions() {
err = multierr.Combine(err, errors.New("ETH_GAS_BUMP_TX_DEPTH must be less than or equal to ETH_MAX_IN_FLIGHT_TRANSACTIONS"))
}
if c.EvmGasTipCapDefault().Cmp(c.EvmGasTipCapMinimum()) < 0 {
err = multierr.Combine(err, errors.Errorf("EVM_GAS_TIP_CAP_DEFAULT (%s) must be greater than or equal to EVM_GAS_TIP_CAP_MINIMUM (%s)", c.EvmGasTipCapDefault(), c.EvmGasTipCapMinimum()))
}
if c.EvmGasFeeCapDefault().Cmp(c.EvmGasTipCapDefault()) < 0 {
err = multierr.Combine(err, errors.Errorf("EVM_GAS_FEE_CAP_DEFAULT (%s) must be greater than or equal to EVM_GAS_TIP_CAP_DEFAULT (%s)", c.EvmGasFeeCapDefault(), c.EvmGasTipCapDefault()))
}
if c.EvmGasBumpThreshold() == 0 && c.GasEstimatorMode() == "FixedPrice" && c.EvmGasFeeCapDefault().Cmp(c.EvmMaxGasPriceWei()) != 0 && c.EvmEIP1559DynamicFees() {
// EvmGasFeeCapDefault MUST == EvmMaxGasPriceWei in EIP1559 mode if fixed estimator mode is on and gas bumping is disabled
err = multierr.Combine(err, errors.Errorf("You are using FixedPrice estimator with gas bumping disabled in EIP1559 mode. ETH_MAX_GAS_PRICE_WEI (current value: %s) will be used as the FeeCap for transactions instead of EVM_GAS_FEE_CAP_DEFAULT (current value: %s). To prevent surprising behaviour, you are required to set EVM_GAS_FEE_CAP_DEFAULT and ETH_MAX_GAS_PRICE_WEI to the same value in this mode", c.EvmMaxGasPriceWei(), c.EvmGasFeeCapDefault()))
} else if c.EvmGasFeeCapDefault().Cmp(c.EvmMaxGasPriceWei()) > 0 {
err = multierr.Combine(err, errors.Errorf("EVM_GAS_FEE_CAP_DEFAULT (%s) must be less than or equal to ETH_MAX_GAS_PRICE_WEI (%s)", c.EvmGasFeeCapDefault(), c.EvmMaxGasPriceWei()))
}
if c.EvmMinGasPriceWei().Cmp(c.EvmGasPriceDefault()) > 0 {
err = multierr.Combine(err, errors.New("ETH_MIN_GAS_PRICE_WEI must be less than or equal to ETH_GAS_PRICE_DEFAULT"))
}
if c.EvmMaxGasPriceWei().Cmp(c.EvmGasPriceDefault()) < 0 {
err = multierr.Combine(err, errors.New("ETH_MAX_GAS_PRICE_WEI must be greater than or equal to ETH_GAS_PRICE_DEFAULT"))
}
if c.EvmHeadTrackerHistoryDepth() < c.EvmFinalityDepth() {
err = multierr.Combine(err, errors.New("ETH_HEAD_TRACKER_HISTORY_DEPTH must be equal to or greater than ETH_FINALITY_DEPTH"))
}
if c.GasEstimatorMode() == "BlockHistory" && c.BlockHistoryEstimatorBlockHistorySize() <= 0 {
err = multierr.Combine(err, errors.New("BLOCK_HISTORY_ESTIMATOR_BLOCK_HISTORY_SIZE must be greater than or equal to 1 if block history estimator is enabled"))
}
if c.EvmFinalityDepth() < 1 {
err = multierr.Combine(err, errors.New("ETH_FINALITY_DEPTH must be greater than or equal to 1"))
}
if c.MinIncomingConfirmations() < 1 {
err = multierr.Combine(err, errors.New("MIN_INCOMING_CONFIRMATIONS must be greater than or equal to 1"))
}
lc := ocrtypes.LocalConfig{
BlockchainTimeout: c.OCRBlockchainTimeout(),
ContractConfigConfirmations: c.OCRContractConfirmations(),
ContractConfigTrackerPollInterval: c.OCRContractPollInterval(),
ContractConfigTrackerSubscribeInterval: c.OCRContractSubscribeInterval(),
ContractTransmitterTransmitTimeout: c.OCRContractTransmitterTransmitTimeout(),
DatabaseTimeout: c.OCRDatabaseTimeout(),
DataSourceTimeout: c.OCRObservationTimeout(),
DataSourceGracePeriod: c.OCRObservationGracePeriod(),
}
if ocrerr := ocr.SanityCheckLocalConfig(lc); ocrerr != nil {
err = multierr.Combine(err, ocrerr)
}
chainType := c.ChainType()
if !chainType.IsValid() {
err = multierr.Combine(err, errors.Errorf("CHAIN_TYPE %q unrecognised", chainType))
} else if c.knownID && c.defaultSet.chainType != chainType {
// Exclude Optimism Bedrock for now, until the upgrade is over.
if chainType != config.ChainOptimismBedrock {
err = multierr.Combine(err, errors.Errorf("CHAIN_TYPE %q cannot be used with chain ID %d", chainType, c.ChainID()))
}
} else {
switch chainType {
case config.ChainOptimism, config.ChainMetis:
gasEst := c.GasEstimatorMode()
switch gasEst {
case "Optimism2", "L2Suggested":
// valid
case "Optimism":
err = multierr.Combine(err, errors.Errorf("GAS_ESTIMATOR_MODE %q is no longer supported since OVM 1.0 was discontinued - use %q", "Optimism", "L2Suggested"))
default:
err = multierr.Combine(err, errors.Errorf("GAS_ESTIMATOR_MODE %q is not allowed with chain type %q - "+
"must be %q (or the equivalent, deprecated %q)", gasEst, chainType, "L2Suggested", "Optimism2"))
}
case config.ChainArbitrum, config.ChainXDai:
}
}
return err
}
func (c *chainScopedConfig) ChainID() *big.Int {
return c.id
}
func (c *chainScopedConfig) logEnvOverrideOnce(name string, envVal interface{}) {
k := fmt.Sprintf("env-%s", name)
c.onceMapMu.RLock()
if _, ok := c.onceMap[k]; ok {
c.onceMapMu.RUnlock()
return
}
c.onceMapMu.RUnlock()
c.onceMapMu.Lock()
defer c.onceMapMu.Unlock()
if _, ok := c.onceMap[k]; ok {
return
}
c.logger.Warnf("Global ENV var set %s=%v, overriding all non key-specific values for %s", envvar.TryName(name), envVal, name)
c.onceMap[k] = struct{}{}
}
func (c *chainScopedConfig) logPersistedOverrideOnce(name string, pstVal interface{}) {
k := fmt.Sprintf("pst-%s", name)
c.onceMapMu.RLock()
if _, ok := c.onceMap[k]; ok {
c.onceMapMu.RUnlock()
return
}
c.onceMapMu.RUnlock()
c.onceMapMu.Lock()
defer c.onceMapMu.Unlock()
if _, ok := c.onceMap[k]; ok {
return
}
c.logger.Infof("User-specified var set %s=%v, overriding chain-specific default value for %s", name, pstVal, name)
c.onceMap[k] = struct{}{}
}
func (c *chainScopedConfig) logKeySpecificOverrideOnce(name string, addr gethcommon.Address, pstVal interface{}) {
k := fmt.Sprintf("ksp-%s", name)
c.onceMapMu.RLock()
if _, ok := c.onceMap[k]; ok {
c.onceMapMu.RUnlock()
return
}
c.onceMapMu.RUnlock()
c.onceMapMu.Lock()
defer c.onceMapMu.Unlock()
if _, ok := c.onceMap[k]; ok {
return
}
c.logger.Infof("Key-specific var set %s=%v for key %s, overriding chain-specific values for %s", name, pstVal, addr.Hex(), name)
c.onceMap[k] = struct{}{}
}
// EvmGasBumpThreshold is the number of blocks to wait before bumping gas again on unconfirmed transactions
// Set to 0 to disable gas bumping
func (c *chainScopedConfig) EvmGasBumpThreshold() uint64 {
val, ok := c.GeneralConfig.GlobalEvmGasBumpThreshold()
if ok {
c.logEnvOverrideOnce("EvmGasBumpThreshold", val)
return val
}
return c.defaultSet.gasBumpThreshold
}
// EvmGasBumpWei is the minimum fixed amount of wei by which gas is bumped on each transaction attempt
func (c *chainScopedConfig) EvmGasBumpWei() *assets.Wei {
val, ok := c.GeneralConfig.GlobalEvmGasBumpWei()
if ok {
c.logEnvOverrideOnce("EvmGasBumpWei", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasBumpWei
c.persistMu.RUnlock()
if p != nil {
c.logPersistedOverrideOnce("EvmGasBumpWei", p)
return p
}
n := c.defaultSet.gasBumpWei
return &n
}
// EvmMaxInFlightTransactions controls how many transactions are allowed to be
// "in-flight" i.e. broadcast but unconfirmed at any one time
// 0 value disables the limit
func (c *chainScopedConfig) EvmMaxInFlightTransactions() uint32 {
val, ok := c.GeneralConfig.GlobalEvmMaxInFlightTransactions()
if ok {
c.logEnvOverrideOnce("EvmMaxInFlightTransactions", val)
return val
}
return c.defaultSet.maxInFlightTransactions
}
// EvmMaxGasPriceWei is the maximum amount in Wei that a transaction will be
// bumped to before abandoning it and marking it as errored.
func (c *chainScopedConfig) EvmMaxGasPriceWei() *assets.Wei {
val, ok := c.GeneralConfig.GlobalEvmMaxGasPriceWei()
if ok {
c.logEnvOverrideOnce("EvmMaxGasPriceWei", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmMaxGasPriceWei
c.persistMu.RUnlock()
if p != nil {
c.logPersistedOverrideOnce("EvmMaxGasPriceWei", p)
return p
}
n := c.defaultSet.maxGasPriceWei
return &n
}
// EvmMaxQueuedTransactions is the maximum number of unbroadcast
// transactions per key that are allowed to be enqueued before jobs will start
// failing and rejecting send of any further transactions.
// 0 value disables
func (c *chainScopedConfig) EvmMaxQueuedTransactions() uint64 {
val, ok := c.GeneralConfig.GlobalEvmMaxQueuedTransactions()
if ok {
c.logEnvOverrideOnce("EvmMaxQueuedTransactions", val)
return val
}
return c.defaultSet.maxQueuedTransactions
}
// EvmMinGasPriceWei is the minimum amount in Wei that a transaction may be priced.
// Chainlink will never send a transaction priced below this amount.
func (c *chainScopedConfig) EvmMinGasPriceWei() *assets.Wei {
val, ok := c.GeneralConfig.GlobalEvmMinGasPriceWei()
if ok {
c.logEnvOverrideOnce("EvmMinGasPriceWei", val)
return val
}
n := c.defaultSet.minGasPriceWei
return &n
}
// EvmGasLimitDefault sets the default gas limit for outgoing transactions.
func (c *chainScopedConfig) EvmGasLimitDefault() uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitDefault()
if ok {
c.logEnvOverrideOnce("EvmGasLimitDefault", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasLimitDefault
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasLimitDefault", p.Int64)
return uint32(p.Int64)
}
return c.defaultSet.gasLimitDefault
}
// EvmGasLimitOCRJobType overrides the default gas limit for OCR jobs.
func (c *chainScopedConfig) EvmGasLimitOCRJobType() *uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitOCRJobType()
if ok {
c.logEnvOverrideOnce("EvmGasLimitOCRJobType", val)
return &val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasLimitOCRJobType
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasLimitOCRJobType", p.Int64)
v := uint32(p.Int64)
return &v
}
return c.defaultSet.gasLimitOCRJobType
}
// EvmGasLimitDRJobType overrides the default gas limit for Direct Request jobs.
func (c *chainScopedConfig) EvmGasLimitDRJobType() *uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitDRJobType()
if ok {
c.logEnvOverrideOnce("EvmGasLimitDRJobType", val)
return &val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasLimitDRJobType
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasLimitDRJobType", p.Int64)
v := uint32(p.Int64)
return &v
}
return c.defaultSet.gasLimitDRJobType
}
// EvmGasLimitVRFJobType overrides the default gas limit for VRF jobs.
func (c *chainScopedConfig) EvmGasLimitVRFJobType() *uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitVRFJobType()
if ok {
c.logEnvOverrideOnce("EvmGasLimitVRFJobType", val)
return &val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasLimitVRFJobType
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasLimitVRFJobType", p.Int64)
v := uint32(p.Int64)
return &v
}
return c.defaultSet.gasLimitVRFJobType
}
// EvmGasLimitFMJobType overrides the default gas limit for Flux Monitor jobs.
func (c *chainScopedConfig) EvmGasLimitFMJobType() *uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitFMJobType()
if ok {
c.logEnvOverrideOnce("EvmGasLimitFMJobType", val)
return &val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasLimitFMJobType
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasLimitFMJobType", p.Int64)
v := uint32(p.Int64)
return &v
}
return c.defaultSet.gasLimitFMJobType
}
// EvmGasLimitKeeperJobType overrides the default gas limit for Keeper jobs.
func (c *chainScopedConfig) EvmGasLimitKeeperJobType() *uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitKeeperJobType()
if ok {
c.logEnvOverrideOnce("EvmGasLimitKeeperJobType", val)
return &val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasLimitKeeperJobType
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasLimitKeeperJobType", p.Int64)
v := uint32(p.Int64)
return &v
}
return c.defaultSet.gasLimitKeeperJobType
}
// EvmGasLimitTransfer is the gas limit for an ordinary eth->eth transfer
func (c *chainScopedConfig) EvmGasLimitTransfer() uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitTransfer()
if ok {
c.logEnvOverrideOnce("EvmGasLimitTransfer", val)
return val
}
return c.defaultSet.gasLimitTransfer
}
// EvmGasPriceDefault is the starting gas price for every transaction
func (c *chainScopedConfig) EvmGasPriceDefault() *assets.Wei {
val, ok := c.GeneralConfig.GlobalEvmGasPriceDefault()
if ok {
c.logEnvOverrideOnce("EvmGasPriceDefault", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasPriceDefault
c.persistMu.RUnlock()
if p != nil {
c.logPersistedOverrideOnce("EvmGasPriceDefault", p)
return p
}
n := c.defaultSet.gasPriceDefault
return &n
}
// SetEvmGasPriceDefault saves a runtime value for the default gas price for transactions
// nil or negative value clears
func (c *chainScopedConfig) SetEvmGasPriceDefault(value *big.Int) error {
if value == nil || value.Cmp(big.NewInt(0)) < 0 {
c.persistMu.Lock()
defer c.persistMu.Unlock()
c.persistedCfg.EvmGasPriceDefault = nil
return c.orm.clear("EvmGasPriceDefault")
}
min := c.EvmMinGasPriceWei()
max := c.EvmMaxGasPriceWei()
if value.Cmp(min.ToInt()) < 0 {
return errors.Errorf("cannot set default gas price to %s, it is below the minimum allowed value of %s", value.String(), min.String())
}
if value.Cmp(max.ToInt()) > 0 {
return errors.Errorf("cannot set default gas price to %s, it is above the maximum allowed value of %s", value.String(), max.String())
}
c.persistMu.Lock()
defer c.persistMu.Unlock()
c.persistedCfg.EvmGasPriceDefault = assets.NewWei(value)
return c.orm.storeString("EvmGasPriceDefault", value.String())
}
// EvmFinalityDepth is the number of blocks after which an ethereum transaction is considered "final"
// BlocksConsideredFinal determines how deeply we look back to ensure that transactions are confirmed onto the longest chain
// There is not a large performance penalty to setting this relatively high (on the order of hundreds)
// It is practically limited by the number of heads we store in the database and should be less than this with a comfortable margin.
// If a transaction is mined in a block more than this many blocks ago, and is reorged out, we will NOT retransmit this transaction and undefined behaviour can occur including gaps in the nonce sequence that require manual intervention to fix.
// Therefore this number represents a number of blocks we consider large enough that no re-org this deep will ever feasibly happen.
//
// Special cases:
// ETH_FINALITY_DEPTH=0 would imply that transactions can be final even before they were mined into a block. This is not supported.
// ETH_FINALITY_DEPTH=1 implies that transactions are final after we see them in one block.
//
// Examples:
//
// Transaction sending:
// A transaction is sent at block height 42
//
// ETH_FINALITY_DEPTH is set to 5
// A re-org occurs at height 44 starting at block 41, transaction is marked for rebroadcast
// A re-org occurs at height 46 starting at block 41, transaction is marked for rebroadcast
// A re-org occurs at height 47 starting at block 41, transaction is NOT marked for rebroadcast
func (c *chainScopedConfig) EvmFinalityDepth() uint32 {
val, ok := c.GeneralConfig.GlobalEvmFinalityDepth()
if ok {
c.logEnvOverrideOnce("EvmFinalityDepth", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmFinalityDepth
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmFinalityDepth", p.Int64)
return uint32(p.Int64)
}
return c.defaultSet.finalityDepth
}
// EvmHeadTrackerHistoryDepth tracks the top N block numbers to keep in the `heads` database table.
// Note that this can easily result in MORE than N records since in the case of re-orgs we keep multiple heads for a particular block height.
// This number should be at least as large as `EvmFinalityDepth`.
// There may be a small performance penalty to setting this to something very large (10,000+)
func (c *chainScopedConfig) EvmHeadTrackerHistoryDepth() uint32 {
val, ok := c.GeneralConfig.GlobalEvmHeadTrackerHistoryDepth()
if ok {
c.logEnvOverrideOnce("EvmHeadTrackerHistoryDepth", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmHeadTrackerHistoryDepth
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmHeadTrackerHistoryDepth", p.Int64)
return uint32(p.Int64)
}
return c.defaultSet.headTrackerHistoryDepth
}
// EvmHeadTrackerSamplingInterval is the interval between sampled head callbacks
// to services that are only interested in the latest head every some time
// Setting it to a zero duration disables sampling (every head will be delivered)
func (c *chainScopedConfig) EvmHeadTrackerSamplingInterval() time.Duration {
val, ok := c.GeneralConfig.GlobalEvmHeadTrackerSamplingInterval()
if ok {
c.logEnvOverrideOnce("EvmHeadTrackerSamplingInterval", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmHeadTrackerSamplingInterval
c.persistMu.RUnlock()
if p != nil {
c.logPersistedOverrideOnce("EvmHeadTrackerSamplingInterval", p.Duration())
return p.Duration()
}
return c.defaultSet.headTrackerSamplingInterval
}
// BlockEmissionIdleWarningThreshold is the duration of time since last received head
// to print a warning log message indicating not receiving heads
func (c *chainScopedConfig) BlockEmissionIdleWarningThreshold() time.Duration {
val, ok := c.GeneralConfig.GlobalBlockEmissionIdleWarningThreshold()
if ok {
c.logEnvOverrideOnce("BlockEmissionIdleWarningThreshold", val)
return val
}
return c.defaultSet.blockEmissionIdleWarningThreshold
}
// EthTxResendAfterThreshold controls how long the ethResender will wait before
// re-sending the latest eth_tx_attempt. This is designed a as a fallback to
// protect against the eth nodes dropping txes (it has been anecdotally
// observed to happen), networking issues or txes being ejected from the
// mempool.
// See eth_resender.go for more details
func (c *chainScopedConfig) EthTxResendAfterThreshold() time.Duration {
val, ok := c.GeneralConfig.GlobalEthTxResendAfterThreshold()
if ok {
c.logEnvOverrideOnce("EthTxResendAfterThreshold", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EthTxResendAfterThreshold
c.persistMu.RUnlock()
if p != nil {
c.logPersistedOverrideOnce("EthTxResendAfterThreshold", p.Duration())
return p.Duration()
}
return c.defaultSet.ethTxResendAfterThreshold
}
// BlockHistoryEstimatorBatchSize sets the maximum number of blocks to fetch in one batch in the block history estimator
// If the env var GAS_UPDATER_BATCH_SIZE is set to 0, it defaults to ETH_RPC_DEFAULT_BATCH_SIZE
func (c *chainScopedConfig) BlockHistoryEstimatorBatchSize() (size uint32) {
val, ok := c.GeneralConfig.GlobalBlockHistoryEstimatorBatchSize()
if ok {
c.logEnvOverrideOnce("BlockHistoryEstimatorBatchSize", val)
size = val
} else {
valLegacy, set := lookupEnv(c, "GAS_UPDATER_BATCH_SIZE", parse.Uint32)
if set {
c.logEnvOverrideOnce("GAS_UPDATER_BATCH_SIZE", valLegacy)
c.logger.Error("GAS_UPDATER_BATCH_SIZE is deprecated, please use BLOCK_HISTORY_ESTIMATOR_BATCH_SIZE instead (or simply remove to use the default)")
size = valLegacy
} else {
size = c.defaultSet.blockHistoryEstimatorBatchSize
}
}
if size > 0 {
return size
}
return c.EvmRPCDefaultBatchSize()
}
// BlockHistoryEstimatorBlockDelay is the number of blocks that the block history estimator trails behind head.
// E.g. if this is set to 3, and we receive block 10, block history estimator will
// fetch block 7.
// CAUTION: You might be tempted to set this to 0 to use the latest possible
// block, but it is possible to receive a head BEFORE that block is actually
// available from the connected node via RPC. In this case you will get false
// "zero" blocks that are missing transactions.
func (c *chainScopedConfig) BlockHistoryEstimatorBlockDelay() uint16 {
val, ok := c.GeneralConfig.GlobalBlockHistoryEstimatorBlockDelay()
if ok {
c.logEnvOverrideOnce("BlockHistoryEstimatorBlockDelay", val)
return val
}
valLegacy, set := lookupEnv(c, "GAS_UPDATER_BLOCK_DELAY", parse.Uint16)
if set {
c.logEnvOverrideOnce("GAS_UPDATER_BLOCK_DELAY", valLegacy)
c.logger.Error("GAS_UPDATER_BLOCK_DELAY is deprecated, please use BLOCK_HISTORY_ESTIMATOR_BLOCK_DELAY instead (or simply remove to use the default)")
return valLegacy
}
c.persistMu.RLock()
p := c.persistedCfg.BlockHistoryEstimatorBlockDelay
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("BlockHistoryEstimatorBlockDelay", p.Int64)
return uint16(p.Int64)
}
return c.defaultSet.blockHistoryEstimatorBlockDelay
}
// BlockHistoryEstimatorBlockHistorySize is the number of past blocks to keep in memory to
// use as a basis for calculating a percentile gas price
func (c *chainScopedConfig) BlockHistoryEstimatorBlockHistorySize() uint16 {
val, ok := c.GeneralConfig.GlobalBlockHistoryEstimatorBlockHistorySize()
if ok {
c.logEnvOverrideOnce("BlockHistoryEstimatorBlockHistorySize", val)
return val
}
valLegacy, set := lookupEnv(c, "GAS_UPDATER_BLOCK_HISTORY_SIZE", parse.Uint16)
if set {
c.logEnvOverrideOnce("GAS_UPDATER_BLOCK_HISTORY_SIZE", valLegacy)
c.logger.Error("GAS_UPDATER_BLOCK_HISTORY_SIZE is deprecated, please use BLOCK_HISTORY_ESTIMATOR_BLOCK_HISTORY_SIZE instead (or simply remove to use the default)")
return valLegacy
}
c.persistMu.RLock()
p := c.persistedCfg.BlockHistoryEstimatorBlockHistorySize
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("BlockHistoryEstimatorBlockHistorySize", p.Int64)
return uint16(p.Int64)
}
return c.defaultSet.blockHistoryEstimatorBlockHistorySize
}
func (c *chainScopedConfig) BlockHistoryEstimatorEIP1559FeeCapBufferBlocks() uint16 {
val, ok := c.GeneralConfig.GlobalBlockHistoryEstimatorEIP1559FeeCapBufferBlocks()
if ok {
c.logEnvOverrideOnce("BlockHistoryEstimatorEIP1559FeeCapBufferBlocks", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.BlockHistoryEstimatorEIP1559FeeCapBufferBlocks
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("BlockHistoryEstimatorEIP1559FeeCapBufferBlocks", p.Int64)
return uint16(p.Int64)
}
// Default is the gas bump threshold + 1 block
return uint16(c.EvmGasBumpThreshold() + 1)
}
func (c *chainScopedConfig) BlockHistoryEstimatorCheckInclusionBlocks() uint16 {
val, ok := c.GeneralConfig.GlobalBlockHistoryEstimatorCheckInclusionBlocks()
if ok {
c.logEnvOverrideOnce("BlockHistoryEstimatorCheckInclusionBlocks", val)
return val
}
return c.defaultSet.blockHistoryEstimatorCheckInclusionBlocks
}
func (c *chainScopedConfig) BlockHistoryEstimatorCheckInclusionPercentile() uint16 {
val, ok := c.GeneralConfig.GlobalBlockHistoryEstimatorCheckInclusionPercentile()
if ok {
c.logEnvOverrideOnce("BlockHistoryEstimatorCheckInclusionPercentile", val)
return val
}
return c.defaultSet.blockHistoryEstimatorCheckInclusionPercentile
}
// BlockHistoryEstimatorTransactionPercentile is the percentile gas price to choose. E.g.
// if the past transaction history contains four transactions with gas prices:
// [100, 200, 300, 400], picking 25 for this number will give a value of 200
func (c *chainScopedConfig) BlockHistoryEstimatorTransactionPercentile() uint16 {
val, ok := c.GeneralConfig.GlobalBlockHistoryEstimatorTransactionPercentile()
if ok {
c.logEnvOverrideOnce("BlockHistoryEstimatorTransactionPercentile", val)
return val
}
valLegacy, set := lookupEnv(c, "GAS_UPDATER_TRANSACTION_PERCENTILE", parse.Uint16)
if set {
c.logEnvOverrideOnce("GAS_UPDATER_TRANSACTION_PERCENTILE", valLegacy)
c.logger.Error("GAS_UPDATER_TRANSACTION_PERCENTILE is deprecated, please use BLOCK_HISTORY_ESTIMATOR_TRANSACTION_PERCENTILE instead (or simply remove to use the default)")
return valLegacy
}
return c.defaultSet.blockHistoryEstimatorTransactionPercentile
}
// GasEstimatorMode controls what type of gas estimator is used
func (c *chainScopedConfig) GasEstimatorMode() string {
val, ok := c.GeneralConfig.GlobalGasEstimatorMode()
if ok {
c.logEnvOverrideOnce("GasEstimatorMode", val)
return val
}
enabled, set := lookupEnv(c, "GAS_UPDATER_ENABLED", parse.Bool)
if set {
c.logEnvOverrideOnce("GAS_UPDATER_ENABLED", enabled)
if enabled.(bool) {
c.logger.Error("GAS_UPDATER_ENABLED has been deprecated, to enable the block history estimator, please use GAS_ESTIMATOR_MODE=BlockHistory instead (or simply remove to use the default)")
return "BlockHistory"
}
c.logger.Error("GAS_UPDATER_ENABLED has been deprecated, to disable the block history estimator, please use GAS_ESTIMATOR_MODE=FixedPrice instead (or simply remove to use the default)")
return "FixedPrice"
}
c.persistMu.RLock()
p := c.persistedCfg.GasEstimatorMode
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("GasEstimatorMode", p.String)
return p.String
}
return c.defaultSet.gasEstimatorMode
}
func (c *chainScopedConfig) KeySpecificMaxGasPriceWei(addr gethcommon.Address) *assets.Wei {
c.persistMu.RLock()
keySpecific := c.persistedCfg.KeySpecific[addr.Hex()].EvmMaxGasPriceWei
c.persistMu.RUnlock()
chainSpecific := c.EvmMaxGasPriceWei()
if keySpecific != nil && !keySpecific.Equal(assets.NewWeiI(0)) && keySpecific.Cmp(chainSpecific) < 0 {
c.logKeySpecificOverrideOnce("EvmMaxGasPriceWei", addr, keySpecific)
return keySpecific
}
return c.EvmMaxGasPriceWei()
}
func (c *chainScopedConfig) ChainType() config.ChainType {
val, ok := c.GeneralConfig.GlobalChainType()
if ok {
c.logEnvOverrideOnce("ChainType", val)
return config.ChainType(val)
}
c.persistMu.RLock()
p := c.persistedCfg.ChainType
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("ChainType", p.String)
return config.ChainType(p.String)
}
return c.defaultSet.chainType
}
// LinkContractAddress represents the address of the official LINK token
// contract on the current Chain
func (c *chainScopedConfig) LinkContractAddress() string {
val, ok := c.GeneralConfig.GlobalLinkContractAddress()
if ok {
c.logEnvOverrideOnce("LinkContractAddress", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.LinkContractAddress
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("LinkContractAddress", p.String)
return p.String
}
return c.defaultSet.linkContractAddress
}
// OperatorFactoryAddress represents the address of the OperatorFactory
// contract on the current Chain
func (c *chainScopedConfig) OperatorFactoryAddress() string {
val, ok := c.GeneralConfig.GlobalOperatorFactoryAddress()
if ok {
c.logEnvOverrideOnce("OperatorFactoryAddress", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.OperatorFactoryAddress
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("OperatorFactoryAddress", p.String)
return p.String
}
return c.defaultSet.linkContractAddress
}
// MinIncomingConfirmations represents the minimum number of block
// confirmations that need to be recorded since a job run started before a task
// can proceed.
// MIN_INCOMING_CONFIRMATIONS=1 would kick off a job after seeing the transaction in a block
// MIN_INCOMING_CONFIRMATIONS=0 would kick off a job even before the transaction is mined, which is not supported
func (c *chainScopedConfig) MinIncomingConfirmations() uint32 {
val, ok := c.GeneralConfig.GlobalMinIncomingConfirmations()
if ok {
c.logEnvOverrideOnce("MinIncomingConfirmations", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.MinIncomingConfirmations
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("MinIncomingConfirmations", p.Int64)
return uint32(p.Int64)
}
return c.defaultSet.minIncomingConfirmations
}
// MinimumContractPayment represents the minimum amount of LINK that must be
// supplied for a contract to be considered.
func (c *chainScopedConfig) MinimumContractPayment() *assets.Link {
val, ok := c.GeneralConfig.GlobalMinimumContractPayment()
if ok {
c.logEnvOverrideOnce("MinimumContractPayment", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.MinimumContractPayment
c.persistMu.RUnlock()
if p != nil {
c.logPersistedOverrideOnce("MinimumContractPayment", p)
return p
}
return c.defaultSet.minimumContractPayment
}
// EvmGasBumpTxDepth is the number of transactions to gas bump starting from oldest.
// Set to 0 for no limit (i.e. bump all)
func (c *chainScopedConfig) EvmGasBumpTxDepth() uint16 {
val, ok := c.GeneralConfig.GlobalEvmGasBumpTxDepth()
if ok {
c.logEnvOverrideOnce("EvmGasBumpTxDepth", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasBumpTxDepth
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasBumpTxDepth", p.Int64)
return uint16(p.Int64)
}
return c.defaultSet.gasBumpTxDepth
}
// EvmGasBumpPercent is the minimum percentage by which gas is bumped on each transaction attempt
// Change with care since values below geth's default will fail with "underpriced replacement transaction"
func (c *chainScopedConfig) EvmGasBumpPercent() uint16 {
val, ok := c.GeneralConfig.GlobalEvmGasBumpPercent()
if ok {
c.logEnvOverrideOnce("EvmGasBumpPercent", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmGasBumpPercent
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmGasBumpPercent", p.Int64)
return uint16(p.Int64)
}
return c.defaultSet.gasBumpPercent
}
// EvmNonceAutoSync enables/disables running the NonceSyncer on application start
func (c *chainScopedConfig) EvmNonceAutoSync() bool {
val, ok := c.GeneralConfig.GlobalEvmNonceAutoSync()
if ok {
c.logEnvOverrideOnce("EvmNonceAutoSync", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmNonceAutoSync
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmNonceAutoSync", p.Bool)
return p.Bool
}
return c.defaultSet.nonceAutoSync
}
// EvmUseForwarders enables/disables sending transactions through forwarder contracts
func (c *chainScopedConfig) EvmUseForwarders() bool {
val, ok := c.GeneralConfig.GlobalEvmUseForwarders()
if ok {
c.logEnvOverrideOnce("EvmUseForwarders", val)
return val
}
c.persistMu.RLock()
p := c.persistedCfg.EvmUseForwarders
c.persistMu.RUnlock()
if p.Valid {
c.logPersistedOverrideOnce("EvmUseForwarders", p.Bool)
return p.Bool
}
return c.defaultSet.useForwarders
}
func (c *chainScopedConfig) EvmGasLimitMax() uint32 {
val, ok := c.GeneralConfig.GlobalEvmGasLimitMax()
if ok {
c.logEnvOverrideOnce("EvmGasLimitMax", val)
return val
}
c.persistMu.RLock()