-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
700 lines (622 loc) · 30.2 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
package params
import (
"fmt"
"math/big"
"sync"
"github.com/ethereum/go-ethereum/common"
)
// Well-known chain IDs.
var (
MainnetChainID = big.NewInt(101)
BabylonChainID = big.NewInt(106)
TestnetChainID = big.NewInt(102)
PangaeaChainID = big.NewInt(103)
PartnerChainID = big.NewInt(104)
StressnetChainID = big.NewInt(105)
TestChainID = big.NewInt(199) // not a real network
AllProtocolChangesChainID = big.NewInt(200) // not a real network
// EthMainnetShard0ChainID to be reserved unique chain ID for eth compatible chains.
EthMainnetShard0ChainID = big.NewInt(1682841000)
EthBabylonShard0ChainID = big.NewInt(1682848000)
EthTestnetShard0ChainID = big.NewInt(1682842000)
EthPangaeaShard0ChainID = big.NewInt(1682843000)
EthPartnerShard0ChainID = big.NewInt(1682844000)
EthStressnetShard0ChainID = big.NewInt(1682845000)
EthTestShard0ChainID = big.NewInt(1682846000) // not a real network
EthAllProtocolChangesShard0ChainID = big.NewInt(1682847000) // not a real network
)
// EpochTBD is a large, “not anytime soon” epoch. It used as a placeholder
// until the exact epoch is decided.
var EpochTBD = big.NewInt(10000000)
var once sync.Once
var (
// MainnetChainConfig is the chain parameters to run a node on the main network.
MainnetChainConfig = &ChainConfig{
ChainID: MainnetChainID,
EthCompatibleChainID: EthMainnetShard0ChainID,
EthCompatibleShard0ChainID: EthMainnetShard0ChainID,
EthCompatibleEpoch: big.NewInt(0), // => Ignore
CrossTxEpoch: big.NewInt(0), // => Ignore
CrossLinkEpoch: big.NewInt(0), // => Ignore
AggregatedRewardEpoch: big.NewInt(3), // => Ignore
StakingEpoch: big.NewInt(1),
PreStakingEpoch: big.NewInt(0),
QuickUnlockEpoch: big.NewInt(453),
FiveSecondsEpoch: big.NewInt(1),
TwoSecondsEpoch: EpochTBD,
SixtyPercentEpoch: big.NewInt(0), // => Ignore.
RedelegationEpoch: big.NewInt(0), // => Ignore
NoEarlyUnlockEpoch: big.NewInt(0), // => Ignore.
VRFEpoch: big.NewInt(0), // => Ignore.
PrevVRFEpoch: big.NewInt(0), // => Ignore.
MinDelegation100Epoch: big.NewInt(0), // => Ignore.
MinCommissionRateEpoch: big.NewInt(0), // => Ignore.
MinCommissionPromoPeriod: big.NewInt(100),
EPoSBound35Epoch: big.NewInt(0), // => Ignore.
EIP155Epoch: big.NewInt(0), // => Ignore.
S3Epoch: big.NewInt(0), // => Ignore.
DataCopyFixEpoch: big.NewInt(0), // => Ignore.
IstanbulEpoch: big.NewInt(0), // => Ignore.
ReceiptLogEpoch: big.NewInt(0), // => Ignore.
SHA3Epoch: big.NewInt(0), // => Ignore.
HIP6And8Epoch: big.NewInt(0), // => Ignore.
StakingPrecompileEpoch: big.NewInt(0), // => Ignore.
}
// BabylonChainConfig is the chain parameters to run a node on the babylon network.
BabylonChainConfig = &ChainConfig{
ChainID: BabylonChainID,
EthCompatibleChainID: EthBabylonShard0ChainID,
EthCompatibleShard0ChainID: EthBabylonShard0ChainID,
EthCompatibleEpoch: big.NewInt(0), // => Ignore
CrossTxEpoch: big.NewInt(0), // => Ignore
CrossLinkEpoch: big.NewInt(0), // => Ignore
AggregatedRewardEpoch: big.NewInt(3), // => Ignore
StakingEpoch: big.NewInt(1),
PreStakingEpoch: big.NewInt(0),
QuickUnlockEpoch: EpochTBD,
FiveSecondsEpoch: EpochTBD,
TwoSecondsEpoch: EpochTBD,
SixtyPercentEpoch: big.NewInt(0), // => Ignore.
RedelegationEpoch: big.NewInt(0), // => Ignore
NoEarlyUnlockEpoch: big.NewInt(0), // => Ignore.
VRFEpoch: big.NewInt(0), // => Ignore.
PrevVRFEpoch: big.NewInt(0), // => Ignore.
MinDelegation100Epoch: big.NewInt(0), // => Ignore.
MinCommissionRateEpoch: big.NewInt(0), // => Ignore.
MinCommissionPromoPeriod: big.NewInt(100),
EPoSBound35Epoch: big.NewInt(0), // => Ignore.
EIP155Epoch: big.NewInt(0), // => Ignore.
S3Epoch: big.NewInt(0), // => Ignore.
DataCopyFixEpoch: big.NewInt(0), // => Ignore.
IstanbulEpoch: big.NewInt(0), // => Ignore.
ReceiptLogEpoch: big.NewInt(0), // => Ignore.
SHA3Epoch: big.NewInt(0), // => Ignore.
HIP6And8Epoch: big.NewInt(0), // => Ignore.
StakingPrecompileEpoch: big.NewInt(0), // => Ignore.
}
// TestnetChainConfig contains the chain parameters to run a node on the feechain test network.
TestnetChainConfig = &ChainConfig{
ChainID: TestnetChainID,
EthCompatibleChainID: EthTestnetShard0ChainID,
EthCompatibleShard0ChainID: EthTestnetShard0ChainID,
EthCompatibleEpoch: big.NewInt(0), // => Ignore
CrossTxEpoch: big.NewInt(0), // => Ignore
CrossLinkEpoch: big.NewInt(0), // => Ignore
AggregatedRewardEpoch: big.NewInt(3), // => Ignore
StakingEpoch: big.NewInt(1),
PreStakingEpoch: big.NewInt(0),
QuickUnlockEpoch: big.NewInt(2840),
FiveSecondsEpoch: big.NewInt(2725),
TwoSecondsEpoch: EpochTBD,
SixtyPercentEpoch: big.NewInt(0), // => Ignore.
RedelegationEpoch: big.NewInt(0), // => Ignore
NoEarlyUnlockEpoch: big.NewInt(0), // => Ignore.
VRFEpoch: big.NewInt(0), // => Ignore.
PrevVRFEpoch: big.NewInt(0), // => Ignore.
MinDelegation100Epoch: big.NewInt(0), // => Ignore.
MinCommissionRateEpoch: big.NewInt(0), // => Ignore.
MinCommissionPromoPeriod: big.NewInt(100),
EPoSBound35Epoch: big.NewInt(0), // => Ignore.
EIP155Epoch: big.NewInt(0), // => Ignore.
S3Epoch: big.NewInt(0), // => Ignore.
DataCopyFixEpoch: big.NewInt(0), // => Ignore.
IstanbulEpoch: big.NewInt(0), // => Ignore.
ReceiptLogEpoch: big.NewInt(0), // => Ignore.
SHA3Epoch: big.NewInt(0), // => Ignore.
HIP6And8Epoch: big.NewInt(0), // => Ignore.
StakingPrecompileEpoch: big.NewInt(0), // => Ignore.
}
// PangaeaChainConfig contains the chain parameters for the Pangaea network.
// All features except for CrossLink are enabled at launch.
PangaeaChainConfig = &ChainConfig{
ChainID: PangaeaChainID,
EthCompatibleChainID: EthPangaeaShard0ChainID,
EthCompatibleShard0ChainID: EthPangaeaShard0ChainID,
EthCompatibleEpoch: big.NewInt(0),
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: big.NewInt(2),
AggregatedRewardEpoch: big.NewInt(3),
StakingEpoch: big.NewInt(2),
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: EpochTBD,
FiveSecondsEpoch: big.NewInt(0),
TwoSecondsEpoch: big.NewInt(0),
SixtyPercentEpoch: big.NewInt(0),
RedelegationEpoch: big.NewInt(0),
NoEarlyUnlockEpoch: big.NewInt(0),
VRFEpoch: big.NewInt(0),
PrevVRFEpoch: big.NewInt(0),
MinDelegation100Epoch: big.NewInt(0),
MinCommissionRateEpoch: big.NewInt(0),
MinCommissionPromoPeriod: big.NewInt(10),
EPoSBound35Epoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
DataCopyFixEpoch: big.NewInt(0),
IstanbulEpoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
SHA3Epoch: big.NewInt(0),
HIP6And8Epoch: big.NewInt(0),
StakingPrecompileEpoch: big.NewInt(2), // same as staking
}
// PartnerChainConfig contains the chain parameters for the Partner network.
// All features except for CrossLink are enabled at launch.
PartnerChainConfig = &ChainConfig{
ChainID: PartnerChainID,
EthCompatibleChainID: EthPartnerShard0ChainID,
EthCompatibleShard0ChainID: EthPartnerShard0ChainID,
EthCompatibleEpoch: big.NewInt(0),
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: big.NewInt(2),
AggregatedRewardEpoch: big.NewInt(3),
StakingEpoch: big.NewInt(2),
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: EpochTBD,
FiveSecondsEpoch: big.NewInt(0),
TwoSecondsEpoch: big.NewInt(0),
SixtyPercentEpoch: big.NewInt(4),
RedelegationEpoch: big.NewInt(0),
NoEarlyUnlockEpoch: big.NewInt(0),
VRFEpoch: big.NewInt(0),
PrevVRFEpoch: big.NewInt(0),
MinDelegation100Epoch: big.NewInt(0),
MinCommissionRateEpoch: big.NewInt(0),
MinCommissionPromoPeriod: big.NewInt(10),
EPoSBound35Epoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
DataCopyFixEpoch: big.NewInt(0),
IstanbulEpoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
SHA3Epoch: big.NewInt(0),
HIP6And8Epoch: big.NewInt(0),
StakingPrecompileEpoch: big.NewInt(2),
}
// StressnetChainConfig contains the chain parameters for the Stress test network.
// All features except for CrossLink are enabled at launch.
StressnetChainConfig = &ChainConfig{
ChainID: StressnetChainID,
EthCompatibleChainID: EthStressnetShard0ChainID,
EthCompatibleShard0ChainID: EthStressnetShard0ChainID,
EthCompatibleEpoch: big.NewInt(0),
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: big.NewInt(2),
AggregatedRewardEpoch: big.NewInt(3),
StakingEpoch: big.NewInt(2),
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: EpochTBD,
FiveSecondsEpoch: big.NewInt(0),
TwoSecondsEpoch: big.NewInt(0),
SixtyPercentEpoch: big.NewInt(10),
RedelegationEpoch: big.NewInt(0),
NoEarlyUnlockEpoch: big.NewInt(0),
VRFEpoch: big.NewInt(0),
PrevVRFEpoch: big.NewInt(0),
MinDelegation100Epoch: big.NewInt(0),
MinCommissionRateEpoch: big.NewInt(0),
MinCommissionPromoPeriod: big.NewInt(10),
EPoSBound35Epoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
DataCopyFixEpoch: big.NewInt(0),
IstanbulEpoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
SHA3Epoch: big.NewInt(0),
HIP6And8Epoch: big.NewInt(0),
StakingPrecompileEpoch: big.NewInt(2),
}
// LocalnetChainConfig contains the chain parameters to run for local development.
LocalnetChainConfig = &ChainConfig{
ChainID: TestnetChainID,
EthCompatibleChainID: EthTestnetShard0ChainID,
EthCompatibleShard0ChainID: EthTestnetShard0ChainID,
EthCompatibleEpoch: big.NewInt(0),
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: big.NewInt(2),
AggregatedRewardEpoch: big.NewInt(3),
StakingEpoch: big.NewInt(2),
PreStakingEpoch: big.NewInt(0),
QuickUnlockEpoch: EpochTBD,
FiveSecondsEpoch: big.NewInt(0),
TwoSecondsEpoch: big.NewInt(3),
SixtyPercentEpoch: EpochTBD, // Never enable it for localnet as localnet has no external validator setup
RedelegationEpoch: big.NewInt(0),
NoEarlyUnlockEpoch: big.NewInt(0),
VRFEpoch: big.NewInt(0),
PrevVRFEpoch: big.NewInt(0),
MinDelegation100Epoch: big.NewInt(0),
MinCommissionRateEpoch: big.NewInt(0),
MinCommissionPromoPeriod: big.NewInt(10),
EPoSBound35Epoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
DataCopyFixEpoch: big.NewInt(0),
IstanbulEpoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
SHA3Epoch: big.NewInt(0),
HIP6And8Epoch: EpochTBD, // Never enable it for localnet as localnet has no external validator setup
StakingPrecompileEpoch: big.NewInt(2),
}
// AllProtocolChanges ...
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllProtocolChanges = &ChainConfig{
AllProtocolChangesChainID, // ChainID
EthAllProtocolChangesShard0ChainID, // EthCompatibleChainID
EthAllProtocolChangesShard0ChainID, // EthCompatibleShard0ChainID
big.NewInt(0), // EthCompatibleEpoch
big.NewInt(0), // CrossTxEpoch
big.NewInt(0), // CrossLinkEpoch
big.NewInt(0), // AggregatedRewardEpoch
big.NewInt(0), // StakingEpoch
big.NewInt(0), // PreStakingEpoch
big.NewInt(0), // QuickUnlockEpoch
big.NewInt(0), // FiveSecondsEpoch
big.NewInt(0), // TwoSecondsEpoch
big.NewInt(0), // SixtyPercentEpoch
big.NewInt(0), // RedelegationEpoch
big.NewInt(0), // NoEarlyUnlockEpoch
big.NewInt(0), // VRFEpoch
big.NewInt(0), // PrevVRFEpoch
big.NewInt(0), // MinDelegation100Epoch
big.NewInt(0), // MinCommissionRateEpoch
big.NewInt(10), // MinCommissionPromoPeriod
big.NewInt(0), // EPoSBound35Epoch
big.NewInt(0), // EIP155Epoch
big.NewInt(0), // S3Epoch
big.NewInt(0), // DataCopyFixEpoch
big.NewInt(0), // IstanbulEpoch
big.NewInt(0), // ReceiptLogEpoch
big.NewInt(0), // SHA3Epoch
big.NewInt(0), // HIP6And8Epoch
big.NewInt(0), // StakingPrecompileEpoch
}
// TestChainConfig ...
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
TestChainConfig = &ChainConfig{
TestChainID, // ChainID
EthTestShard0ChainID, // EthCompatibleChainID
EthTestShard0ChainID, // EthCompatibleShard0ChainID
big.NewInt(0), // EthCompatibleEpoch
big.NewInt(0), // CrossTxEpoch
big.NewInt(0), // CrossLinkEpoch
big.NewInt(0), // AggregatedRewardEpoch
big.NewInt(0), // StakingEpoch
big.NewInt(0), // PreStakingEpoch
big.NewInt(0), // QuickUnlockEpoch
big.NewInt(0), // FiveSecondsEpoch
big.NewInt(0), // TwoSecondsEpoch
big.NewInt(0), // SixtyPercentEpoch
big.NewInt(0), // RedelegationEpoch
big.NewInt(0), // NoEarlyUnlockEpoch
big.NewInt(0), // VRFEpoch
big.NewInt(0), // PrevVRFEpoch
big.NewInt(0), // MinDelegation100Epoch
big.NewInt(0), // MinCommissionRateEpoch
big.NewInt(10), // MinCommissionPromoPeriod
big.NewInt(0), // EPoSBound35Epoch
big.NewInt(0), // EIP155Epoch
big.NewInt(0), // S3Epoch
big.NewInt(0), // DataCopyFixEpoch
big.NewInt(0), // IstanbulEpoch
big.NewInt(0), // ReceiptLogEpoch
big.NewInt(0), // SHA3Epoch
big.NewInt(0), // HIP6And8Epoch
big.NewInt(0), // StakingPrecompileEpoch
}
// TestRules ...
TestRules = TestChainConfig.Rules(new(big.Int))
)
// TrustedCheckpoint represents a set of post-processed trie roots (CHT and
// BloomTrie) associated with the appropriate section index and head hash. It is
// used to start light syncing from this checkpoint and avoid downloading the
// entire header chain while still being able to securely access old headers/logs.
type TrustedCheckpoint struct {
Name string `json:"-"`
SectionIndex uint64 `json:"sectionIndex"`
SectionHead common.Hash `json:"sectionHead"`
CHTRoot common.Hash `json:"chtRoot"`
BloomRoot common.Hash `json:"bloomRoot"`
}
// ChainConfig is the core config which determines the blockchain settings.
//
// ChainConfig is stored in the database on a per block basis. This means
// that any network, identified by its genesis block, can have its own
// set of configuration options.
type ChainConfig struct {
// ChainId identifies the current chain and is used for replay protection
ChainID *big.Int `json:"chain-id"`
// EthCompatibleChainID identifies the chain id used for ethereum compatible transactions
EthCompatibleChainID *big.Int `json:"eth-compatible-chain-id"`
// EthCompatibleShard0ChainID identifies the shard 0 chain id used for ethereum compatible transactions
EthCompatibleShard0ChainID *big.Int `json:"eth-compatible-shard-0-chain-id"`
// EthCompatibleEpoch is the epoch where ethereum-compatible transaction starts being
// processed.
EthCompatibleEpoch *big.Int `json:"eth-compatible-epoch,omitempty"`
// CrossTxEpoch is the epoch where cross-shard transaction starts being
// processed.
CrossTxEpoch *big.Int `json:"cross-tx-epoch,omitempty"`
// CrossLinkEpoch is the epoch where beaconchain starts containing
// cross-shard links.
CrossLinkEpoch *big.Int `json:"cross-link-epoch,omitempty"`
// AggregatedRewardEpoch is the epoch when block rewards are distributed every 64 blocks
AggregatedRewardEpoch *big.Int `json:"aggregated-reward-epoch,omitempty"`
// StakingEpoch is the epoch when shard assign takes staking into account
StakingEpoch *big.Int `json:"staking-epoch,omitempty"`
// PreStakingEpoch is the epoch we allow staking transactions
PreStakingEpoch *big.Int `json:"prestaking-epoch,omitempty"`
// QuickUnlockEpoch is the epoch when undelegation will be unlocked at the current epoch
QuickUnlockEpoch *big.Int `json:"quick-unlock-epoch,omitempty"`
// FiveSecondsEpoch is the epoch when block time is reduced to 5 seconds
// and block rewards adjusted to 17.5 ONE/block
FiveSecondsEpoch *big.Int `json:"five-seconds-epoch,omitempty"`
// TwoSecondsEpoch is the epoch when block time is reduced to 2 seconds
// and block rewards adjusted to 7 ONE/block
TwoSecondsEpoch *big.Int `json:"two-seconds-epoch,omitempty"`
// SixtyPercentEpoch is the epoch when internal voting power reduced from 68% to 60%
SixtyPercentEpoch *big.Int `json:"sixty-percent-epoch,omitempty"`
// RedelegationEpoch is the epoch when redelegation is supported and undelegation locking time
// is restored to 7 epoch
RedelegationEpoch *big.Int `json:"redelegation-epoch,omitempty"`
// NoEarlyUnlockEpoch is the epoch when the early unlock of undelegated token from validators who were elected for
// more than 7 epochs is disabled
NoEarlyUnlockEpoch *big.Int `json:"no-early-unlock-epoch,omitempty"`
// VRFEpoch is the epoch when VRF randomness is enabled
VRFEpoch *big.Int `json:"vrf-epoch,omitempty"`
// PrevVRFEpoch is the epoch when previous VRF randomness can be fetched
PrevVRFEpoch *big.Int `json:"prev-vrf-epoch,omitempty"`
// MinDelegation100Epoch is the epoch when min delegation is reduced from 1000 ONE to 100 ONE
MinDelegation100Epoch *big.Int `json:"min-delegation-100-epoch,omitempty"`
// MinCommissionRateEpoch is the epoch when policy for minimum comission rate of 5% is started
MinCommissionRateEpoch *big.Int `json:"min-commission-rate-epoch,omitempty"`
// MinCommissionPromoPeriod is the number of epochs when newly elected validators can have 0% commission
MinCommissionPromoPeriod *big.Int `json:"commission-promo-period,omitempty"`
// EPoSBound35Epoch is the epoch when the EPoS bound parameter c is changed from 15% to 35%
EPoSBound35Epoch *big.Int `json:"epos-bound-35-epoch,omitempty"`
// EIP155 hard fork epoch (include EIP158 too)
EIP155Epoch *big.Int `json:"eip155-epoch,omitempty"`
// S3 epoch is the first epoch containing S3 asadal and all ethereum update up to Constantinople
S3Epoch *big.Int `json:"s3-epoch,omitempty"`
// DataCopyFix epoch is the first epoch containing fix for evm datacopy bug.
DataCopyFixEpoch *big.Int `json:"data-copy-fix-epoch,omitempty"`
// Istanbul epoch
IstanbulEpoch *big.Int `json:"istanbul-epoch,omitempty"`
// ReceiptLogEpoch is the first epoch support receiptlog
ReceiptLogEpoch *big.Int `json:"receipt-log-epoch,omitempty"`
// IsSHA3Epoch is the first epoch in supporting SHA3 FIPS-202 standard
SHA3Epoch *big.Int `json:"sha3-epoch,omitempty"`
// IsHIP6And8Epoch is the first epoch to support HIP-6 and HIP-8
HIP6And8Epoch *big.Int `json:"hip6_8-epoch,omitempty"`
// StakingPrecompileEpoch is the first epoch to support the staking precompiles
StakingPrecompileEpoch *big.Int `json:"staking-precompile-epoch,omitempty"`
}
// String implements the fmt.Stringer interface.
func (c *ChainConfig) String() string {
return fmt.Sprintf("{ChainID: %v EthCompatibleChainID: %v EIP155: %v CrossTx: %v Staking: %v CrossLink: %v ReceiptLog: %v SHA3Epoch: %v StakingPrecompileEpoch: %v}",
c.ChainID,
c.EthCompatibleChainID,
c.EIP155Epoch,
c.CrossTxEpoch,
c.StakingEpoch,
c.CrossLinkEpoch,
c.ReceiptLogEpoch,
c.SHA3Epoch,
c.StakingPrecompileEpoch,
)
}
// IsEIP155 returns whether epoch is either equal to the EIP155 fork epoch or greater.
func (c *ChainConfig) IsEIP155(epoch *big.Int) bool {
return isForked(c.EIP155Epoch, epoch)
}
// AcceptsCrossTx returns whether cross-shard transaction is accepted in the
// given epoch.
//
// Note that this is different from comparing epoch against CrossTxEpoch.
// Cross-shard transaction is accepted from CrossTxEpoch+1 and on, in order to
// allow for all shards to roll into CrossTxEpoch and become able to handle
// ingress receipts. In other words, cross-shard transaction fields are
// introduced and ingress receipts are processed at CrossTxEpoch, but the shard
// does not accept cross-shard transactions from clients until CrossTxEpoch+1.
func (c *ChainConfig) AcceptsCrossTx(epoch *big.Int) bool {
crossTxEpoch := new(big.Int).Add(c.CrossTxEpoch, common.Big1)
return isForked(crossTxEpoch, epoch)
}
// HasCrossTxFields returns whether blocks in the given epoch includes
// cross-shard transaction fields.
func (c *ChainConfig) HasCrossTxFields(epoch *big.Int) bool {
return isForked(c.CrossTxEpoch, epoch)
}
// IsEthCompatible determines whether it is ethereum compatible epoch
func (c *ChainConfig) IsEthCompatible(epoch *big.Int) bool {
return isForked(c.EthCompatibleEpoch, epoch)
}
// IsAggregatedRewardEpoch determines whether it is the epoch when rewards are distributed every 64 blocks
func (c *ChainConfig) IsAggregatedRewardEpoch(epoch *big.Int) bool {
return isForked(c.AggregatedRewardEpoch, epoch)
}
// IsStaking determines whether it is staking epoch
func (c *ChainConfig) IsStaking(epoch *big.Int) bool {
return isForked(c.StakingEpoch, epoch)
}
// IsFiveSeconds determines whether it is the epoch to change to 5 seconds block time
func (c *ChainConfig) IsFiveSeconds(epoch *big.Int) bool {
return isForked(c.FiveSecondsEpoch, epoch)
}
// IsTwoSeconds determines whether it is the epoch to change to 3 seconds block time
func (c *ChainConfig) IsTwoSeconds(epoch *big.Int) bool {
return isForked(c.TwoSecondsEpoch, epoch)
}
// IsSixtyPercent determines whether it is the epoch to reduce internal voting power to 60%
func (c *ChainConfig) IsSixtyPercent(epoch *big.Int) bool {
return isForked(c.SixtyPercentEpoch, epoch)
}
// IsRedelegation determines whether it is the epoch to support redelegation
func (c *ChainConfig) IsRedelegation(epoch *big.Int) bool {
return isForked(c.RedelegationEpoch, epoch)
}
// IsNoEarlyUnlock determines whether it is the epoch to stop early unlock
func (c *ChainConfig) IsNoEarlyUnlock(epoch *big.Int) bool {
return isForked(c.NoEarlyUnlockEpoch, epoch)
}
// IsVRF determines whether it is the epoch to enable vrf
func (c *ChainConfig) IsVRF(epoch *big.Int) bool {
return isForked(c.VRFEpoch, epoch)
}
// IsPrevVRF determines whether it is the epoch to enable previous vrf
func (c *ChainConfig) IsPrevVRF(epoch *big.Int) bool {
return isForked(c.PrevVRFEpoch, epoch)
}
// IsMinDelegation100 determines whether it is the epoch to reduce min delegation to 100
func (c *ChainConfig) IsMinDelegation100(epoch *big.Int) bool {
return isForked(c.MinDelegation100Epoch, epoch)
}
// IsMinCommissionRate determines whether it is the epoch to start the policy of 5% min commission
func (c *ChainConfig) IsMinCommissionRate(epoch *big.Int) bool {
return isForked(c.MinCommissionRateEpoch, epoch)
}
// IsEPoSBound35 determines whether it is the epoch to extend the EPoS bound to 35%
func (c *ChainConfig) IsEPoSBound35(epoch *big.Int) bool {
return isForked(c.EPoSBound35Epoch, epoch)
}
// IsPreStaking determines whether staking transactions are allowed
func (c *ChainConfig) IsPreStaking(epoch *big.Int) bool {
return isForked(c.PreStakingEpoch, epoch)
}
// IsQuickUnlock determines whether it's the epoch when the undelegation should be unlocked at end of current epoch
func (c *ChainConfig) IsQuickUnlock(epoch *big.Int) bool {
return isForked(c.QuickUnlockEpoch, epoch)
}
// IsCrossLink returns whether epoch is either equal to the CrossLink fork epoch or greater.
func (c *ChainConfig) IsCrossLink(epoch *big.Int) bool {
return isForked(c.CrossLinkEpoch, epoch)
}
// IsS3 returns whether epoch is either equal to the S3 fork epoch or greater.
func (c *ChainConfig) IsS3(epoch *big.Int) bool {
return isForked(c.S3Epoch, epoch)
}
// IsDataCopyFixEpoch returns whether epoch has the fix for DataCopy evm bug.
func (c *ChainConfig) IsDataCopyFixEpoch(epoch *big.Int) bool {
return isForked(c.DataCopyFixEpoch, epoch)
}
// IsIstanbul returns whether epoch is either equal to the Istanbul fork epoch or greater.
func (c *ChainConfig) IsIstanbul(epoch *big.Int) bool {
return isForked(c.IstanbulEpoch, epoch)
}
// IsReceiptLog returns whether epoch is either equal to the ReceiptLog fork epoch or greater.
func (c *ChainConfig) IsReceiptLog(epoch *big.Int) bool {
return isForked(c.ReceiptLogEpoch, epoch)
}
// IsSHA3 returns whether epoch is either equal to the IsSHA3 fork epoch or greater.
func (c *ChainConfig) IsSHA3(epoch *big.Int) bool {
return isForked(c.SHA3Epoch, epoch)
}
// IsHIP6And8Epoch determines whether it is the epoch to support
// HIP-6: reduce the internal voting power from 60% to 49%
// HIP-8: increase external nodes from 800 to 900
func (c *ChainConfig) IsHIP6And8Epoch(epoch *big.Int) bool {
return isForked(c.HIP6And8Epoch, epoch)
}
// IsStakingPrecompileEpoch determines whether staking
// precompiles are available in the EVM
func (c *ChainConfig) IsStakingPrecompile(epoch *big.Int) bool {
return isForked(c.StakingPrecompileEpoch, epoch)
}
// UpdateEthChainIDByShard update the ethChainID based on shard ID.
func UpdateEthChainIDByShard(shardID uint32) {
once.Do(func() {
MainnetChainConfig.EthCompatibleChainID = big.NewInt(0).Add(MainnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
BabylonChainConfig.EthCompatibleChainID = big.NewInt(0).Add(BabylonChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
TestnetChainConfig.EthCompatibleChainID = big.NewInt(0).Add(TestnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
PangaeaChainConfig.EthCompatibleChainID = big.NewInt(0).Add(PangaeaChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
PartnerChainConfig.EthCompatibleChainID = big.NewInt(0).Add(PartnerChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
StressnetChainConfig.EthCompatibleChainID = big.NewInt(0).Add(StressnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
LocalnetChainConfig.EthCompatibleChainID = big.NewInt(0).Add(LocalnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
AllProtocolChanges.EthCompatibleChainID = big.NewInt(0).Add(AllProtocolChanges.EthCompatibleChainID, big.NewInt(int64(shardID)))
TestChainConfig.EthCompatibleChainID = big.NewInt(0).Add(TestChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID)))
})
}
// IsEthCompatible returns whether the chainID is for ethereum compatible txn or not
func IsEthCompatible(chainID *big.Int) bool {
return chainID.Cmp(EthMainnetShard0ChainID) >= 0
}
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice).
//
// The returned GasTable's fields shouldn't, under any circumstances, be changed.
func (c *ChainConfig) GasTable(epoch *big.Int) GasTable {
if epoch == nil {
return GasTableR3
}
switch {
case c.IsS3(epoch):
return GasTableS3
default:
return GasTableR3
}
}
// isForked returns whether a fork scheduled at epoch s is active at the given head epoch.
func isForked(s, epoch *big.Int) bool {
if s == nil || epoch == nil {
return false
}
return s.Cmp(epoch) <= 0
}
// Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions
// that do not have or require information about the block.
//
// Rules is a one time interface meaning that it shouldn't be used in between transition
// phases.
type Rules struct {
ChainID *big.Int
EthChainID *big.Int
IsCrossLink, IsEIP155, IsS3, IsReceiptLog, IsIstanbul, IsVRF, IsPrevVRF, IsSHA3, IsStakingPrecompile bool
}
// Rules ensures c's ChainID is not nil.
func (c *ChainConfig) Rules(epoch *big.Int) Rules {
// if c.IsStakingPrecompile(epoch) {
// if !c.IsPreStaking(epoch) {
// panic("Cannot have staking precompile epoch if not prestaking epoch")
// }
// }
chainID := c.ChainID
if chainID == nil {
chainID = new(big.Int)
}
ethChainID := c.EthCompatibleChainID
if ethChainID == nil {
ethChainID = new(big.Int)
}
return Rules{
ChainID: new(big.Int).Set(chainID),
EthChainID: new(big.Int).Set(ethChainID),
IsCrossLink: c.IsCrossLink(epoch),
IsEIP155: c.IsEIP155(epoch),
IsS3: c.IsS3(epoch),
IsReceiptLog: c.IsReceiptLog(epoch),
IsIstanbul: c.IsIstanbul(epoch),
IsVRF: c.IsVRF(epoch),
IsPrevVRF: c.IsPrevVRF(epoch),
IsSHA3: c.IsSHA3(epoch),
IsStakingPrecompile: c.IsStakingPrecompile(epoch),
}
}