forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#19438: Introduce deploymentstatus
e48826a tests: remove ComputeBlockVersion shortcut from versionbits tests (Anthony Towns) c5f3672 [refactor] Move ComputeBlockVersion into VersionBitsCache (Anthony Towns) 4a69b4d [move-only] Move ComputeBlockVersion from validation to versionbits (Anthony Towns) 0cfd6c6 [refactor] versionbits: make VersionBitsCache a full class (Anthony Towns) 8ee3e0b [refactor] rpc/blockchain.cpp: SoftForkPushBack (Anthony Towns) 92f48f3 deploymentinfo: Add DeploymentName() (Anthony Towns) ea68b3a [move-only] Rename versionbitsinfo to deploymentinfo (Anthony Towns) c64b2c6 scripted-diff: rename versionbitscache (Anthony Towns) de55304 [refactor] Add versionbits deployments to deploymentstatus.h (Anthony Towns) 2b0d291 [refactor] Add deploymentstatus.h (Anthony Towns) eccd736 versionbits: Use dedicated lock instead of cs_main (Anthony Towns) 36a4ba0 versionbits: correct doxygen comments (Anthony Towns) Pull request description: Introduces helper functions to make it easy to bury future deployments, along the lines of the suggestion from [11398](bitcoin#11398 (comment)) "I would prefer it if a buried deployment wouldn't require all code paths that check the BIP9 status to require changing". This provides three functions: `DeploymentEnabled()` which tests if a deployment can ever be active, `DeploymentActiveAt()` which checks if a deployment should be enforced in the given block, and `DeploymentActiveAfter()` which checks if a deployment should be enforced in the block following the given block, and overloads all three to work both with buried deployments and versionbits deployments. This adds a dedicated lock for the versionbits cache, which is acquired internally by the versionbits functions, rather than relying on `cs_main`. It also moves moves versionbitscache into deploymentstatus to avoid a circular dependency with validation. ACKs for top commit: jnewbery: ACK e48826a gruve-p: ACK bitcoin@e48826a MarcoFalke: re-ACK e48826a 🥈 Tree-SHA512: c846ba64436d36f8180046ad551d8b0d9e20509b9bc185aa2639055fc28803dd8ec2d6771ab337e80da0b40009ad959590d5772f84a0bf6199b65190d4155bed
- Loading branch information
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.