-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
391 lines (313 loc) · 7.88 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
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 config
import (
"github.com/theQRL/go-qrl/pkg/misc"
"os/user"
"path"
"sync"
)
type Config struct {
Dev *DevConfig
User *UserConfig
}
type MinerConfig struct {
MiningEnabled bool
MiningAddress string
MiningThreadCount uint
}
type NodeConfig struct {
EnablePeerDiscovery bool
PeerList []string
BindingIP string
LocalPort uint16
PublicPort uint16
PeerRateLimit uint64
BanMinutes uint8
MaxPeersLimit uint16
MaxPeersInPeerList uint64
MaxRedundantConnections int
}
type NotificationServerConfig struct {
EnableNotificationServer bool
BindingIP string
LocalPort uint16
}
type EphemeralConfig struct {
AcceptEphemeral bool
}
type NTPConfig struct {
Retries int
Servers []string
Refresh uint64
}
type TransactionPoolConfig struct {
TransactionPoolSize uint64
PendingTransactionPoolSize uint64
PendingTranactionPoolReserve uint64
StaleTransactionThreshold uint64
}
type API struct {
AdminAPI *APIConfig
PublicAPI *APIConfig
MiningAPI *APIConfig
}
type MongoProcessorConfig struct {
Enabled bool
DBName string
Host string
Port uint16
Username string
Password string
ItemsPerPage uint64
}
type UserConfig struct {
Node *NodeConfig
NotificationServerConfig *NotificationServerConfig
Miner *MinerConfig
Ephemeral *EphemeralConfig
NTP *NTPConfig
ChainStateTimeout uint16
ChainStateBroadcastPeriod uint16
TransactionPool *TransactionPoolConfig
QrlDir string
ChainFileDirectory string
API *API
MongoProcessorConfig *MongoProcessorConfig
}
type APIConfig struct {
Enabled bool
Host string
Port uint32
Threads uint32
MaxConcurrentRPC uint16
}
type DevConfig struct {
Genesis *GenesisConfig
Version string
BlocksPerEpoch uint64
BlockLeadTimestamp uint32
BlockMaxDrift uint16
MaxFutureBlockLength uint16
MaxMarginBlockNumber uint16
MinMarginBlockNumber uint16
ReorgLimit uint64
MessageQSize uint32
MessageReceiptTimeout uint32
MessageBufferSize uint32
MaxOTSTracking uint64
OtsBitFieldSize uint64
MiningNonceOffset int64
ExtraNonceOffset uint16
MiningBlobSize uint16
DefaultNonce uint8
DefaultAccountBalance uint64
MiningSetpointBlocktime uint64
DBName string
PeersFilename string
WalletDatFilename string
BannedPeersFilename string
Transaction *TransactionConfig
Token *TokenConfig
NMeasurement uint8
KP int64
NumberOfBlockAnalyze uint8
SizeMultiplier float64
BlockMinSizeLimit int
TxExtraOverhead int
ShorPerQuanta uint64
MaxReceivableBytes uint64
ReservedQuota uint64
MaxBytesOut uint64
SyncDelayMining uint8
BlockTimeSeriesSize uint32
RecordTransactionHashes bool // True will enable recording of transaction hashes into address state
}
type TransactionConfig struct {
MultiOutputLimit uint8
}
type TokenConfig struct {
MaxSymbolLength uint8
MaxNameLength uint8
}
type GenesisConfig struct {
GenesisPrevHeadehash []byte
MaxCoinSupply uint64
SuppliedCoins uint64
GenesisDifficulty uint64
CoinbaseAddress []byte
GenesisTimestamp uint32
}
var once sync.Once
var config *Config
func GetConfig() *Config {
once.Do(func() {
userConfig := GetUserConfig()
devConfig := GetDevConfig()
config = &Config{
User: userConfig,
Dev: devConfig,
}
})
return config
}
func GetUserConfig() (userConf *UserConfig) {
node := &NodeConfig{
EnablePeerDiscovery: true,
PeerList: []string{
"35.178.79.137:19000",
"35.177.182.85:19000",
"18.130.119.29:19000",
"18.130.25.64:19000",
},
BindingIP: "0.0.0.0",
LocalPort: 19000,
PublicPort: 19000,
PeerRateLimit: 500,
BanMinutes: 20,
MaxPeersLimit: 32,
MaxPeersInPeerList: 100,
MaxRedundantConnections: 5,
}
notificationServerConfig := &NotificationServerConfig{
EnableNotificationServer: true,
BindingIP: "0.0.0.0",
LocalPort: 18001,
}
miner := &MinerConfig{
MiningEnabled: false,
MiningAddress: "",
MiningThreadCount: 0,
}
ephemeral := &EphemeralConfig{
AcceptEphemeral: false,
}
ntp := &NTPConfig{
Retries: 6,
Servers: []string{"pool.ntp.org", "ntp.ubuntu.com"},
Refresh: 12 * 60 * 60,
}
transactionPool := &TransactionPoolConfig{
TransactionPoolSize: 25000,
PendingTransactionPoolSize: 75000,
PendingTranactionPoolReserve: 750,
StaleTransactionThreshold: 15,
}
adminAPI := &APIConfig{
Enabled: false,
Host: "127.0.0.1",
Port: 19008,
Threads: 1,
MaxConcurrentRPC: 100,
}
publicAPI := &APIConfig{
Enabled: true,
Host: "127.0.0.1",
Port: 19009,
Threads: 1,
MaxConcurrentRPC: 100,
}
miningAPI := &APIConfig{
Enabled: true,
Host: "127.0.0.1",
Port: 19007,
Threads: 1,
MaxConcurrentRPC: 100,
}
api := &API{
AdminAPI: adminAPI,
PublicAPI: publicAPI,
MiningAPI: miningAPI,
}
mongoProcessorConfig := &MongoProcessorConfig{
Enabled: false,
DBName: "qrl",
Host: "127.0.0.1",
Port: 3001,
Username: "",
Password: "",
ItemsPerPage: 1000,
}
userCurrentDir, _ := user.Current() // TODO: Handle error
userConf = &UserConfig{
Node: node,
NotificationServerConfig: notificationServerConfig,
Miner: miner,
Ephemeral: ephemeral,
NTP: ntp,
ChainStateTimeout: 180,
ChainStateBroadcastPeriod: 30,
TransactionPool: transactionPool,
QrlDir: path.Join(userCurrentDir.HomeDir, ".qrl"),
ChainFileDirectory: "data",
API: api,
MongoProcessorConfig: mongoProcessorConfig,
}
return userConf
}
func (u *UserConfig) DataDir() string {
return path.Join(u.QrlDir, u.ChainFileDirectory)
}
func (u *UserConfig) SetDataDir(dataDir string) {
u.QrlDir = dataDir
}
func (u *UserConfig) GetLogFileName() string {
return path.Join(u.QrlDir, "go-qrl.log")
}
func GetDevConfig() (dev *DevConfig) {
genesis := &GenesisConfig{
GenesisPrevHeadehash: []byte("Outside Context Problem"),
MaxCoinSupply: 105000000000000000,
SuppliedCoins: 65000000000000000,
GenesisDifficulty: 10000000,
CoinbaseAddress: misc.HStr2Bin("0000000000000000000000000000000000000000000000000000000000000000"),
GenesisTimestamp: 1530004179,
}
transaction := &TransactionConfig{
MultiOutputLimit: 100,
}
token := &TokenConfig{
MaxSymbolLength: 10,
MaxNameLength: 30,
}
dev = &DevConfig{
Genesis: genesis,
Version: "0.1.3 go",
BlocksPerEpoch: 100,
BlockLeadTimestamp: 30,
BlockMaxDrift: 15,
MaxFutureBlockLength: 256,
MaxMarginBlockNumber: 32,
MinMarginBlockNumber: 7,
ReorgLimit: 22000,
MessageQSize: 300,
MessageReceiptTimeout: 10,
MessageBufferSize: 64 * 1024 * 1024,
MaxOTSTracking: 8192,
OtsBitFieldSize: 8192 / 8,
MiningNonceOffset: 39,
ExtraNonceOffset: 43,
MiningBlobSize: 76,
DefaultNonce: 0,
DefaultAccountBalance: 0,
MiningSetpointBlocktime: 60,
DBName: "go-state",
PeersFilename: "known_peers.json",
WalletDatFilename: "wallet.json",
BannedPeersFilename: "banned_peers.qrl",
Transaction: transaction,
Token: token,
NMeasurement: 30,
KP: 5,
NumberOfBlockAnalyze: 10,
SizeMultiplier: 1.1,
BlockMinSizeLimit: 1024 * 1024,
TxExtraOverhead: 15,
ShorPerQuanta: 1000000000,
MaxReceivableBytes: 10 * 1024 * 1024,
ReservedQuota: 1024,
SyncDelayMining: 60,
BlockTimeSeriesSize: 1440,
RecordTransactionHashes: false,
}
dev.MaxBytesOut = dev.MaxReceivableBytes - dev.ReservedQuota
return dev
}