-
Notifications
You must be signed in to change notification settings - Fork 127
/
config.go
85 lines (76 loc) · 2.02 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
package config
import (
"encoding/json"
"io/ioutil"
"time"
"github.com/MixinNetwork/mixin/crypto"
)
const (
Debug = true
BuildVersion = "v0.7.10-BUILD_VERSION"
MainnetId = "6430225c42bb015b4da03102fa962e4f4ef3969e03e04345db229f8377ef7997"
SnapshotRoundGap = uint64(3 * time.Second)
SnapshotReferenceThreshold = 10
SnapshotSyncRoundThreshold = 100
SnapshotRoundSize = 50
TransactionMaximumSize = 1024 * 1024
WithdrawalClaimFee = "0.0001"
KernelMintTimeBegin = 7
KernelMintTimeEnd = 9
KernelNodeAcceptTimeBegin = 13
KernelNodeAcceptTimeEnd = 19
KernelNodePledgePeriodMinimum = 12 * time.Hour
KernelNodeAcceptPeriodMinimum = 12 * time.Hour
KernelNodeAcceptPeriodMaximum = 7 * 24 * time.Hour
)
type custom struct {
Environment string `json:"environment"`
Signer crypto.Key `json:"signer"`
Listener string `json:"listener"`
MaxCacheSize int `json:"max-cache-size"`
RingCacheSize uint64 `json:"ring-cache-size"`
RingFinalSize uint64 `json:"ring-final-size"`
ElectionTicker int `json:"election-ticker"`
ConsensusOnly bool `json:"consensus-only"`
CacheTTL time.Duration `json:"cache-ttl"`
}
var Custom *custom
func Initialize(file string) error {
if Custom != nil {
return nil
}
f, err := ioutil.ReadFile(file)
if err != nil {
return err
}
var cm map[string]interface{}
err = json.Unmarshal(f, &cm)
if err != nil {
return err
}
var config custom
err = json.Unmarshal(f, &config)
if err != nil {
return err
}
if config.CacheTTL == 0 {
config.CacheTTL = 3600 * 2
}
if config.MaxCacheSize == 0 {
config.MaxCacheSize = 1024 * 16
}
if config.RingCacheSize == 0 {
config.RingCacheSize = 1024 * 1024
}
if config.RingFinalSize == 0 {
config.RingFinalSize = 1024 * 1024 * 16
}
if config.ElectionTicker == 0 {
config.ElectionTicker = 700
}
if _, found := cm["consensus-only"]; !found {
config.ConsensusOnly = true
}
Custom = &config
return nil
}