-
Notifications
You must be signed in to change notification settings - Fork 211
/
config.go
285 lines (247 loc) · 11.4 KB
/
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
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
// Package config contains go-spacemesh node configuration definitions
package config
import (
"fmt"
"math"
"os"
"path/filepath"
"time"
"github.com/spf13/viper"
"github.com/spacemeshos/go-spacemesh/activation"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
"github.com/spacemeshos/go-spacemesh/beacon"
"github.com/spacemeshos/go-spacemesh/blocks"
"github.com/spacemeshos/go-spacemesh/bootstrap"
"github.com/spacemeshos/go-spacemesh/checkpoint"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/fetch"
vm "github.com/spacemeshos/go-spacemesh/genvm"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/hare3/eligibility"
"github.com/spacemeshos/go-spacemesh/miner"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/syncer"
timeConfig "github.com/spacemeshos/go-spacemesh/timesync/config"
"github.com/spacemeshos/go-spacemesh/tortoise"
)
const (
defaultDataDirName = "spacemesh"
// NewBlockProtocol indicates the protocol name for new blocks arriving.
)
var (
defaultHomeDir string
defaultDataDir string
)
func init() {
defaultHomeDir, _ = os.UserHomeDir()
defaultDataDir = filepath.Join(defaultHomeDir, defaultDataDirName, "/")
}
// Config defines the top level configuration for a spacemesh node.
type Config struct {
BaseConfig `mapstructure:"main"`
Preset string `mapstructure:"preset"`
Genesis GenesisConfig `mapstructure:"genesis"`
PublicMetrics PublicMetrics `mapstructure:"public-metrics"`
Tortoise tortoise.Config `mapstructure:"tortoise"`
P2P p2p.Config `mapstructure:"p2p"`
API grpcserver.Config `mapstructure:"api"`
HARE3 hare3.Config `mapstructure:"hare3"`
HareEligibility eligibility.Config `mapstructure:"hare-eligibility"`
Certificate blocks.CertConfig `mapstructure:"certificate"`
Beacon beacon.Config `mapstructure:"beacon"`
TIME timeConfig.TimeConfig `mapstructure:"time"`
VM vm.Config `mapstructure:"vm"`
Certifier activation.CertifierConfig `mapstructure:"certifier"`
POST activation.PostConfig `mapstructure:"post"`
POSTService activation.PostSupervisorConfig
POET activation.PoetConfig `mapstructure:"poet"`
SMESHING SmeshingConfig `mapstructure:"smeshing"`
LOGGING LoggerConfig `mapstructure:"logging"`
FETCH fetch.Config `mapstructure:"fetch"`
Bootstrap bootstrap.Config `mapstructure:"bootstrap"`
Sync syncer.Config `mapstructure:"syncer"`
Recovery checkpoint.Config `mapstructure:"recovery"`
Cache datastore.Config `mapstructure:"cache"`
ActiveSet miner.ActiveSetPreparation `mapstructure:"active-set-preparation"`
}
// DataDir returns the absolute path to use for the node's data. This is the tilde-expanded path given in the config
// with a subfolder named after the network ID.
func (cfg *Config) DataDir() string {
return filepath.Clean(cfg.DataDirParent)
}
// BaseConfig defines the default configuration options for spacemesh app.
type BaseConfig struct {
DataDirParent string `mapstructure:"data-folder"`
FileLock string `mapstructure:"filelock"`
Standalone bool `mapstructure:"standalone"`
CollectMetrics bool `mapstructure:"metrics"`
MetricsPort int `mapstructure:"metrics-port"`
ProfilerName string `mapstructure:"profiler-name"`
ProfilerURL string `mapstructure:"profiler-url"`
LayerDuration time.Duration `mapstructure:"layer-duration"`
LayerAvgSize uint32 `mapstructure:"layer-average-size"`
LayersPerEpoch uint32 `mapstructure:"layers-per-epoch"`
PoETServers DeprecatedPoETServers `mapstructure:"poet-server"`
PoetServers []types.PoetServer `mapstructure:"poet-servers"`
PprofHTTPServer bool `mapstructure:"pprof-server"`
PprofHTTPServerListener string `mapstructure:"pprof-listener"`
TxsPerProposal int `mapstructure:"txs-per-proposal"`
BlockGasLimit uint64 `mapstructure:"block-gas-limit"`
// if the number of proposals with the same mesh state crosses this threshold (in percentage),
// then we optimistically filter out infeasible transactions before constructing the block.
OptFilterThreshold int `mapstructure:"optimistic-filtering-threshold"`
TickSize uint64 `mapstructure:"tick-size"`
DatabaseConnections int `mapstructure:"db-connections"`
DatabaseLatencyMetering bool `mapstructure:"db-latency-metering"`
DatabaseSizeMeteringInterval time.Duration `mapstructure:"db-size-metering-interval"`
DatabasePruneInterval time.Duration `mapstructure:"db-prune-interval"`
DatabaseVacuumState int `mapstructure:"db-vacuum-state"`
DatabaseSkipMigrations []int `mapstructure:"db-skip-migrations"`
DatabaseQueryCache bool `mapstructure:"db-query-cache"`
DatabaseQueryCacheSizes DatabaseQueryCacheSizes `mapstructure:"db-query-cache-sizes"`
PruneActivesetsFrom types.EpochID `mapstructure:"prune-activesets-from"`
// ScanMalfeasantATXs is a flag to enable scanning for malfeasant ATXs.
ScanMalfeasantATXs bool `mapstructure:"scan-malfeasant-atxs"`
NetworkHRP string `mapstructure:"network-hrp"`
// MinerGoodAtxsPercent is a threshold to decide if tortoise activeset should be
// picked from first block instead of synced data.
MinerGoodAtxsPercent int `mapstructure:"miner-good-atxs-percent"`
RegossipAtxInterval time.Duration `mapstructure:"regossip-atx-interval"`
// ATXGradeDelay is used to grade ATXs for selection in tortoise active set.
// See grading function in miner/proposals_builder.go
ATXGradeDelay time.Duration `mapstructure:"atx-grade-delay"`
// PostValidDelay is the time after which a PoST is considered valid
// counting from the time an ATX was received.
// Before that time, the PoST must be fully verified.
// After that time, we depend on PoST malfeasance proofs.
PostValidDelay time.Duration `mapstructure:"post-valid-delay"`
// NoMainOverride forces the "nomain" builds to run on the mainnet
NoMainOverride bool `mapstructure:"no-main-override"`
// ATX version switches
// Each entry states on which publish epoch given ATX version becomes valid.
// Note: There is always one valid version at any given time.
// ATX V1 starts with epoch 0 unless configured otherwise.
AtxVersions activation.AtxVersions `mapstructure:"atx-versions"`
}
type DatabaseQueryCacheSizes struct {
EpochATXs int `mapstructure:"epoch-atxs"`
ATXBlob int `mapstructure:"atx-blob"`
ActiveSetBlob int `mapstructure:"active-set-blob"`
}
type DeprecatedPoETServers struct{}
// DeprecatedMsg implements Deprecated interface.
func (DeprecatedPoETServers) DeprecatedMsg() string {
return `The 'poet-server' is deprecated. Please migrate to the 'poet-servers'. ` +
`Check 'Upgrade Information' in CHANGELOG.md for details.`
}
type PublicMetrics struct {
MetricsURL string `mapstructure:"metrics-url"`
MetricsPushPeriod time.Duration `mapstructure:"metrics-push-period"`
MetricsPushUser string `mapstructure:"metrics-push-user"`
MetricsPushPass string `mapstructure:"metrics-push-pass"`
MetricsPushHeader map[string]string `mapstructure:"metrics-push-header"`
}
// SmeshingConfig defines configuration for the node's smeshing (mining).
type SmeshingConfig struct {
Start bool `mapstructure:"smeshing-start"`
CoinbaseAccount string `mapstructure:"smeshing-coinbase"`
Opts activation.PostSetupOpts `mapstructure:"smeshing-opts"`
ProvingOpts activation.PostProvingOpts `mapstructure:"smeshing-proving-opts"`
VerifyingOpts activation.PostProofVerifyingOpts `mapstructure:"smeshing-verifying-opts"`
}
// DefaultConfig returns the default configuration for a spacemesh node.
func DefaultConfig() Config {
return Config{
BaseConfig: defaultBaseConfig(),
Genesis: DefaultGenesisConfig(),
Tortoise: tortoise.DefaultConfig(),
P2P: p2p.DefaultConfig(),
API: grpcserver.DefaultConfig(),
HARE3: hare3.DefaultConfig(),
HareEligibility: eligibility.DefaultConfig(),
Beacon: beacon.DefaultConfig(),
TIME: timeConfig.DefaultConfig(),
VM: vm.DefaultConfig(),
POST: activation.DefaultPostConfig(),
POSTService: activation.DefaultPostServiceConfig(),
POET: activation.DefaultPoetConfig(),
SMESHING: DefaultSmeshingConfig(),
FETCH: fetch.DefaultConfig(),
LOGGING: DefaultLoggingConfig(),
Bootstrap: bootstrap.DefaultConfig(),
Sync: syncer.DefaultConfig(),
Recovery: checkpoint.DefaultConfig(),
Cache: datastore.DefaultConfig(),
ActiveSet: miner.DefaultActiveSetPreparation(),
Certifier: activation.DefaultCertifierConfig(),
}
}
// DefaultTestConfig returns the default config for tests.
func DefaultTestConfig() Config {
conf := DefaultConfig()
conf.BaseConfig = defaultTestConfig()
conf.Genesis = DefaultTestGenesisConfig()
conf.P2P = p2p.DefaultConfig()
conf.API = grpcserver.DefaultTestConfig()
conf.POSTService = activation.DefaultTestPostServiceConfig()
conf.HARE3.PreroundDelay = 1 * time.Second
conf.HARE3.RoundDuration = 1 * time.Second
return conf
}
// DefaultBaseConfig returns a default configuration for spacemesh.
func defaultBaseConfig() BaseConfig {
return BaseConfig{
DataDirParent: defaultDataDir,
FileLock: filepath.Join(os.TempDir(), "spacemesh.lock"),
CollectMetrics: false,
MetricsPort: 1010,
ProfilerName: "go-spacemesh",
LayerDuration: 30 * time.Second,
LayersPerEpoch: 3,
TxsPerProposal: 100,
BlockGasLimit: math.MaxUint64,
OptFilterThreshold: 90,
TickSize: 100,
DatabaseConnections: 16,
DatabaseSizeMeteringInterval: 10 * time.Minute,
DatabasePruneInterval: 30 * time.Minute,
DatabaseQueryCacheSizes: DatabaseQueryCacheSizes{
EpochATXs: 20,
ATXBlob: 10000,
ActiveSetBlob: 200,
},
NetworkHRP: "sm",
ATXGradeDelay: 10 * time.Second,
PostValidDelay: 12 * time.Hour,
PprofHTTPServerListener: "localhost:6060",
}
}
// DefaultSmeshingConfig returns the node's default smeshing configuration.
func DefaultSmeshingConfig() SmeshingConfig {
return SmeshingConfig{
Start: false,
CoinbaseAccount: "",
Opts: activation.DefaultPostSetupOpts(),
ProvingOpts: activation.DefaultPostProvingOpts(),
VerifyingOpts: activation.DefaultPostVerifyingOpts(),
}
}
func defaultTestConfig() BaseConfig {
conf := defaultBaseConfig()
conf.MetricsPort += 10000
conf.NetworkHRP = "stest"
types.SetNetworkHRP(conf.NetworkHRP)
return conf
}
// LoadConfig load the config file.
func LoadConfig(config string, vip *viper.Viper) error {
if config == "" {
return nil
}
vip.SetConfigFile(config)
if err := vip.ReadInConfig(); err != nil {
return fmt.Errorf("can't load config at %s: %w", config, err)
}
return nil
}