PIVX Core  5.6.99
P2P Digital Currency
upgrades.cpp
Go to the documentation of this file.
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 
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 
83  int nHeight,
84  const Consensus::Params& params,
86 {
87  assert(nHeight >= 0);
89  auto nActivationHeight = params.vUpgrades[idx].nActivationHeight;
90 
91  if (nActivationHeight == Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT) {
92  return UPGRADE_DISABLED;
93  } 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  return UPGRADE_PENDING;
104  }
105 }
106 
108  int nHeight,
109  const Consensus::Params& params,
111 {
112  return NetworkUpgradeState(nHeight, params, idx) == UPGRADE_ACTIVE;
113 }
114 
115 int CurrentEpoch(int nHeight, const Consensus::Params& params) {
116  for (auto idxInt = Consensus::MAX_NETWORK_UPGRADES - 1; idxInt > Consensus::BASE_NETWORK; idxInt--) {
117  if (NetworkUpgradeActive(nHeight, params, Consensus::UpgradeIndex(idxInt))) {
118  return idxInt;
119  }
120  }
122 }
123 
125  int nHeight,
126  const Consensus::Params& params,
128 {
130 
131  // Don't count BASE_NETWORK as an activation height
132  if (idx == Consensus::BASE_NETWORK) {
133  return false;
134  }
135 
136  return nHeight >= 0 && nHeight == params.vUpgrades[idx].nActivationHeight;
137 }
138 
140  int nHeight,
141  const Consensus::Params& params)
142 {
143  if (nHeight < 0) {
144  return false;
145  }
146 
147  for (int idx = Consensus::BASE_NETWORK + 1; idx < (int) Consensus::MAX_NETWORK_UPGRADES; idx++) {
148  if (nHeight == params.vUpgrades[idx].nActivationHeight)
149  return true;
150  }
151 
152  return false;
153 }
154 
155 Optional<int> NextEpoch(int nHeight, const Consensus::Params& params) {
156  if (nHeight < 0) {
157  return nullopt;
158  }
159 
160  // BASE_NETWORK is never pending
161  for (auto idx = Consensus::BASE_NETWORK + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) {
162  if (NetworkUpgradeState(nHeight, params, Consensus::UpgradeIndex(idx)) == UPGRADE_PENDING) {
163  return idx;
164  }
165  }
166 
167  return nullopt;
168 }
169 
171  int nHeight,
172  const Consensus::Params& params)
173 {
174  auto idx = NextEpoch(nHeight, params);
175  if (idx) {
176  return params.vUpgrades[idx.get()].nActivationHeight;
177  }
178  return nullopt;
179 }
UpgradeIndex
Index into Params.vUpgrades and NetworkUpgradeInfo.
Definition: params.h:26
@ BASE_NETWORK
Definition: params.h:27
@ MAX_NETWORK_UPGRADES
Definition: params.h:44
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
int nActivationHeight
Height of the first block for which the new consensus rules will be active.
Definition: params.h:56
static constexpr int NO_ACTIVATION_HEIGHT
Special value for nActivationHeight indicating that the upgrade will never activate.
Definition: params.h:74
Parameters that influence chain consensus.
Definition: params.h:171
NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]
Definition: params.h:213
bool NetworkUpgradeActive(int nHeight, const Consensus::Params &params, Consensus::UpgradeIndex idx)
Returns true if the given network upgrade is active as of the given block height.
Definition: upgrades.cpp:107
UpgradeState NetworkUpgradeState(int nHeight, const Consensus::Params &params, Consensus::UpgradeIndex idx)
Checks the state of a given network upgrade based on block height.
Definition: upgrades.cpp:82
int CurrentEpoch(int nHeight, const Consensus::Params &params)
Returns the index of the most recent upgrade as of the given block height (corresponding to the curre...
Definition: upgrades.cpp:115
bool IsActivationHeightForAnyUpgrade(int nHeight, const Consensus::Params &params)
Returns true if the given block height is the activation height for any upgrade.
Definition: upgrades.cpp:139
bool IsActivationHeight(int nHeight, const Consensus::Params &params, Consensus::UpgradeIndex idx)
Returns true if the given block height is the activation height for the given upgrade.
Definition: upgrades.cpp:124
Optional< int > NextEpoch(int nHeight, const Consensus::Params &params)
Returns the index of the next upgrade after the given block height, or nullopt if there are no more k...
Definition: upgrades.cpp:155
Optional< int > NextActivationHeight(int nHeight, const Consensus::Params &params)
Returns the activation height for the next upgrade after the given block height, or nullopt if there ...
Definition: upgrades.cpp:170
const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES]
General information about each network upgrade.
Definition: upgrades.cpp:15
UpgradeState
Definition: upgrades.h:12
@ UPGRADE_PENDING
Definition: upgrades.h:14
@ UPGRADE_DISABLED
Definition: upgrades.h:13
@ UPGRADE_ACTIVE
Definition: upgrades.h:15