-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathflags.go
More file actions
391 lines (344 loc) · 10.9 KB
/
flags.go
File metadata and controls
391 lines (344 loc) · 10.9 KB
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
package cmd
import (
"fmt"
"math/big"
"github.com/spf13/cobra"
commonEthereum "github.com/keep-network/keep-common/pkg/chain/ethereum"
"github.com/keep-network/keep-common/pkg/chain/ethereum/ethutil"
"github.com/keep-network/keep-common/pkg/cmd/flag"
"github.com/keep-network/keep-common/pkg/rate"
"github.com/keep-network/keep-core/config"
"github.com/keep-network/keep-core/config/network"
"github.com/keep-network/keep-core/pkg/bitcoin/electrum"
chainEthereum "github.com/keep-network/keep-core/pkg/chain/ethereum"
"github.com/keep-network/keep-core/pkg/clientinfo"
"github.com/keep-network/keep-core/pkg/maintainer/spv"
"github.com/keep-network/keep-core/pkg/net/libp2p"
"github.com/keep-network/keep-core/pkg/tbtc"
)
func initGlobalFlags(
cmd *cobra.Command,
configFilePath *string,
) {
initGlobalConfigFlags(cmd, configFilePath)
initGlobalNetworkFlags(cmd)
}
func initFlags(
cmd *cobra.Command,
configFilePath *string,
cfg *config.Config,
categories ...config.Category,
) {
for _, category := range categories {
switch category {
case config.Ethereum:
initEthereumFlags(cmd, cfg)
case config.BitcoinElectrum:
initBitcoinElectrumFlags(cmd, cfg)
case config.Network:
initNetworkFlags(cmd, cfg)
case config.Storage:
initStorageFlags(cmd, cfg)
case config.ClientInfo:
initClientInfoFlags(cmd, cfg)
case config.Tbtc:
initTbtcFlags(cmd, cfg)
case config.Maintainer:
initMaintainerFlags(cmd, cfg)
case config.Developer:
initDeveloperFlags(cmd)
}
}
// Display flags in help in the same order they are defined. By default the
// flags are ordered alphabetically which reduces readability.
cmd.Flags().SortFlags = false
}
// Initialize flag for configuration file path.
func initGlobalConfigFlags(cmd *cobra.Command, configFilePath *string) {
cmd.PersistentFlags().StringVarP(
configFilePath,
"config",
"c",
"", // Don't define default value as it would fail configuration reading.
"Path to the configuration file. Supported formats: TOML, YAML, JSON.",
)
}
// Initializes boolean flags for network configuration. The flags can be used
// to run a client for a specific network, e.g. add `--testnet` to the client
// start command to run the client against test networks. Only one flag
// from this set is allowed.
func initGlobalNetworkFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Bool(
network.Mainnet.String(),
false,
"Mainnet network",
)
cmd.PersistentFlags().Bool(
network.Testnet.String(),
false,
"Testnet network",
)
cmd.PersistentFlags().Bool(
network.Developer.String(),
false,
"Developer network",
)
cmd.MarkFlagsMutuallyExclusive(
network.Mainnet.String(),
network.Testnet.String(),
network.Developer.String(),
)
}
// Initialize flags for Ethereum configuration.
func initEthereumFlags(cmd *cobra.Command, cfg *config.Config) {
cmd.Flags().StringVar(
&cfg.Ethereum.URL,
"ethereum.url",
"",
"WS connection URL for Ethereum client.",
)
cmd.Flags().StringVar(
&cfg.Ethereum.Account.KeyFile,
"ethereum.keyFile",
"",
"The local filesystem path to Keep operator account keyfile.",
)
cmd.Flags().DurationVar(
&cfg.Ethereum.MiningCheckInterval,
"ethereum.miningCheckInterval",
ethutil.DefaultMiningCheckInterval,
"The time interval in seconds in which transaction mining status is checked. If the transaction is not mined within this time, the gas price is increased and transaction is resubmitted.",
)
flag.WeiVarFlag(
cmd.Flags(),
&cfg.Ethereum.MaxGasFeeCap,
"ethereum.maxGasFeeCap",
ethutil.DefaultMaxGasFeeCap,
"The maximum gas fee the client is willing to pay for the transaction to be mined. If reached, no resubmission attempts are performed.",
)
cmd.Flags().IntVar(
&cfg.Ethereum.RequestsPerSecondLimit,
"ethereum.requestPerSecondLimit",
rate.DefaultRequestsPerSecondLimit,
"Request per second limit for all types of Ethereum client requests.",
)
cmd.Flags().IntVar(
&cfg.Ethereum.ConcurrencyLimit,
"ethereum.concurrencyLimit",
rate.DefaultConcurrencyLimit,
"The maximum number of concurrent requests which can be executed against Ethereum client.",
)
flag.WeiVarFlag(
cmd.Flags(),
&cfg.Ethereum.BalanceAlertThreshold,
"ethereum.balanceAlertThreshold",
*commonEthereum.WrapWei(big.NewInt(500000000000000000)), // 0.5 ether
"The minimum balance of operator account below which client starts reporting errors in logs.",
)
}
// Initialize flags for Bitcoin electrum configuration.
func initBitcoinElectrumFlags(cmd *cobra.Command, cfg *config.Config) {
cmd.Flags().StringVar(
&cfg.Bitcoin.Electrum.URL,
"bitcoin.electrum.url",
"",
"URL to the Electrum server in format: `scheme://hostname:port`.",
)
cmd.Flags().DurationVar(
&cfg.Bitcoin.Electrum.ConnectTimeout,
"bitcoin.electrum.connectTimeout",
electrum.DefaultConnectTimeout,
"Timeout for a single attempt of Electrum connection establishment.",
)
cmd.Flags().DurationVar(
&cfg.Bitcoin.Electrum.ConnectRetryTimeout,
"bitcoin.electrum.connectRetryTimeout",
electrum.DefaultConnectRetryTimeout,
"Timeout for Electrum connection establishment retries.",
)
cmd.Flags().DurationVar(
&cfg.Bitcoin.Electrum.RequestTimeout,
"bitcoin.electrum.requestTimeout",
electrum.DefaultRequestTimeout,
"Timeout for a single attempt of Electrum protocol request.",
)
cmd.Flags().DurationVar(
&cfg.Bitcoin.Electrum.RequestRetryTimeout,
"bitcoin.electrum.requestRetryTimeout",
electrum.DefaultRequestRetryTimeout,
"Timeout for Electrum protocol request retries.",
)
cmd.Flags().DurationVar(
&cfg.Bitcoin.Electrum.KeepAliveInterval,
"bitcoin.electrum.keepAliveInterval",
electrum.DefaultKeepAliveInterval,
"Interval for connection keep alive requests.",
)
}
// Initialize flags for Network configuration.
func initNetworkFlags(cmd *cobra.Command, cfg *config.Config) {
// TODO: Remove in v3.0.0 along with isBootstrap() in start.go and
// the LibP2P.Bootstrap config field.
cmd.Flags().BoolVar(
&cfg.LibP2P.Bootstrap,
"network.bootstrap",
false,
"[DEPRECATED: remove in v3.0] Run the client in bootstrap mode. This flag is deprecated and will be removed in v3.0.",
)
cmd.Flags().StringSliceVar(
&cfg.LibP2P.Peers,
"network.peers",
[]string{},
"Addresses of the network bootstrap nodes.",
)
cmd.Flags().IntVarP(
&cfg.LibP2P.Port,
"network.port",
"p",
libp2p.DefaultPort,
"Keep client listening port.",
)
cmd.Flags().StringSliceVar(
&cfg.LibP2P.AnnouncedAddresses,
"network.announcedAddresses",
[]string{},
"Overwrites the default Keep client address announced in the network. Should be used for NAT or when more advanced firewall rules are applied.",
)
cmd.Flags().IntVar(
&cfg.LibP2P.DisseminationTime,
"network.disseminationTime",
0,
"Specifies courtesy message dissemination time in seconds for topics the node is not subscribed to. Should be used only on selected bootstrap nodes. (0 = none)",
)
}
// Initialize flags for Storage configuration.
func initStorageFlags(cmd *cobra.Command, cfg *config.Config) {
cmd.Flags().StringVar(
&cfg.Storage.Dir,
"storage.dir",
"",
"Location to store the Keep client key shares and other sensitive data.",
)
}
// Initialize flags for ClientInfo configuration.
func initClientInfoFlags(cmd *cobra.Command, cfg *config.Config) {
cmd.Flags().IntVar(
&cfg.ClientInfo.Port,
"clientInfo.port",
9601,
"Client Info HTTP server listening port.",
)
cmd.Flags().DurationVar(
&cfg.ClientInfo.NetworkMetricsTick,
"clientInfo.networkMetricsTick",
clientinfo.DefaultNetworkMetricsTick,
"Client Info network metrics check tick in seconds.",
)
cmd.Flags().DurationVar(
&cfg.ClientInfo.EthereumMetricsTick,
"clientInfo.ethereumMetricsTick",
clientinfo.DefaultEthereumMetricsTick,
"Client info Ethereum metrics check tick in seconds.",
)
}
func initTbtcFlags(cmd *cobra.Command, cfg *config.Config) {
cmd.Flags().IntVar(
&cfg.Tbtc.PreParamsPoolSize,
"tbtc.preParamsPoolSize",
tbtc.DefaultPreParamsPoolSize,
"tECDSA pre-parameters pool size.",
)
cmd.Flags().DurationVar(
&cfg.Tbtc.PreParamsGenerationTimeout,
"tbtc.preParamsGenerationTimeout",
tbtc.DefaultPreParamsGenerationTimeout,
"tECDSA pre-parameters generation timeout.",
)
cmd.Flags().DurationVar(
&cfg.Tbtc.PreParamsGenerationDelay,
"tbtc.preParamsGenerationDelay",
tbtc.DefaultPreParamsGenerationDelay,
"tECDSA pre-parameters generation delay.",
)
cmd.Flags().IntVar(
&cfg.Tbtc.PreParamsGenerationConcurrency,
"tbtc.preParamsGenerationConcurrency",
tbtc.DefaultPreParamsGenerationConcurrency,
"tECDSA pre-parameters generation concurrency.",
)
cmd.Flags().IntVar(
&cfg.Tbtc.KeyGenerationConcurrency,
"tbtc.keyGenerationConcurrency",
tbtc.DefaultKeyGenerationConcurrency,
"tECDSA key generation concurrency.",
)
}
// Initialize flags for Maintainer configuration.
func initMaintainerFlags(command *cobra.Command, cfg *config.Config) {
command.Flags().BoolVar(
&cfg.Maintainer.BitcoinDifficulty.Enabled,
"bitcoinDifficulty",
false,
"Start Bitcoin difficulty maintainer.",
)
command.Flags().BoolVar(
&cfg.Maintainer.BitcoinDifficulty.DisableProxy,
"bitcoinDifficulty.disableProxy",
false,
"Disable Bitcoin difficulty proxy.",
)
command.Flags().BoolVar(
&cfg.Maintainer.Spv.Enabled,
"spv",
false,
"Start SPV maintainer.",
)
command.Flags().Uint64Var(
&cfg.Maintainer.Spv.HistoryDepth,
"spv.historyDepth",
spv.DefaultHistoryDepth,
"Number of blocks to look back for past wallet-related events.",
)
command.Flags().IntVar(
&cfg.Maintainer.Spv.TransactionLimit,
"spv.transactionLimit",
spv.DefaultTransactionLimit,
"The maximum number of confirmed transactions returned when getting "+
"transactions for a public key hash.",
)
command.Flags().DurationVar(
&cfg.Maintainer.Spv.RestartBackoffTime,
"spv.restartBackoffTime",
spv.DefaultRestartBackoffTime,
"The restart backoff which should be applied when the SPV maintainer "+
"is restarted.",
)
command.Flags().DurationVar(
&cfg.Maintainer.Spv.IdleBackoffTime,
"spv.idleBackoffTime",
spv.DefaultIdleBackOffTime,
"The wait time which should be applied when there are no more "+
"transaction proofs to submit.",
)
}
// Initialize flags for Developer configuration.
func initDeveloperFlags(command *cobra.Command) {
initContractAddressFlag := func(contractName string) {
command.Flags().String(
config.GetDeveloperContractAddressKey(contractName),
"",
fmt.Sprintf(
"Address of the %s smart contract",
contractName,
),
)
}
initContractAddressFlag(chainEthereum.BridgeContractName)
initContractAddressFlag(chainEthereum.MaintainerProxyContractName)
initContractAddressFlag(chainEthereum.LightRelayContractName)
initContractAddressFlag(chainEthereum.LightRelayMaintainerProxyContractName)
initContractAddressFlag(chainEthereum.RandomBeaconContractName)
initContractAddressFlag(chainEthereum.TokenStakingContractName)
initContractAddressFlag(chainEthereum.WalletRegistryContractName)
initContractAddressFlag(chainEthereum.WalletProposalValidatorContractName)
}