mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
[refactor] Add deploymentstatus.h
Provides DeploymentEnabled, DeploymentActiveAt, and DeploymentActiveAfter helpers for checking the status of buried deployments. Can be overloaded so the same syntax works for non-buried deployments, allowing future soft forks to be changed from signalled to buried deployments without having to touch the implementation code. Replaces IsWitnessEnabled and IsScriptWitnessEnabled.
This commit is contained in:
33
src/deploymentstatus.h
Normal file
33
src/deploymentstatus.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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 <limits>
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
/** 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();
|
||||
}
|
||||
|
||||
#endif // BITCOIN_DEPLOYMENTSTATUS_H
|
||||
Reference in New Issue
Block a user