forked from PIVX-Project/PIVX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrades.cpp
179 lines (163 loc) · 5.47 KB
/
upgrades.cpp
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
// Copyright (c) 2018 The Zcash developers
// Copyright (c) 2020-2022 The PIVX Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "consensus/upgrades.h"
/**
* General information about each network upgrade.
* Ordered by Consensus::UpgradeIndex.
*
* If the upgrade name has many words, use the '_' character to divide them.
* We are using it in the -nuparams startup arg and input it with spaces is just ugly.
*/
const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES] = {
{
/*.strName =*/ "Base",
/*.strInfo =*/ "PIVX network",
},
{
/*.strName =*/ "PoS",
/*.strInfo =*/ "Proof of Stake Consensus activation",
},
{
/*.strName =*/ "PoS_v2",
/*.strInfo =*/ "New selection for stake modifier",
},
{
/*.strName =*/ "Zerocoin",
/*.strInfo =*/ "ZeroCoin protocol activation - start block v4",
},
{
/*.strName =*/ "Zerocoin_v2",
/*.strInfo =*/ "New zerocoin serials and zPOS start",
},
{
/*.strName =*/ "BIP65",
/*.strInfo =*/ "CLTV (BIP65) activation - start block v5",
},
{
/*.strName =*/ "Zerocoin_Public",
/*.strInfo =*/ "Activation of zerocoin public spends (spend v3)",
},
{
/*.strName =*/ "PIVX_v3.4",
/*.strInfo =*/ "New 256-bit stake modifier - start block v6",
},
{
/*.strName =*/ "PIVX_v4.0",
/*.strInfo =*/ "New message sigs - start block v7 - time protocol - zc spend v4",
},
{
/*.strName =*/ "v5_shield",
/*.strInfo =*/ "Sapling Shield - start block v8 - start transaction v3",
},
{
/*.strName =*/ "PIVX_v5.2",
/*.strInfo =*/ "New cold-staking rules",
},
{
/*.strName =*/ "PIVX_v5.3",
/*.strInfo =*/ "New staking rules",
},
{
/*.strName =*/ "PIVX_v5.5",
/*.strInfo =*/ "New rewards structure",
},
{
/*.strName =*/ "PIVX_v5.6",
/*.strInfo =*/ "Exchange address",
},
{
/*.strName =*/ "v6_evo",
/*.strInfo =*/ "Deterministic Masternodes",
},
{
/*.strName =*/ "Test_dummy",
/*.strInfo =*/ "Test dummy info",
},
};
UpgradeState NetworkUpgradeState(
int nHeight,
const Consensus::Params& params,
Consensus::UpgradeIndex idx)
{
assert(nHeight >= 0);
assert(idx >= Consensus::BASE_NETWORK && idx < Consensus::MAX_NETWORK_UPGRADES);
auto nActivationHeight = params.vUpgrades[idx].nActivationHeight;
if (nActivationHeight == Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT) {
return UPGRADE_DISABLED;
} else if (nHeight >= nActivationHeight) {
// From ZIP200:
//
// ACTIVATION_HEIGHT
// The block height at which the network upgrade rules will come into effect.
//
// For removal of ambiguity, the block at height ACTIVATION_HEIGHT - 1 is
// subject to the pre-upgrade consensus rules.
return UPGRADE_ACTIVE;
} else {
return UPGRADE_PENDING;
}
}
bool NetworkUpgradeActive(
int nHeight,
const Consensus::Params& params,
Consensus::UpgradeIndex idx)
{
return NetworkUpgradeState(nHeight, params, idx) == UPGRADE_ACTIVE;
}
int CurrentEpoch(int nHeight, const Consensus::Params& params) {
for (auto idxInt = Consensus::MAX_NETWORK_UPGRADES - 1; idxInt > Consensus::BASE_NETWORK; idxInt--) {
if (NetworkUpgradeActive(nHeight, params, Consensus::UpgradeIndex(idxInt))) {
return idxInt;
}
}
return Consensus::BASE_NETWORK;
}
bool IsActivationHeight(
int nHeight,
const Consensus::Params& params,
Consensus::UpgradeIndex idx)
{
assert(idx >= Consensus::BASE_NETWORK && idx < Consensus::MAX_NETWORK_UPGRADES);
// Don't count BASE_NETWORK as an activation height
if (idx == Consensus::BASE_NETWORK) {
return false;
}
return nHeight >= 0 && nHeight == params.vUpgrades[idx].nActivationHeight;
}
bool IsActivationHeightForAnyUpgrade(
int nHeight,
const Consensus::Params& params)
{
if (nHeight < 0) {
return false;
}
for (int idx = Consensus::BASE_NETWORK + 1; idx < (int) Consensus::MAX_NETWORK_UPGRADES; idx++) {
if (nHeight == params.vUpgrades[idx].nActivationHeight)
return true;
}
return false;
}
Optional<int> NextEpoch(int nHeight, const Consensus::Params& params) {
if (nHeight < 0) {
return nullopt;
}
// BASE_NETWORK is never pending
for (auto idx = Consensus::BASE_NETWORK + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) {
if (NetworkUpgradeState(nHeight, params, Consensus::UpgradeIndex(idx)) == UPGRADE_PENDING) {
return idx;
}
}
return nullopt;
}
Optional<int> NextActivationHeight(
int nHeight,
const Consensus::Params& params)
{
auto idx = NextEpoch(nHeight, params);
if (idx) {
return params.vUpgrades[idx.get()].nActivationHeight;
}
return nullopt;
}