forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dashpay#5740 from knst/bp-versionbits
backport: bitcoin#19438 Introduce deploymentstatus (versionbits improvements)
- Loading branch information
1 parent
5e8140d
commit 18b5805
Showing
23 changed files
with
378 additions
and
183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2016-2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <deploymentinfo.h> | ||
|
||
#include <consensus/params.h> | ||
|
||
const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = { | ||
{ | ||
/*.name =*/ "testdummy", | ||
/*.gbt_force =*/ true, | ||
}, | ||
{ | ||
/*.name =*/"v20", | ||
/*.gbt_force =*/true, | ||
}, | ||
{ | ||
/*.name =*/"mn_rr", | ||
/*.gbt_force =*/true, | ||
}, | ||
}; | ||
|
||
std::string DeploymentName(Consensus::BuriedDeployment dep) | ||
{ | ||
assert(ValidDeployment(dep)); | ||
switch (dep) { | ||
case Consensus::DEPLOYMENT_HEIGHTINCB: | ||
return "bip34"; | ||
case Consensus::DEPLOYMENT_CLTV: | ||
return "bip65"; | ||
case Consensus::DEPLOYMENT_DERSIG: | ||
return "bip66"; | ||
case Consensus::DEPLOYMENT_BIP147: | ||
return "bip147"; | ||
case Consensus::DEPLOYMENT_CSV: | ||
return "csv"; | ||
case Consensus::DEPLOYMENT_DIP0001: | ||
return "dip0001"; | ||
case Consensus::DEPLOYMENT_DIP0003: | ||
return "dip0003"; | ||
case Consensus::DEPLOYMENT_DIP0008: | ||
return "dip0008"; | ||
case Consensus::DEPLOYMENT_DIP0020: | ||
return "dip0020"; | ||
case Consensus::DEPLOYMENT_DIP0024: | ||
return "dip0024"; | ||
case Consensus::DEPLOYMENT_BRR: | ||
return "realloc"; | ||
case Consensus::DEPLOYMENT_V19: | ||
return "v19"; | ||
} // no default case, so the compiler can warn about missing cases | ||
return ""; | ||
} |
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,29 @@ | ||
// Copyright (c) 2016-2018 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_DEPLOYMENTINFO_H | ||
#define BITCOIN_DEPLOYMENTINFO_H | ||
|
||
#include <consensus/params.h> | ||
|
||
#include <string> | ||
|
||
struct VBDeploymentInfo { | ||
/** Deployment name */ | ||
const char *name; | ||
/** Whether GBT clients can safely ignore this rule in simplified usage */ | ||
bool gbt_force; | ||
}; | ||
|
||
extern const VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]; | ||
|
||
std::string DeploymentName(Consensus::BuriedDeployment dep); | ||
|
||
inline std::string DeploymentName(Consensus::DeploymentPos pos) | ||
{ | ||
assert(Consensus::ValidDeployment(pos)); | ||
return VersionBitsDeploymentInfo[pos].name; | ||
} | ||
|
||
#endif // BITCOIN_DEPLOYMENTINFO_H |
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,17 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <deploymentstatus.h> | ||
|
||
#include <consensus/params.h> | ||
#include <versionbits.h> | ||
|
||
VersionBitsCache g_versionbitscache; | ||
|
||
/* Basic sanity checking for BuriedDeployment/DeploymentPos enums and | ||
* ValidDeployment check */ | ||
|
||
static_assert(ValidDeployment(Consensus::DEPLOYMENT_TESTDUMMY), "sanity check of DeploymentPos failed (TESTDUMMY not valid)"); | ||
static_assert(!ValidDeployment(Consensus::MAX_VERSION_BITS_DEPLOYMENTS), "sanity check of DeploymentPos failed (MAX value considered valid)"); | ||
static_assert(!ValidDeployment(static_cast<Consensus::BuriedDeployment>(Consensus::DEPLOYMENT_TESTDUMMY)), "sanity check of BuriedDeployment failed (overlaps with DeploymentPos)"); |
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,55 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_DEPLOYMENTSTATUS_H | ||
#define BITCOIN_DEPLOYMENTSTATUS_H | ||
|
||
#include <chain.h> | ||
#include <versionbits.h> | ||
|
||
#include <limits> | ||
|
||
/** Global cache for versionbits deployment status */ | ||
extern VersionBitsCache g_versionbitscache; | ||
|
||
/** Determine if a deployment is active for the next block */ | ||
inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::BuriedDeployment dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return (pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1) >= params.DeploymentHeight(dep); | ||
} | ||
|
||
inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return ThresholdState::ACTIVE == g_versionbitscache.State(pindexPrev, params, dep); | ||
} | ||
|
||
/** Determine if a deployment is active for this block */ | ||
inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::BuriedDeployment dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return index.nHeight >= params.DeploymentHeight(dep); | ||
} | ||
|
||
inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::DeploymentPos dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return DeploymentActiveAfter(index.pprev, params, dep); | ||
} | ||
|
||
/** Determine if a deployment is enabled (can ever be active) */ | ||
inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::BuriedDeployment dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return params.DeploymentHeight(dep) != std::numeric_limits<int>::max(); | ||
} | ||
|
||
inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::DeploymentPos dep) | ||
{ | ||
assert(Consensus::ValidDeployment(dep)); | ||
return params.vDeployments[dep].nTimeout != 0; | ||
} | ||
|
||
#endif // BITCOIN_DEPLOYMENTSTATUS_H |
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
Oops, something went wrong.