Add feature flagging infrastructure to consensus parameters.
This commit is contained in:
parent
1cf4a10456
commit
2fc8963e63
|
@ -136,6 +136,9 @@ public:
|
|||
consensus.vUpgrades[Consensus::UPGRADE_NU5].nProtocolVersion = 170015;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_NU5].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_ZFUTURE].nProtocolVersion = 0x7FFFFFFF;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_ZFUTURE].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
|
||||
consensus.nFundingPeriodLength = consensus.nPostBlossomSubsidyHalvingInterval / 48;
|
||||
|
||||
|
@ -359,7 +362,8 @@ public:
|
|||
// "t3fmYHU2DnVaQgPhDs6TMFVmyC3qbWEWgXN", /* main-index: 52*/
|
||||
// "t3T4WmAp6nrLkJ24iPpGeCe1fSWTPv47ASG", /* main-index: 53*/
|
||||
// "t3fP6GrDM4QVwdjFhmCxGNbe7jXXXSDQ5dv", /* main-index: 54*/
|
||||
};
|
||||
};
|
||||
|
||||
assert(vFoundersRewardAddress.size() <= consensus.GetLastFoundersRewardBlockHeight(0));
|
||||
}
|
||||
};
|
||||
|
@ -423,6 +427,9 @@ public:
|
|||
consensus.vUpgrades[Consensus::UPGRADE_NU5].nProtocolVersion = 170014;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_NU5].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_ZFUTURE].nProtocolVersion = 0x7FFFFFFF;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_ZFUTURE].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
|
||||
consensus.nFundingPeriodLength = consensus.nPostBlossomSubsidyHalvingInterval / 48;
|
||||
|
||||
|
@ -667,6 +674,9 @@ public:
|
|||
consensus.vUpgrades[Consensus::UPGRADE_NU5].nProtocolVersion = 170014;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_NU5].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_ZFUTURE].nProtocolVersion = 0x7FFFFFFF;
|
||||
consensus.vUpgrades[Consensus::UPGRADE_ZFUTURE].nActivationHeight =
|
||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||
|
||||
consensus.nFundingPeriodLength = consensus.nPostBlossomSubsidyHalvingInterval / 48;
|
||||
// Defined funding streams can be enabled with node config flags.
|
||||
|
|
|
@ -8,12 +8,21 @@
|
|||
#include <key_io.h>
|
||||
#include <script/standard.h>
|
||||
#include "upgrades.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace Consensus {
|
||||
bool Params::NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const {
|
||||
return NetworkUpgradeState(nHeight, *this, idx) == UPGRADE_ACTIVE;
|
||||
}
|
||||
|
||||
bool Params::FeatureRequired(const Consensus::ConsensusFeature feature) const {
|
||||
return vRequiredFeatures.count(feature) > 0;
|
||||
}
|
||||
|
||||
bool Params::FeatureActive(const int nHeight, const Consensus::ConsensusFeature feature) const {
|
||||
return Features.FeatureActive(*this, nHeight, feature);
|
||||
}
|
||||
|
||||
bool Params::FutureTimestampSoftForkActive(int nHeight) const {
|
||||
return nHeight >= nFutureTimestampSoftForkHeight;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <optional>
|
||||
#include <variant>
|
||||
|
||||
|
||||
namespace Consensus {
|
||||
|
||||
// Early declaration to ensure it is accessible.
|
||||
|
@ -38,6 +37,7 @@ enum UpgradeIndex : uint32_t {
|
|||
UPGRADE_HEARTWOOD,
|
||||
UPGRADE_CANOPY,
|
||||
UPGRADE_NU5,
|
||||
UPGRADE_ZFUTURE,
|
||||
// NOTE: Also add new upgrades to NetworkUpgradeInfo in upgrades.cpp
|
||||
MAX_NETWORK_UPGRADES
|
||||
};
|
||||
|
@ -141,6 +141,63 @@ public:
|
|||
FundingStreamAddress RecipientAddress(const Params& params, int nHeight) const;
|
||||
};
|
||||
|
||||
enum ConsensusFeature : uint32_t {
|
||||
// Index value for the maximum consensus feature ID.
|
||||
MAX_FEATURES
|
||||
};
|
||||
const auto FIRST_CONSENSUS_FEATURE = MAX_FEATURES;
|
||||
|
||||
template <class Feature>
|
||||
struct FeatureInfo {
|
||||
std::vector<Feature> dependsOn;
|
||||
UpgradeIndex activation;
|
||||
};
|
||||
|
||||
template <class Feature, class Params>
|
||||
class FeatureSet {
|
||||
private:
|
||||
std::vector<FeatureInfo<Feature>> features;
|
||||
public:
|
||||
FeatureSet(std::vector<FeatureInfo<Feature>> features): features(features) {
|
||||
}
|
||||
|
||||
bool FeatureActive(
|
||||
const Params& params,
|
||||
const int nHeight,
|
||||
const Feature feature) const {
|
||||
assert(feature < features.size());
|
||||
|
||||
// The feature must be explicitly required by a CLI argument or by
|
||||
// the feature being universally available above a network upgrade
|
||||
// activation height.
|
||||
if (params.NetworkUpgradeActive(nHeight, features[feature].activation) ||
|
||||
params.FeatureRequired(feature)) {
|
||||
// Transitively check that if a feature is active, all of the other features
|
||||
// that it depends on are also active.
|
||||
auto requires = features[feature].dependsOn;
|
||||
assert(std::all_of(
|
||||
requires.begin(),
|
||||
requires.end(),
|
||||
[&](Feature feat) {
|
||||
return FeatureActive(params, nHeight, feat);
|
||||
}
|
||||
));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Features encodes a directed acyclic graph of feature dependencies
|
||||
* as an array indexed by feature ID. Values are FeatureInfo objects
|
||||
* containing the list of feature IDs upon which the index's feature ID
|
||||
* depends.
|
||||
*/
|
||||
const FeatureSet<ConsensusFeature, Params> Features({});
|
||||
|
||||
/** ZIP208 block target interval in seconds. */
|
||||
static const unsigned int PRE_BLOSSOM_POW_TARGET_SPACING = 150;
|
||||
static const unsigned int POST_BLOSSOM_POW_TARGET_SPACING = 75;
|
||||
|
@ -169,6 +226,10 @@ struct Params {
|
|||
|
||||
bool FutureTimestampSoftForkActive(int nHeight) const;
|
||||
|
||||
bool FeatureActive(int nHeight, Consensus::ConsensusFeature feature) const;
|
||||
|
||||
bool FeatureRequired(Consensus::ConsensusFeature feature) const;
|
||||
|
||||
uint256 hashGenesisBlock;
|
||||
|
||||
bool fCoinbaseMustBeShielded = false;
|
||||
|
@ -220,6 +281,13 @@ struct Params {
|
|||
int endHeight,
|
||||
const std::vector<std::string>& addresses);
|
||||
|
||||
/**
|
||||
* A set of features that have been explicitly force-enabled
|
||||
* via the CLI, overriding block-height based decisions for
|
||||
* this feature.
|
||||
*/
|
||||
std::set<ConsensusFeature> vRequiredFeatures;
|
||||
|
||||
/**
|
||||
* Default block height at which the future timestamp soft fork rule activates.
|
||||
*
|
||||
|
@ -279,7 +347,6 @@ struct Params {
|
|||
|
||||
uint256 nMinimumChainWork;
|
||||
};
|
||||
|
||||
} // namespace Consensus
|
||||
|
||||
#endif // BITCOIN_CONSENSUS_PARAMS_H
|
||||
|
|
|
@ -10,44 +10,49 @@
|
|||
*/
|
||||
const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES] = {
|
||||
{
|
||||
/*.nBranchId =*/ 0,
|
||||
/*.strName =*/ "Sprout",
|
||||
/*.strInfo =*/ "The Zcash network at launch",
|
||||
.nBranchId = 0,
|
||||
.strName = "Sprout",
|
||||
.strInfo = "The Zcash network at launch",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0x74736554,
|
||||
/*.strName =*/ "Test dummy",
|
||||
/*.strInfo =*/ "Test dummy info",
|
||||
.nBranchId = 0x74736554,
|
||||
.strName = "Test dummy",
|
||||
.strInfo = "Test dummy info",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0x5ba81b19,
|
||||
/*.strName =*/ "Overwinter",
|
||||
/*.strInfo =*/ "See https://z.cash/upgrade/overwinter/ for details.",
|
||||
.nBranchId = 0x5ba81b19,
|
||||
.strName = "Overwinter",
|
||||
.strInfo = "See https://z.cash/upgrade/overwinter/ for details.",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0x76b809bb,
|
||||
/*.strName =*/ "Sapling",
|
||||
/*.strInfo =*/ "See https://z.cash/upgrade/sapling/ for details.",
|
||||
.nBranchId = 0x76b809bb,
|
||||
.strName = "Sapling",
|
||||
.strInfo = "See https://z.cash/upgrade/sapling/ for details.",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0x2bb40e60,
|
||||
/*.strName =*/ "Blossom",
|
||||
/*.strInfo =*/ "See https://z.cash/upgrade/blossom/ for details.",
|
||||
.nBranchId = 0x2bb40e60,
|
||||
.strName = "Blossom",
|
||||
.strInfo = "See https://z.cash/upgrade/blossom/ for details.",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0xf5b9230b,
|
||||
/*.strName =*/ "Heartwood",
|
||||
/*.strInfo =*/ "See https://z.cash/upgrade/heartwood/ for details.",
|
||||
.nBranchId = 0xf5b9230b,
|
||||
.strName = "Heartwood",
|
||||
.strInfo = "See https://z.cash/upgrade/heartwood/ for details.",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0xe9ff75a6,
|
||||
/*.strName =*/ "Canopy",
|
||||
/*.strInfo =*/ "See https://z.cash/upgrade/canopy/ for details.",
|
||||
.nBranchId = 0xe9ff75a6,
|
||||
.strName = "Canopy",
|
||||
.strInfo = "See https://z.cash/upgrade/canopy/ for details.",
|
||||
},
|
||||
{
|
||||
/*.nBranchId =*/ 0xf919a198,
|
||||
/*.strName =*/ "NU5",
|
||||
/*.strInfo =*/ "See https://z.cash/upgrade/nu5/ for details.",
|
||||
.nBranchId = 0xf919a198,
|
||||
.strName = "NU5",
|
||||
.strInfo = "See https://z.cash/upgrade/nu5/ for details.",
|
||||
},
|
||||
{
|
||||
.nBranchId = 0xffffffff,
|
||||
.strName = "ZFUTURE",
|
||||
.strInfo = "Future network upgrade (integration testing only)",
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue