Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardise deployment handling #16229

Closed
wants to merge 10 commits into from
3 changes: 3 additions & 0 deletions doc/release-notes-16229.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RPC changes
-----------
The RPC `getblockchaininfo` response changes the `softforks` key to provide an object whose keys are the softfork ids, rather than a list of softforks. This also now includes any BIP 9 softforks, and associated data. The `bip9_softforks` key is no longer included.
106 changes: 73 additions & 33 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,56 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
}

template <int b>
inline Consensus::Deployment DeploymentAlwaysActive()
{
// have to specify bit here, so that it AlwaysActive can be overridden usefully by -vbparams
static_assert(0 <= b && b <= 28, "Version bit must be between 0 and 28");

Consensus::Deployment res;
res.bit = b;
res.nStartTime = Consensus::Deployment::ALWAYS_ACTIVE;
res.nTimeout = Consensus::Deployment::NO_TIMEOUT;
return res;
}

template <int64_t height>
inline Consensus::Deployment DeploymentAtFixedHeight()
{
static_assert(0 < height, "Use DeploymentAlwaysActive() or set positive height for fixed activation");
static_assert(height < 500000000, "Fixed activation height should not look like a timestamp");

Consensus::Deployment res;
res.bit = 33;
res.nStartTime = height;
res.nTimeout = Consensus::Deployment::FIXED_ACTIVATION_HEIGHT;
return res;
}

template <int b, int64_t start, int64_t end>
inline Consensus::Deployment DeploymentByBIP9()
{
static_assert(0 <= b && b <= 28, "Version bit must be between 0 and 28");
static_assert(start != Consensus::Deployment::ALWAYS_ACTIVE, "Use DeploymentAlwaysActive()");
static_assert(end != Consensus::Deployment::DISABLED, "Use DeploymentDisabled()");
static_assert(end >= start, "End time must be greater than start time");

Consensus::Deployment res;
res.bit = b;
res.nStartTime = start;
res.nTimeout = end;
return res;
}

inline Consensus::Deployment DeploymentDisabled()
{
Consensus::Deployment res;
res.bit = 33;
res.nStartTime = 0;
res.nTimeout = Consensus::Deployment::DISABLED;
return res;
}

/**
* Main network
*/
Expand All @@ -67,28 +117,26 @@ class CMainParams : public CChainParams {
consensus.BIP16Exception = uint256S("0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22");
consensus.BIP34Height = 227931;
consensus.BIP34Hash = uint256S("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY] = DeploymentByBIP9<28, 1199145601, 1230767999>(); // January 1, 2008 - December 31, 2008

// Deployment of BIP66.
consensus.vDeployments[Consensus::DEPLOYMENT_STRICTDER] = DeploymentAtFixedHeight<363725>(); // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931

// Deployment of BIP65.
consensus.vDeployments[Consensus::DEPLOYMENT_CLTV] = DeploymentAtFixedHeight<388381>(); // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0

// Deployment of BIP68, BIP112, and BIP113.
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1462060800; // May 1st, 2016
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1493596800; // May 1st, 2017
consensus.vDeployments[Consensus::DEPLOYMENT_CSV] = DeploymentAtFixedHeight<419328>(); // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5

// Deployment of SegWit (BIP141, BIP143, and BIP147)
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT] = DeploymentAtFixedHeight<481824>(); // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000051dc8b82f450202ecb3d471");
Expand Down Expand Up @@ -184,28 +232,26 @@ class CTestNetParams : public CChainParams {
consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
consensus.BIP34Height = 21111;
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY] = DeploymentByBIP9<28, 1199145601, 1230767999>(); // January 1, 2008 - December 31, 2008

// Deployment of BIP66.
consensus.vDeployments[Consensus::DEPLOYMENT_STRICTDER] = DeploymentAtFixedHeight<330776>(); // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182

// Deployment of BIP65.
consensus.vDeployments[Consensus::DEPLOYMENT_CLTV] = DeploymentAtFixedHeight<581885>(); // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6

// Deployment of BIP68, BIP112, and BIP113.
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1456790400; // March 1st, 2016
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1493596800; // May 1st, 2017
consensus.vDeployments[Consensus::DEPLOYMENT_CSV] = DeploymentAtFixedHeight<770112>(); // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb

// Deployment of SegWit (BIP141, BIP143, and BIP147)
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT] = DeploymentAtFixedHeight<834624>(); // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000007dbe94253893cbd463");
Expand Down Expand Up @@ -279,24 +325,18 @@ class CRegTestParams : public CChainParams {
consensus.BIP16Exception = uint256();
consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests)
consensus.BIP34Hash = uint256();
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = true;
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY] = DeploymentByBIP9<28, 0, Consensus::Deployment::NO_TIMEOUT>();
consensus.vDeployments[Consensus::DEPLOYMENT_STRICTDER] = DeploymentAtFixedHeight<1251>(); // BIP66 activated on regtest (Used in functional tests)
consensus.vDeployments[Consensus::DEPLOYMENT_CLTV] = DeploymentAtFixedHeight<1351>(); // BIP65 activated on regtest (Used in functional tests)
consensus.vDeployments[Consensus::DEPLOYMENT_CSV] = DeploymentByBIP9<0, 0, Consensus::Deployment::NO_TIMEOUT>();
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT] = DeploymentAlwaysActive<1>();

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
Expand Down
18 changes: 12 additions & 6 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Consensus {
enum DeploymentPos
{
DEPLOYMENT_TESTDUMMY,
DEPLOYMENT_STRICTDER, // Deployment of BIP66
DEPLOYMENT_CLTV, // Deployment of BIP65
DEPLOYMENT_CSV, // Deployment of BIP68, BIP112, and BIP113.
DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
Expand All @@ -25,7 +27,7 @@ enum DeploymentPos
/**
* Struct for each individual consensus rule change using BIP9.
*/
struct BIP9Deployment {
struct Deployment {
/** Bit position to select the particular bit in nVersion. */
int bit;
/** Start MedianTime for version bits miner confirmation. Can be a date in the past */
Expand All @@ -36,11 +38,19 @@ struct BIP9Deployment {
/** Constant for nTimeout very far in the future. */
static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max();

/** Constant for nTimeout indicating nStartTime is a fixed block height where activation begins. */
static constexpr int64_t FIXED_ACTIVATION_HEIGHT = -1;

/** Special value for nStartTime indicating that the deployment is always active.
* This is useful for testing, as it means tests don't need to deal with the activation
* process (which takes at least 3 BIP9 intervals). Only tests that specifically test the
* behaviour during activation cannot use this. */
static constexpr int64_t ALWAYS_ACTIVE = -1;

/** Special value for nTimeout indicating that the deployment is never active.
* This is useful for integrating code changes or activation on regtest/testnet
* before the deployment parameters for mainnet are set. */
static constexpr int64_t DISABLED = 0;
};

/**
Expand All @@ -54,18 +64,14 @@ struct Params {
/** Block height and hash at which BIP34 becomes active */
int BIP34Height;
uint256 BIP34Hash;
/** Block height at which BIP65 becomes active */
int BIP65Height;
/** Block height at which BIP66 becomes active */
int BIP66Height;
/**
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
* Examples: 1916 for 95%, 1512 for testchains.
*/
uint32_t nRuleChangeActivationThreshold;
uint32_t nMinerConfirmationWindow;
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS];
Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS];
/** Proof of work parameters */
uint256 powLimit;
bool fPowAllowMinDifficultyBlocks;
Expand Down
Loading