Skip to content

Commit 0c87d1a

Browse files
dathonohmluke-jr
authored andcommitted
versionbits: add expiry support to versionbit deployments
Github-Pull: #238 Rebased-From: 7de9918
1 parent ef1faec commit 0c87d1a

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/consensus/params.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ struct BIP9Deployment {
5252
* boundary.
5353
*/
5454
int min_activation_height{0};
55+
/** For temporary softforks: number of blocks the deployment remains active after activation.
56+
* std::numeric_limits<int>::max() means permanent (never expires). */
57+
int active_duration{std::numeric_limits<int>::max()};
5558

5659
/** Constant for nTimeout very far in the future. */
5760
static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max();

src/deploymentstatus.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus
2020
inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos dep, VersionBitsCache& versionbitscache)
2121
{
2222
assert(Consensus::ValidDeployment(dep));
23-
return ThresholdState::ACTIVE == versionbitscache.State(pindexPrev, params, dep);
23+
if (ThresholdState::ACTIVE != versionbitscache.State(pindexPrev, params, dep)) return false;
24+
25+
const auto& deployment = params.vDeployments[dep];
26+
// Permanent deployment (never expires)
27+
if (deployment.active_duration == std::numeric_limits<int>::max()) return true;
28+
29+
const int activation_height = versionbitscache.StateSinceHeight(pindexPrev, params, dep);
30+
const int height = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
31+
return height < activation_height + deployment.active_duration;
2432
}
2533

2634
/** Determine if a deployment is active for this block */

src/rpc/blockchain.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,13 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo
17291729
UniValue rv(UniValue::VOBJ);
17301730
rv.pushKV("type", "bip9");
17311731
if (ThresholdState::ACTIVE == next_state) {
1732-
rv.pushKV("height", chainman.m_versionbitscache.StateSinceHeight(blockindex, chainman.GetConsensus(), id));
1732+
const int activation_height = chainman.m_versionbitscache.StateSinceHeight(blockindex, chainman.GetConsensus(), id);
1733+
rv.pushKV("height", activation_height);
1734+
// Add height_end for temporary softforks
1735+
const auto& deployment = chainman.GetConsensus().vDeployments[id];
1736+
if (deployment.active_duration < std::numeric_limits<int>::max()) {
1737+
rv.pushKV("height_end", activation_height + deployment.active_duration - 1);
1738+
}
17331739
}
17341740
rv.pushKV("active", ThresholdState::ACTIVE == next_state);
17351741
rv.pushKV("bip9", std::move(bip9));
@@ -1826,7 +1832,8 @@ RPCHelpMan getblockchaininfo()
18261832
namespace {
18271833
const std::vector<RPCResult> RPCHelpForDeployment{
18281834
{RPCResult::Type::STR, "type", "one of \"buried\", \"bip9\""},
1829-
{RPCResult::Type::NUM, "height", /*optional=*/true, "height of the first block which the rules are or will be enforced (only for \"buried\" type, or \"bip9\" type with \"active\" status)"},
1835+
{RPCResult::Type::NUM, "height", /*optional=*/true, "height of the first block which enforces the rules (only for \"buried\" type, or \"bip9\" type with \"active\" status)"},
1836+
{RPCResult::Type::NUM, "height_end", /*optional=*/true, "height of the last block which enforces the rules (only for \"bip9\" type with \"active\" status and temporary deployments)"},
18301837
{RPCResult::Type::BOOL, "active", "true if the rules are enforced for the mempool and the next block"},
18311838
{RPCResult::Type::OBJ, "bip9", /*optional=*/true, "status of bip9 softforks (only for \"bip9\" type)",
18321839
{

0 commit comments

Comments
 (0)