-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ocr1_config.go
104 lines (86 loc) · 3.61 KB
/
ocr1_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
package config
import (
"time"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/core/config/envvar"
"github.com/smartcontractkit/chainlink/core/config/parse"
"github.com/smartcontractkit/chainlink/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/core/store/models"
)
// OCR1Config is a subset of global config relevant to OCR v1.
type OCR1Config interface {
// OCR1 config, can override in jobs, only ethereum.
OCRBlockchainTimeout() time.Duration
OCRContractPollInterval() time.Duration
OCRContractSubscribeInterval() time.Duration
OCRKeyBundleID() (string, error)
OCRObservationTimeout() time.Duration
OCRSimulateTransactions() bool
OCRTransmitterAddress() (ethkey.EIP55Address, error) // OCR2 can support non-evm changes
// OCR1 config, cannot override in jobs
OCRTraceLogging() bool
OCRDefaultTransactionQueueDepth() uint32
}
func (c *generalConfig) getDuration(field string) time.Duration {
return c.getWithFallback(field, parse.Duration).(time.Duration)
}
func (c *generalConfig) GlobalOCRContractConfirmations() (uint16, bool) {
return lookupEnv(c, envvar.Name("OCRContractConfirmations"), parse.Uint16)
}
func (c *generalConfig) GlobalOCRObservationGracePeriod() (time.Duration, bool) {
return lookupEnv(c, envvar.Name("OCRObservationGracePeriod"), time.ParseDuration)
}
func (c *generalConfig) GlobalOCRContractTransmitterTransmitTimeout() (time.Duration, bool) {
return lookupEnv(c, envvar.Name("OCRContractTransmitterTransmitTimeout"), time.ParseDuration)
}
func (c *generalConfig) GlobalOCRDatabaseTimeout() (time.Duration, bool) {
return lookupEnv(c, envvar.Name("OCRDatabaseTimeout"), time.ParseDuration)
}
func (c *generalConfig) OCRContractPollInterval() time.Duration {
return c.getDuration("OCRContractPollInterval")
}
func (c *generalConfig) OCRContractSubscribeInterval() time.Duration {
return c.getDuration("OCRContractSubscribeInterval")
}
func (c *generalConfig) OCRBlockchainTimeout() time.Duration {
return c.getDuration("OCRBlockchainTimeout")
}
func (c *generalConfig) OCRKeyBundleID() (string, error) {
kbStr := c.viper.GetString(envvar.Name("OCRKeyBundleID"))
if kbStr != "" {
_, err := models.Sha256HashFromHex(kbStr)
if err != nil {
return "", errors.Wrapf(ErrEnvInvalid, "OCR_KEY_BUNDLE_ID is an invalid sha256 hash hex string %v", err)
}
}
return kbStr, nil
}
// OCRDefaultTransactionQueueDepth controls the queue size for DropOldestStrategy in OCR
// Set to 0 to use SendEvery strategy instead
func (c *generalConfig) OCRDefaultTransactionQueueDepth() uint32 {
return c.viper.GetUint32(envvar.Name("OCRDefaultTransactionQueueDepth"))
}
// OCRTraceLogging determines whether OCR logs at TRACE level are enabled. The
// option to turn them off is given because they can be very verbose
func (c *generalConfig) OCRTraceLogging() bool {
return c.viper.GetBool(envvar.Name("OCRTraceLogging"))
}
func (c *generalConfig) OCRObservationTimeout() time.Duration {
return c.getDuration("OCRObservationTimeout")
}
// OCRSimulateTransactions enables using eth_call transaction simulation before
// sending when set to true
func (c *generalConfig) OCRSimulateTransactions() bool {
return c.viper.GetBool(envvar.Name("OCRSimulateTransactions"))
}
func (c *generalConfig) OCRTransmitterAddress() (ethkey.EIP55Address, error) {
taStr := c.viper.GetString(envvar.Name("OCRTransmitterAddress"))
if taStr != "" {
ta, err := ethkey.NewEIP55Address(taStr)
if err != nil {
return "", errors.Wrapf(ErrEnvInvalid, "OCR_TRANSMITTER_ADDRESS is invalid EIP55 %v", err)
}
return ta, nil
}
return "", errors.Wrap(ErrEnvUnset, "OCR_TRANSMITTER_ADDRESS env var is not set")
}