Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #2898 - str4d:2286-nu-activation-mechanism, r=str4d
Network upgrade activation mechanism Implements ZIP 200. Integration with `CChainParams` inspired by bitcoin/bitcoin#7575. Includes block index rewinding logic cherry-picked from bitcoin/bitcoin#8149. Closes #2286. Part of #2905.
- Loading branch information
Showing
15 changed files
with
709 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (c) 2018 The Zcash 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. | ||
*/ | ||
const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES] = { | ||
{ | ||
/*.nBranchId =*/ 0, | ||
/*.strName =*/ "Sprout", | ||
/*.strInfo =*/ "The Zcash network at launch", | ||
}, | ||
{ | ||
/*.nBranchId =*/ 0x74736554, | ||
/*.strName =*/ "Test dummy", | ||
/*.strInfo =*/ "Test dummy info", | ||
}, | ||
{ | ||
/*.nBranchId =*/ 0x5ba81b19, | ||
/*.strName =*/ "Overwinter", | ||
/*.strInfo =*/ "TBD", | ||
} | ||
}; | ||
|
||
UpgradeState NetworkUpgradeState( | ||
int nHeight, | ||
const Consensus::Params& params, | ||
Consensus::UpgradeIndex idx) | ||
{ | ||
assert(nHeight >= 0); | ||
assert(idx >= Consensus::BASE_SPROUT && 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 ZIP 200: | ||
// | ||
// ACTIVATION_HEIGHT | ||
// The non-zero block height at which the network upgrade rules will come | ||
// into effect, and be enforced as part of the blockchain consensus. | ||
// | ||
// For removal of ambiguity, the block at height ACTIVATION_HEIGHT - 1 is | ||
// subject to the pre-upgrade consensus rules, and would be the last common | ||
// block in the event of a persistent pre-upgrade branch. | ||
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_SPROUT; idxInt--) { | ||
if (NetworkUpgradeActive(nHeight, params, Consensus::UpgradeIndex(idxInt))) { | ||
return idxInt; | ||
} | ||
} | ||
} | ||
|
||
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) { | ||
return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId; | ||
} | ||
|
||
bool IsActivationHeight( | ||
int nHeight, | ||
const Consensus::Params& params, | ||
Consensus::UpgradeIndex idx) | ||
{ | ||
assert(idx >= Consensus::BASE_SPROUT && idx < Consensus::MAX_NETWORK_UPGRADES); | ||
|
||
// Don't count Sprout as an activation height | ||
if (idx == Consensus::BASE_SPROUT) { | ||
return false; | ||
} | ||
|
||
return nHeight >= 0 && nHeight == params.vUpgrades[idx].nActivationHeight; | ||
} | ||
|
||
bool IsActivationHeightForAnyUpgrade( | ||
int nHeight, | ||
const Consensus::Params& params) | ||
{ | ||
if (nHeight < 0) { | ||
return false; | ||
} | ||
|
||
// Don't count Sprout as an activation height | ||
for (int idx = Consensus::BASE_SPROUT + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) { | ||
if (nHeight == params.vUpgrades[idx].nActivationHeight) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
boost::optional<int> NextActivationHeight( | ||
int nHeight, | ||
const Consensus::Params& params) | ||
{ | ||
if (nHeight < 0) { | ||
return boost::none; | ||
} | ||
|
||
// Don't count Sprout as an activation height | ||
for (auto idx = Consensus::BASE_SPROUT + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) { | ||
if (NetworkUpgradeState(nHeight, params, Consensus::UpgradeIndex(idx)) == UPGRADE_PENDING) { | ||
return params.vUpgrades[idx].nActivationHeight; | ||
} | ||
} | ||
|
||
return boost::none; | ||
} |
Oops, something went wrong.