Line data Source code
1 : // Copyright (c) 2018 The Zcash developers
2 : // Copyright (c) 2020-2022 The PIVX Core developers
3 : // Distributed under the MIT software license, see the accompanying
4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 :
6 : #include "consensus/upgrades.h"
7 :
8 : /**
9 : * General information about each network upgrade.
10 : * Ordered by Consensus::UpgradeIndex.
11 : *
12 : * If the upgrade name has many words, use the '_' character to divide them.
13 : * We are using it in the -nuparams startup arg and input it with spaces is just ugly.
14 : */
15 : const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES] = {
16 : {
17 : /*.strName =*/ "Base",
18 : /*.strInfo =*/ "PIVX network",
19 : },
20 : {
21 : /*.strName =*/ "PoS",
22 : /*.strInfo =*/ "Proof of Stake Consensus activation",
23 : },
24 : {
25 : /*.strName =*/ "PoS_v2",
26 : /*.strInfo =*/ "New selection for stake modifier",
27 : },
28 : {
29 : /*.strName =*/ "Zerocoin",
30 : /*.strInfo =*/ "ZeroCoin protocol activation - start block v4",
31 : },
32 : {
33 : /*.strName =*/ "Zerocoin_v2",
34 : /*.strInfo =*/ "New zerocoin serials and zPOS start",
35 : },
36 : {
37 : /*.strName =*/ "BIP65",
38 : /*.strInfo =*/ "CLTV (BIP65) activation - start block v5",
39 : },
40 : {
41 : /*.strName =*/ "Zerocoin_Public",
42 : /*.strInfo =*/ "Activation of zerocoin public spends (spend v3)",
43 : },
44 : {
45 : /*.strName =*/ "PIVX_v3.4",
46 : /*.strInfo =*/ "New 256-bit stake modifier - start block v6",
47 : },
48 : {
49 : /*.strName =*/ "PIVX_v4.0",
50 : /*.strInfo =*/ "New message sigs - start block v7 - time protocol - zc spend v4",
51 : },
52 : {
53 : /*.strName =*/ "v5_shield",
54 : /*.strInfo =*/ "Sapling Shield - start block v8 - start transaction v3",
55 : },
56 : {
57 : /*.strName =*/ "PIVX_v5.2",
58 : /*.strInfo =*/ "New cold-staking rules",
59 : },
60 : {
61 : /*.strName =*/ "PIVX_v5.3",
62 : /*.strInfo =*/ "New staking rules",
63 : },
64 : {
65 : /*.strName =*/ "PIVX_v5.5",
66 : /*.strInfo =*/ "New rewards structure",
67 : },
68 : {
69 : /*.strName =*/ "PIVX_v5.6",
70 : /*.strInfo =*/ "Exchange address",
71 : },
72 : {
73 : /*.strName =*/ "v6_evo",
74 : /*.strInfo =*/ "Deterministic Masternodes",
75 : },
76 : {
77 : /*.strName =*/ "Test_dummy",
78 : /*.strInfo =*/ "Test dummy info",
79 : },
80 : };
81 :
82 3324761 : UpgradeState NetworkUpgradeState(
83 : int nHeight,
84 : const Consensus::Params& params,
85 : Consensus::UpgradeIndex idx)
86 : {
87 3324761 : assert(nHeight >= 0);
88 3324761 : assert(idx >= Consensus::BASE_NETWORK && idx < Consensus::MAX_NETWORK_UPGRADES);
89 3324761 : auto nActivationHeight = params.vUpgrades[idx].nActivationHeight;
90 :
91 3324761 : if (nActivationHeight == Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT) {
92 : return UPGRADE_DISABLED;
93 2875863 : } else if (nHeight >= nActivationHeight) {
94 : // From ZIP200:
95 : //
96 : // ACTIVATION_HEIGHT
97 : // The block height at which the network upgrade rules will come into effect.
98 : //
99 : // For removal of ambiguity, the block at height ACTIVATION_HEIGHT - 1 is
100 : // subject to the pre-upgrade consensus rules.
101 : return UPGRADE_ACTIVE;
102 : } else {
103 2109533 : return UPGRADE_PENDING;
104 : }
105 : }
106 :
107 32865 : bool NetworkUpgradeActive(
108 : int nHeight,
109 : const Consensus::Params& params,
110 : Consensus::UpgradeIndex idx)
111 : {
112 32865 : return NetworkUpgradeState(nHeight, params, idx) == UPGRADE_ACTIVE;
113 : }
114 :
115 0 : int CurrentEpoch(int nHeight, const Consensus::Params& params) {
116 0 : for (auto idxInt = Consensus::MAX_NETWORK_UPGRADES - 1; idxInt > Consensus::BASE_NETWORK; idxInt--) {
117 0 : if (NetworkUpgradeActive(nHeight, params, Consensus::UpgradeIndex(idxInt))) {
118 0 : return idxInt;
119 : }
120 : }
121 : return Consensus::BASE_NETWORK;
122 : }
123 :
124 15 : bool IsActivationHeight(
125 : int nHeight,
126 : const Consensus::Params& params,
127 : Consensus::UpgradeIndex idx)
128 : {
129 15 : assert(idx >= Consensus::BASE_NETWORK && idx < Consensus::MAX_NETWORK_UPGRADES);
130 :
131 : // Don't count BASE_NETWORK as an activation height
132 15 : if (idx == Consensus::BASE_NETWORK) {
133 : return false;
134 : }
135 :
136 15 : return nHeight >= 0 && nHeight == params.vUpgrades[idx].nActivationHeight;
137 : }
138 :
139 15 : bool IsActivationHeightForAnyUpgrade(
140 : int nHeight,
141 : const Consensus::Params& params)
142 : {
143 15 : if (nHeight < 0) {
144 : return false;
145 : }
146 :
147 190 : for (int idx = Consensus::BASE_NETWORK + 1; idx < (int) Consensus::MAX_NETWORK_UPGRADES; idx++) {
148 180 : if (nHeight == params.vUpgrades[idx].nActivationHeight)
149 : return true;
150 : }
151 :
152 : return false;
153 : }
154 :
155 15 : Optional<int> NextEpoch(int nHeight, const Consensus::Params& params) {
156 15 : if (nHeight < 0) {
157 3 : return nullopt;
158 : }
159 :
160 : // BASE_NETWORK is never pending
161 189 : for (auto idx = Consensus::BASE_NETWORK + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) {
162 180 : if (NetworkUpgradeState(nHeight, params, Consensus::UpgradeIndex(idx)) == UPGRADE_PENDING) {
163 3 : return idx;
164 : }
165 : }
166 :
167 9 : return nullopt;
168 : }
169 :
170 15 : Optional<int> NextActivationHeight(
171 : int nHeight,
172 : const Consensus::Params& params)
173 : {
174 15 : auto idx = NextEpoch(nHeight, params);
175 15 : if (idx) {
176 3 : return params.vUpgrades[idx.get()].nActivationHeight;
177 : }
178 12 : return nullopt;
179 : }
|