@@ -3,51 +3,33 @@ package config
33import (
44 "errors"
55 "fmt"
6+ "log"
67 "net/url"
78 "slices"
9+ "strings"
810 "time"
911
1012 sdk "github.com/cosmos/cosmos-sdk/types"
1113 "github.com/pelletier/go-toml/v2"
1214 "github.com/shopspring/decimal"
1315
1416 "github.com/smartcontractkit/chainlink-common/pkg/config"
17+ "github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
1518
16- "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client"
1719 "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db"
1820)
1921
20- // Global defaults.
21- var defaultConfigSet = configSet {
22- BlockRate : 6 * time .Second ,
23- // ~6s per block, so ~3m until we give up on the tx getting confirmed
24- // Anecdotally it appears anything more than 4 blocks would be an extremely long wait,
25- // In practice during the UST depegging and subsequent extreme congestion, we saw
26- // ~16 block FIFO lineups.
27- BlocksUntilTxTimeout : 30 ,
28- ConfirmPollPeriod : time .Second ,
29- FallbackGasPrice : sdk .MustNewDecFromStr ("0.015" ),
30- // This is high since we simulate before signing the transaction.
31- // There's a chicken and egg problem: need to sign to simulate accurately
32- // but you need to specify a gas limit when signing.
33- // TODO: Determine how much gas a signature adds and then
34- // add that directly so we can be more accurate.
35- GasLimitMultiplier : client .DefaultGasLimitMultiplier ,
36- // The max gas limit per block is 1_000_000_000
37- // https://github.com/terra-money/core/blob/d6037b9a12c8bf6b09fe861c8ad93456aac5eebb/app/legacy/migrate.go#L69.
38- // The max msg size is 10KB https://github.com/terra-money/core/blob/d6037b9a12c8bf6b09fe861c8ad93456aac5eebb/x/wasm/types/params.go#L15.
39- // Our msgs are only OCR reports for now, which will not exceed that size.
40- // There appears to be no gas limit per tx, only per block, so theoretically
41- // we could include 1000 msgs which use up to 1M gas.
42- // To be conservative and since the number of messages we'd
43- // have in a batch on average roughly corresponds to the number of terra ocr jobs we're running (do not expect more than 100),
44- // we can set a max msgs per batch of 100.
45- MaxMsgsPerBatch : 100 ,
46- OCR2CachePollPeriod : 4 * time .Second ,
47- OCR2CacheTTL : time .Minute ,
48- TxMsgTimeout : 10 * time .Minute ,
49- Bech32Prefix : "wasm" , // note: this shouldn't be used outside of tests
50- GasToken : "ucosm" , // note: this shouldn't be used outside of tests
22+ var defaults TOMLConfig
23+
24+ func init () {
25+ if err := configtest .DocDefaultsOnly (strings .NewReader (docsTOML ), & defaults , config .DecodeTOML ); err != nil {
26+ log .Fatalf ("Failed to initialize defaults from docs: %v" , err )
27+ }
28+ }
29+
30+ func Defaults () (c TOMLConfig ) {
31+ c .SetFrom (& defaults )
32+ return
5133}
5234
5335type Config interface {
@@ -93,44 +75,6 @@ type Chain struct {
9375 TxMsgTimeout * config.Duration
9476}
9577
96- func (c * Chain ) SetDefaults () {
97- if c .Bech32Prefix == nil {
98- c .Bech32Prefix = & defaultConfigSet .Bech32Prefix
99- }
100- if c .BlockRate == nil {
101- c .BlockRate = config .MustNewDuration (defaultConfigSet .BlockRate )
102- }
103- if c .BlocksUntilTxTimeout == nil {
104- c .BlocksUntilTxTimeout = & defaultConfigSet .BlocksUntilTxTimeout
105- }
106- if c .ConfirmPollPeriod == nil {
107- c .ConfirmPollPeriod = config .MustNewDuration (defaultConfigSet .ConfirmPollPeriod )
108- }
109- if c .FallbackGasPrice == nil {
110- d := decimal .NewFromBigInt (defaultConfigSet .FallbackGasPrice .BigInt (), - sdk .Precision )
111- c .FallbackGasPrice = & d
112- }
113- if c .GasToken == nil {
114- c .GasToken = & defaultConfigSet .GasToken
115- }
116- if c .GasLimitMultiplier == nil {
117- d := decimal .NewFromFloat (defaultConfigSet .GasLimitMultiplier )
118- c .GasLimitMultiplier = & d
119- }
120- if c .MaxMsgsPerBatch == nil {
121- c .MaxMsgsPerBatch = & defaultConfigSet .MaxMsgsPerBatch
122- }
123- if c .OCR2CachePollPeriod == nil {
124- c .OCR2CachePollPeriod = config .MustNewDuration (defaultConfigSet .OCR2CachePollPeriod )
125- }
126- if c .OCR2CacheTTL == nil {
127- c .OCR2CacheTTL = config .MustNewDuration (defaultConfigSet .OCR2CacheTTL )
128- }
129- if c .TxMsgTimeout == nil {
130- c .TxMsgTimeout = config .MustNewDuration (defaultConfigSet .TxMsgTimeout )
131- }
132- }
133-
13478type Node struct {
13579 Name * string
13680 TendermintURL * config.URL
@@ -249,6 +193,13 @@ func (c *TOMLConfig) IsEnabled() bool {
249193 return c .Enabled == nil || * c .Enabled
250194}
251195
196+ func (c * TOMLConfig ) SetDefaults () {
197+ def := Defaults ()
198+ def .SetFrom (c )
199+ * c = def
200+
201+ }
202+
252203func (c * TOMLConfig ) SetFrom (f * TOMLConfig ) {
253204 if f .ChainID != nil {
254205 c .ChainID = f .ChainID
0 commit comments