-
Notifications
You must be signed in to change notification settings - Fork 211
/
root.go
257 lines (230 loc) · 16.4 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
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
package cmd
import (
"fmt"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
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.Hdist, "hdist",
config.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().IntVar(&config.P2P.TCPPort, "tcp-port",
config.P2P.TCPPort, "inet port for P2P listener")
cmd.PersistentFlags().StringVar(&config.P2P.TCPInterface, "tcp-interface",
config.P2P.TCPInterface, "inet interface for P2P listener, specify as IP address")
cmd.PersistentFlags().BoolVar(&config.P2P.AcquirePort, "acquire-port",
config.P2P.AcquirePort, "Should the node attempt to forward the port to this machine on a NAT?")
cmd.PersistentFlags().DurationVar(&config.P2P.DialTimeout, "dial-timeout",
config.P2P.DialTimeout, "Network dial timeout duration")
cmd.PersistentFlags().DurationVar(&config.P2P.ConnKeepAlive, "conn-keepalive",
config.P2P.ConnKeepAlive, "Network connection keep alive")
cmd.PersistentFlags().Uint32Var(&config.P2P.NetworkID, "network-id",
config.P2P.NetworkID, "NetworkID to run on (0 - mainnet, 1 - testnet)")
cmd.PersistentFlags().DurationVar(&config.P2P.ResponseTimeout, "response-timeout",
config.P2P.ResponseTimeout, "Timeout for waiting on response message")
cmd.PersistentFlags().DurationVar(&config.P2P.SessionTimeout, "session-timeout",
config.P2P.SessionTimeout, "Timeout for waiting on session message")
cmd.PersistentFlags().StringVar(&config.P2P.NodeID, "node-id",
config.P2P.NodeID, "Load node data by id (pub key) from local store")
cmd.PersistentFlags().IntVar(&config.P2P.BufferSize, "buffer-size",
config.P2P.BufferSize, "Size of the messages handler's buffer")
cmd.PersistentFlags().IntVar(&config.P2P.MaxPendingConnections, "max-pending-connections",
config.P2P.MaxPendingConnections, "The maximum number of pending connections")
cmd.PersistentFlags().IntVar(&config.P2P.OutboundPeersTarget, "outbound-target",
config.P2P.OutboundPeersTarget, "The outbound peer target we're trying to connect")
cmd.PersistentFlags().IntVar(&config.P2P.MaxInboundPeers, "max-inbound",
config.P2P.MaxInboundPeers, "The maximum number of inbound peers ")
cmd.PersistentFlags().BoolVar(&config.P2P.SwarmConfig.Gossip, "gossip",
config.P2P.SwarmConfig.Gossip, "should we start a gossiping node?")
cmd.PersistentFlags().BoolVar(&config.P2P.SwarmConfig.Bootstrap, "bootstrap",
config.P2P.SwarmConfig.Bootstrap, "Bootstrap the swarm")
cmd.PersistentFlags().IntVar(&config.P2P.SwarmConfig.RoutingTableBucketSize, "bucketsize",
config.P2P.SwarmConfig.RoutingTableBucketSize, "The rounding table bucket size")
cmd.PersistentFlags().IntVar(&config.P2P.SwarmConfig.RoutingTableAlpha, "alpha",
config.P2P.SwarmConfig.RoutingTableAlpha, "The rounding table Alpha")
cmd.PersistentFlags().IntVar(&config.P2P.SwarmConfig.RandomConnections, "randcon",
config.P2P.SwarmConfig.RoutingTableAlpha, "Number of random connections")
cmd.PersistentFlags().StringSliceVar(&config.P2P.SwarmConfig.BootstrapNodes, "bootnodes",
config.P2P.SwarmConfig.BootstrapNodes, "Number of random connections")
cmd.PersistentFlags().StringVar(&config.P2P.SwarmConfig.PeersFile, "peers-file",
config.P2P.SwarmConfig.PeersFile, "addrbook peers file. located under data-dir/<publickey>/<peer-file> not loaded or saved if empty string is given.")
/** ======================== 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().IntVar(&config.P2P.MsgSizeLimit, "msg-size-limit",
config.P2P.MsgSizeLimit, "The message size limit in bytes for incoming messages")
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().DurationVar(&config.TortoiseBeacon.WaitAfterEpochStart, "tortoise-beacon-wait-after-epoch-start",
config.TortoiseBeacon.WaitAfterEpochStart, "How many milliseconds to wait after a new epoch is started.")
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")
/**======================== 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)
}
}