-
Notifications
You must be signed in to change notification settings - Fork 211
/
root.go
232 lines (205 loc) · 14.5 KB
/
root.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/spacemeshos/go-spacemesh/common/types"
cfg "github.com/spacemeshos/go-spacemesh/config"
)
var config = cfg.DefaultConfig()
// AddCommands adds cobra commands to the app.
func AddCommands(cmd *cobra.Command) {
/** ======================== BaseConfig Flags ========================== **/
cmd.PersistentFlags().StringVarP(&config.BaseConfig.ConfigFile,
"config", "c", config.BaseConfig.ConfigFile, "Set Load configuration from file")
cmd.PersistentFlags().StringVarP(&config.BaseConfig.DataDirParent, "data-folder", "d",
config.BaseConfig.DataDirParent, "Specify data directory for spacemesh")
cmd.PersistentFlags().BoolVar(&config.TestMode, "test-mode",
config.TestMode, "Initialize testing features")
cmd.PersistentFlags().BoolVar(&config.CollectMetrics, "metrics",
config.CollectMetrics, "collect node metrics")
cmd.PersistentFlags().IntVar(&config.MetricsPort, "metrics-port",
config.MetricsPort, "metric server port")
cmd.PersistentFlags().StringVar(&config.MetricsPush, "metrics-push",
config.MetricsPush, "Push metrics to url")
cmd.PersistentFlags().IntVar(&config.MetricsPushPeriod, "metrics-push-period",
config.MetricsPushPeriod, "Push period")
cmd.PersistentFlags().StringVar(&config.OracleServer, "oracle_server",
config.OracleServer, "The oracle server url. (temporary) ")
cmd.PersistentFlags().IntVar(&config.OracleServerWorldID, "oracle_server_worldid",
config.OracleServerWorldID, "The worldid to use with the oracle server (temporary) ")
cmd.PersistentFlags().StringVar(&config.PoETServer, "poet-server",
config.PoETServer, "The poet server url. (temporary) ")
cmd.PersistentFlags().StringVar(&config.GenesisTime, "genesis-time",
config.GenesisTime, "Time of the genesis layer in 2019-13-02T17:02:00+00:00 format")
cmd.PersistentFlags().IntVar(&config.LayerDurationSec, "layer-duration-sec",
config.LayerDurationSec, "Duration between layers in seconds")
cmd.PersistentFlags().IntVar(&config.LayerAvgSize, "layer-average-size",
config.LayerAvgSize, "Layer Avg size")
cmd.PersistentFlags().Uint32Var(&config.Tortoise.Hdist, "tortoise-hdist",
config.Tortoise.Hdist, "hdist")
cmd.PersistentFlags().BoolVar(&config.PprofHTTPServer, "pprof-server",
config.PprofHTTPServer, "enable http pprof server")
cmd.PersistentFlags().StringVar(&config.GoldenATXID, "golden-atx",
config.GoldenATXID, "golden ATX hash")
cmd.PersistentFlags().IntVar(&config.BlockCacheSize, "block-cache-size",
config.BlockCacheSize, "size in layers of meshdb block cache")
cmd.PersistentFlags().StringVar(&config.PublishEventsURL, "events-url",
config.PublishEventsURL, "publish events to this url; if no url specified no events will be published")
cmd.PersistentFlags().StringVar(&config.ProfilerURL, "profiler-url",
config.ProfilerURL, "send profiler data to certain url, if no url no profiling will be sent, format: http://<IP>:<PORT>")
cmd.PersistentFlags().StringVar(&config.ProfilerName, "profiler-name",
config.ProfilerURL, "the name to use when sending profiles")
cmd.PersistentFlags().IntVar(&config.SyncRequestTimeout, "sync-request-timeout",
config.SyncRequestTimeout, "the timeout in ms for direct requests in the sync")
cmd.PersistentFlags().IntVar(&config.AtxsPerBlock, "atxs-per-block",
config.AtxsPerBlock, "the number of atxs to select per block on block creation")
cmd.PersistentFlags().IntVar(&config.TxsPerBlock, "txs-per-block",
config.TxsPerBlock, "the number of transactions to select per block on block creation")
/** ======================== P2P Flags ========================== **/
cmd.PersistentFlags().StringVar(&config.P2P.Listen, "listen",
config.P2P.Listen, "address for listening")
cmd.PersistentFlags().BoolVar(&config.P2P.Flood, "flood",
config.P2P.Flood, "flood created messages to all peers (true by default. disable to lower traffic requirements)")
cmd.PersistentFlags().BoolVar(&config.P2P.DisableNatPort, "disable-natport",
config.P2P.DisableNatPort, "disable nat port-mapping (if enabled upnp protocol is used to negotiate external port with router)")
cmd.PersistentFlags().Uint32Var(&config.P2P.NetworkID, "network-id",
config.P2P.NetworkID, "network-id to participate in")
cmd.PersistentFlags().IntVar(&config.P2P.LowPeers, "low-peers",
config.P2P.LowPeers, "low watermark for the number of connections")
cmd.PersistentFlags().IntVar(&config.P2P.HighPeers, "high-peers",
config.P2P.HighPeers,
"high watermark for the number of connections; once reached, connections are pruned until low watermark remains")
cmd.PersistentFlags().IntVar(&config.P2P.TargetOutbound, "target-outbound",
config.P2P.TargetOutbound, "target outbound connections")
cmd.PersistentFlags().StringSliceVar(&config.P2P.Bootnodes, "bootnodes",
config.P2P.Bootnodes, "entrypoints into the network")
/** ======================== TIME Flags ========================== **/
cmd.PersistentFlags().DurationVar(&config.TIME.MaxAllowedDrift, "max-allowed-time-drift",
config.TIME.MaxAllowedDrift, "When to close the app until user resolves time sync problems")
cmd.PersistentFlags().IntVar(&config.TIME.NtpQueries, "ntp-queries",
config.TIME.NtpQueries, "Number of ntp queries to do")
cmd.PersistentFlags().DurationVar(&config.TIME.DefaultTimeoutLatency, "default-timeout-latency",
config.TIME.DefaultTimeoutLatency, "Default timeout to ntp query")
cmd.PersistentFlags().DurationVar(&config.TIME.RefreshNtpInterval, "refresh-ntp-interval",
config.TIME.RefreshNtpInterval, "Refresh intervals to ntp")
cmd.PersistentFlags().StringSliceVar(&config.TIME.NTPServers,
"ntp-servers", config.TIME.NTPServers, "A list of NTP servers to query (e.g., 'time.google.com'). Overrides the list in config. Must contain more servers than the number of ntp-queries.")
cmd.PersistentFlags().BoolVar(&config.TIME.Peersync.Disable, "disable", config.TIME.Peersync.Disable,
"disable verification that local time is in sync with peers")
cmd.PersistentFlags().DurationVar(&config.TIME.Peersync.RoundRetryInterval, "peersync-round-retry-interval",
config.TIME.Peersync.RoundRetryInterval, "when to retry a sync round after a failure")
cmd.PersistentFlags().DurationVar(&config.TIME.Peersync.RoundInterval, "peersync-round-interval",
config.TIME.Peersync.RoundRetryInterval, "when to run a next sync round")
cmd.PersistentFlags().DurationVar(&config.TIME.Peersync.RoundTimeout, "peersync-round-timeout",
config.TIME.Peersync.RoundRetryInterval, "how long to wait for a round to complete")
cmd.PersistentFlags().DurationVar(&config.TIME.Peersync.MaxClockOffset, "peersync-max-clock-offset",
config.TIME.Peersync.MaxClockOffset, "max difference between local clock and peers clock")
cmd.PersistentFlags().IntVar(&config.TIME.Peersync.MaxOffsetErrors, "peersync-max-offset-errors",
config.TIME.Peersync.MaxOffsetErrors, "the node will exit when max number of consecutive offset errors will be reached")
cmd.PersistentFlags().IntVar(&config.TIME.Peersync.RequiredResponses, "peersync-required-responses",
config.TIME.Peersync.RequiredResponses, "min number of clock samples from other that need to be collected to verify time")
/** ======================== API Flags ========================== **/
// StartJSONServer determines if json api server should be started
cmd.PersistentFlags().BoolVar(&config.API.StartJSONServer, "json-server",
config.API.StartJSONServer, "Start the grpc-gateway (json http) server. "+
"The gateway server will be enabled for all corresponding, enabled GRPC services.",
)
// JSONServerPort determines the json api server local listening port
cmd.PersistentFlags().IntVar(&config.API.JSONServerPort, "json-port",
config.API.JSONServerPort, "JSON api server port")
// StartGrpcServices determines which (if any) GRPC API services should be started
cmd.PersistentFlags().StringSliceVar(&config.API.StartGrpcServices, "grpc",
config.API.StartGrpcServices, "Comma-separated list of individual grpc services to enable "+
"(gateway,globalstate,mesh,node,smesher,transaction)")
// GrpcServerPort determines the grpc server local listening port
cmd.PersistentFlags().IntVar(&config.API.GrpcServerPort, "grpc-port",
config.API.GrpcServerPort, "GRPC api server port")
// GrpcServerInterface determines the interface the GRPC server listens on
cmd.PersistentFlags().StringVar(&config.API.GrpcServerInterface, "grpc-interface",
config.API.GrpcServerInterface, "GRPC api server interface")
/**======================== Hare Flags ========================== **/
// N determines the size of the hare committee
cmd.PersistentFlags().IntVar(&config.HARE.N, "hare-committee-size",
config.HARE.N, "Size of Hare committee")
// F determines the max number of adversaries in the Hare committee
cmd.PersistentFlags().IntVar(&config.HARE.F, "hare-max-adversaries",
config.HARE.F, "Max number of adversaries in the Hare committee")
// RoundDuration determines the duration of a round in the Hare protocol
cmd.PersistentFlags().IntVar(&config.HARE.RoundDuration, "hare-round-duration-sec",
config.HARE.RoundDuration, "Duration of round in the Hare protocol")
cmd.PersistentFlags().IntVar(&config.HARE.WakeupDelta, "hare-wakeup-delta",
config.HARE.WakeupDelta, "Wakeup delta after tick for hare protocol")
cmd.PersistentFlags().IntVar(&config.HARE.ExpectedLeaders, "hare-exp-leaders",
config.HARE.ExpectedLeaders, "The expected number of leaders in the hare protocol")
cmd.PersistentFlags().IntVar(&config.HARE.LimitIterations, "hare-limit-iterations",
config.HARE.LimitIterations, "The limit of the number of iteration per consensus process")
cmd.PersistentFlags().IntVar(&config.HARE.LimitConcurrent, "hare-limit-concurrent",
config.HARE.LimitConcurrent, "The number of consensus processes running concurrently")
/**======================== Hare Eligibility Oracle Flags ========================== **/
cmd.PersistentFlags().Uint32Var(&config.HareEligibility.ConfidenceParam, "eligibility-confidence-param",
config.HareEligibility.ConfidenceParam, "The relative layer (with respect to the current layer) we are confident to have consensus about")
cmd.PersistentFlags().Uint32Var(&config.HareEligibility.EpochOffset, "eligibility-epoch-offset",
config.HareEligibility.EpochOffset, "The constant layer (within an epoch) for which we traverse its view for the purpose of counting consensus active set")
/**======================== Tortoise Beacon Flags ========================== **/
cmd.PersistentFlags().Uint64Var(&config.TortoiseBeacon.Kappa, "tortoise-beacon-kappa",
config.TortoiseBeacon.Kappa, "Security parameter (for calculating ATX threshold)")
cmd.PersistentFlags().Var((*types.RatVar)(config.TortoiseBeacon.Q), "tortoise-beacon-q",
"Ratio of dishonest spacetime (for calculating ATX threshold). It should be a string representing a rational number.")
cmd.PersistentFlags().Uint32Var((*uint32)(&config.TortoiseBeacon.RoundsNumber), "tortoise-beacon-rounds-number",
uint32(config.TortoiseBeacon.RoundsNumber), "Amount of rounds in every epoch")
cmd.PersistentFlags().DurationVar(&config.TortoiseBeacon.GracePeriodDuration, "tortoise-beacon-grace-period-duration",
config.TortoiseBeacon.GracePeriodDuration, "Grace period duration in milliseconds")
cmd.PersistentFlags().DurationVar(&config.TortoiseBeacon.ProposalDuration, "tortoise-beacon-proposal-duration",
config.TortoiseBeacon.ProposalDuration, "Proposal duration in milliseconds")
cmd.PersistentFlags().DurationVar(&config.TortoiseBeacon.FirstVotingRoundDuration, "tortoise-beacon-first-voting-round-duration",
config.TortoiseBeacon.FirstVotingRoundDuration, "First voting round duration in milliseconds")
cmd.PersistentFlags().DurationVar(&config.TortoiseBeacon.VotingRoundDuration, "tortoise-beacon-voting-round-duration",
config.TortoiseBeacon.VotingRoundDuration, "Voting round duration in milliseconds")
cmd.PersistentFlags().DurationVar(&config.TortoiseBeacon.WeakCoinRoundDuration, "tortoise-beacon-weak-coin-round-duration",
config.TortoiseBeacon.WeakCoinRoundDuration, "Weak coin round duration in milliseconds")
cmd.PersistentFlags().Var((*types.RatVar)(config.TortoiseBeacon.Theta), "tortoise-beacon-theta",
"Ratio of votes for reaching consensus")
cmd.PersistentFlags().Uint64Var(&config.TortoiseBeacon.VotesLimit, "tortoise-beacon-votes-limit",
config.TortoiseBeacon.VotesLimit, "Maximum allowed number of votes to be sent")
cmd.PersistentFlags().Uint32Var(&config.TortoiseBeacon.BeaconSyncNumBlocks, "tortoise-beacon-sync-num-blocks",
config.TortoiseBeacon.BeaconSyncNumBlocks, "Numbers of blocks to wait before determining beacon values from them.")
/**======================== Post Flags ========================== **/
// TODO(moshababo): add usage desc
cmd.PersistentFlags().UintVar(&config.POST.BitsPerLabel, "post-bits-per-label",
config.POST.BitsPerLabel, "")
cmd.PersistentFlags().UintVar(&config.POST.LabelsPerUnit, "post-labels-per-unit",
config.POST.LabelsPerUnit, "")
cmd.PersistentFlags().UintVar(&config.POST.MinNumUnits, "post-min-numunits",
config.POST.MinNumUnits, "")
cmd.PersistentFlags().UintVar(&config.POST.MaxNumUnits, "post-max-numunits",
config.POST.MaxNumUnits, "")
cmd.PersistentFlags().UintVar(&config.POST.K1, "post-k1",
config.POST.K1, "")
cmd.PersistentFlags().UintVar(&config.POST.K2, "post-k2",
config.POST.K2, "")
/**======================== Smeshing Flags ========================== **/
// TODO(moshababo): add usage desc
cmd.PersistentFlags().BoolVar(&config.SMESHING.Start, "smeshing-start",
config.SMESHING.Start, "")
cmd.PersistentFlags().StringVar(&config.SMESHING.CoinbaseAccount, "smeshing-coinbase",
config.SMESHING.CoinbaseAccount, "coinbase account to accumulate rewards")
cmd.PersistentFlags().StringVar(&config.SMESHING.Opts.DataDir, "smeshing-opts-datadir",
config.SMESHING.Opts.DataDir, "")
cmd.PersistentFlags().UintVar(&config.SMESHING.Opts.NumUnits, "smeshing-opts-numunits",
config.SMESHING.Opts.NumUnits, "")
cmd.PersistentFlags().UintVar(&config.SMESHING.Opts.NumFiles, "smeshing-opts-numfiles",
config.SMESHING.Opts.NumFiles, "")
cmd.PersistentFlags().IntVar(&config.SMESHING.Opts.ComputeProviderID, "smeshing-opts-provider",
config.SMESHING.Opts.ComputeProviderID, "")
cmd.PersistentFlags().BoolVar(&config.SMESHING.Opts.Throttle, "smeshing-opts-throttle",
config.SMESHING.Opts.Throttle, "")
/**========================Consensus Flags ========================== **/
cmd.PersistentFlags().Uint32Var(&config.LayersPerEpoch, "layers-per-epoch",
config.LayersPerEpoch, "number of layers in epoch")
// Bind Flags to config
err := viper.BindPFlags(cmd.PersistentFlags())
if err != nil {
fmt.Println("an error has occurred while binding flags:", err)
}
}