-
Notifications
You must be signed in to change notification settings - Fork 84
/
config.go
272 lines (227 loc) · 7.06 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
package posconfig
import (
"bytes"
"crypto/ecdsa"
"math/big"
"github.com/wanchain/go-wanchain/accounts/keystore"
"github.com/wanchain/go-wanchain/common"
"github.com/wanchain/go-wanchain/common/hexutil"
"github.com/wanchain/go-wanchain/crypto"
bn256 "github.com/wanchain/go-wanchain/crypto/bn256/cloudflare"
"github.com/wanchain/go-wanchain/params"
"github.com/wanchain/go-wanchain/node"
)
var (
// EpochBaseTime is the pos start time such as: 2018-12-12 00:00:00 == 1544544000
//EpochBaseTime = uint64(0)
FirstEpochId = uint64(0)
CurrentEpochId = uint64(0)
Pow2PosUpgradeBlockNumber = uint64(0)
// SelfTestMode config whether it is in a simlate tese mode
SelfTestMode = false
IsDev = false
MineEnabled = false
)
const (
RbLocalDB = "rblocaldb"
EpLocalDB = "eplocaldb"
StakerLocalDB = "stlocaldb"
PosLocalDB = "pos"
IncentiveLocalDB = "incentive"
ReorgLocalDB = "forkdb"
AvgRetDB = "avgretdb"
ApolloEpochID = 18104
AugustEpochID = 18116 //TODO change it as mainnet 8.8
TestnetAdditionalBlock = 6661460
)
var EpochLeadersHold [][]byte
var TestnetAdditionalValue = new(big.Int).Mul(big.NewInt(210000000), big.NewInt(1e18))
const (
// EpochLeaderCount is count of pk in epoch leader group which is select by stake
EpochLeaderCount = 50
// RandomProperCount is count of pk in random leader group which is select by stake
RandomProperCount = 25
PosUpgradeEpochID = 2 // must send tx 2 epoch before.
MaxEpHold = 30
MinEpHold = 0
Key3Suffix = "bn256KeySuffix"
StakeOutEpochKey = "StakeOutEpochKey"
)
const (
// SlotTime is the time span of a slot in second, So it's 1 hours for a epoch
SlotTime = 5
//Incentive should perform delay some epochs.
IncentiveDelayEpochs = 1
IncentiveStartStage = Stage2K
// TODO: recovery K and time
// K count of each epoch
KCount = 12
K = 1440
// SlotCount is slot count in an epoch
SlotCount = K * KCount
// Stage1K is divde a epoch into 10 pieces
Stage1K = uint64(K)
Stage2K = Stage1K * 2
Stage3K = Stage1K * 3
Stage4K = Stage1K * 4
Stage5K = Stage1K * 5
Stage6K = Stage1K * 6
Stage7K = Stage1K * 7
Stage8K = Stage1K * 8
Stage9K = Stage1K * 9
Stage10K = Stage1K * 10
Stage11K = Stage1K * 11
Stage12K = Stage1K * 12
Sma1Start = Stage2K
Sma1End = Stage4K
Sma2Start = Stage6K
Sma2End = Stage8K
Sma3Start = Stage10K
Sma3End = Stage12K
// parameters for security and chain quality
BlockSecurityParam = K
SlotSecurityParam = 2 * K
MinimumChainQuality = 0.5 //BlockSecurityParam / SlotSecurityParam
CriticalReorgThreshold = 3
CriticalChainQuality = 0.618
NonCriticalChainQuality = 0.8
MainnetMercuryEpochId = 18250 //2019.12.20
TestnetMercuryEpochId = 18246 //2019.12.16
MainnetVenusEpochId = 18557
TestnetVenusEpochId = 18369
MainnetMarsEpochId = MainnetVenusEpochId
TestnetMarsEpochId = 18506 //2020.09.01
// After Jupiter fork, wanchain support ethereum tx and wallet.
MainnetJupiterEpochId = 18732
TestnetJupiterEpochId = 18698
TARGETS_LOCKED_EPOCH = 90 //90 DAYS,90 EPOCH
RETURN_DIVIDE = 10000
// StoremanEpochid -> posconfig.Cfg().MarsEpochId
// StoremanEpochid = ApolloEpochID + TARGETS_LOCKED_EPOCH
SeekBackCount = uint64(10) // use 10 epoch before state
)
var TxDelay = K
var GenesisPK string
//var GenesisPK = "04dc40d03866f7335e40084e39c3446fe676b021d1fcead11f2e2715e10a399b498e8875d348ee40358545e262994318e4dcadbc865bcf9aac1fc330f22ae2c786"
//var GenesisPKInit = "04d7dffe5e06d2c7024d9bb93f675b8242e71901ee66a1bfe3fe5369324c0a75bf6f033dc4af65f5d0fe7072e98788fcfa670919b5bdc046f1ca91f28dff59db70"
//var GenesisPK = "046a5e1d2b8ca62accede9b8c7995dbd428ddbaf6a7f85673d426038b05bfdb428681046930a27b849a8f3541e71e8779948df95c78b2b303380769d0f4e8a753e"
var GenesisPKInit = ""
var PosOwnerAddr common.Address
var WhiteList [210]string
type Config struct {
PolymDegree uint
K uint
RBThres uint
EpochInterval uint64
PosStartTime int64
MinerKey *keystore.Key
Dbpath string
NodeCfg *node.Config
Dkg1End uint64
Dkg2Begin uint64
Dkg2End uint64
SignBegin uint64
SignEnd uint64
MercuryEpochId uint64
VenusEpochId uint64
MarsEpochId uint64
JupiterEpochId uint64
DefaultGasPrice *big.Int
SyncTargetBlokcNum uint64
}
var DefaultConfig = Config{
12,
K,
13,
0,
0,
nil,
"",
nil,
Stage2K - 1,
Stage4K,
Stage6K - 1,
Stage8K,
Stage10K - 1,
0,
0,
0,
0,
nil,
0,
}
func Cfg() *Config {
return &DefaultConfig
}
func (c *Config) GetMinerAddr() common.Address {
if c.MinerKey == nil {
return common.Address{}
}
return c.MinerKey.Address
}
func (c *Config) GetMinerBn256PK() *bn256.G1 {
D3 := GenerateD3byKey2(c.MinerKey.PrivateKey2)
return new(bn256.G1).ScalarBaseMult(D3)
}
func GenerateD3byKey2(PrivateKey *ecdsa.PrivateKey) *big.Int {
var one = new(big.Int).SetInt64(1)
params := crypto.S256().Params()
var ebuffer bytes.Buffer
ebuffer.Write(PrivateKey.D.Bytes())
ebuffer.Write(([]byte)(Key3Suffix))
ebyte := crypto.Keccak256(ebuffer.Bytes())
d3 := new(big.Int).SetBytes(ebyte)
n := new(big.Int).Sub(params.N, one)
d3.Mod(d3, n)
d3.Add(d3, one)
return d3
}
func (c *Config) GetMinerBn256SK() *big.Int {
return GenerateD3byKey2(c.MinerKey.PrivateKey2)
}
func Init(nodeCfg *node.Config, networkId uint64) {
if networkId == params.MAINNET_CHAIN_ID {
// this is mainnet. *****
WhiteList = WhiteListMainnet
PosOwnerAddr = PosOwnerAddrMainnet
DefaultConfig.MercuryEpochId = MainnetMercuryEpochId
DefaultConfig.VenusEpochId = MainnetVenusEpochId
DefaultConfig.MarsEpochId = MainnetMarsEpochId
DefaultConfig.JupiterEpochId = MainnetJupiterEpochId
} else if networkId == params.PLUTO_CHAIN_ID {
PosOwnerAddr = PosOwnerAddrInternal
if IsDev { // --plutodev
// TODO: for debug change WhiteListDev -> WhiteListMainnet
WhiteList = WhiteListDev // only one whiteAccount, used as single node.
} else {
WhiteList = WhiteListOrig
}
DefaultConfig.MercuryEpochId = TestnetMercuryEpochId
DefaultConfig.VenusEpochId = TestnetVenusEpochId
DefaultConfig.MarsEpochId = TestnetMarsEpochId
DefaultConfig.JupiterEpochId = TestnetJupiterEpochId
} else if networkId == params.INTERNAL_CHAIN_ID {
PosOwnerAddr = PosOwnerAddrInternal
// TODO: for debug set to WhiteListOrig -> WhiteListDev
WhiteList = WhiteListDev
DefaultConfig.MercuryEpochId = TestnetMercuryEpochId
DefaultConfig.VenusEpochId = TestnetVenusEpochId
DefaultConfig.MarsEpochId = TestnetMarsEpochId
DefaultConfig.JupiterEpochId = TestnetJupiterEpochId
} else { // testnet
PosOwnerAddr = PosOwnerAddrTestnet
WhiteList = WhiteListTestnet
DefaultConfig.MercuryEpochId = TestnetMercuryEpochId
DefaultConfig.VenusEpochId = TestnetVenusEpochId
DefaultConfig.MarsEpochId = TestnetMarsEpochId
DefaultConfig.JupiterEpochId = TestnetJupiterEpochId
}
EpochLeadersHold = make([][]byte, len(WhiteList))
for i := 0; i < len(WhiteList); i++ {
EpochLeadersHold[i] = hexutil.MustDecode(WhiteList[i])
}
DefaultConfig.NodeCfg = nodeCfg
}
func GetRandomGenesis() *big.Int {
return new(big.Int).SetBytes(crypto.Keccak256(big.NewInt(1).Bytes()))
}