aboutsummaryrefslogtreecommitdiff
path: root/src/deploymentstatus.h
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2020-06-16 18:58:56 +1000
committerAnthony Towns <aj@erisian.com.au>2021-06-29 17:11:12 +1000
commit2b0d291da8f479739ff394dd92801da8c40b9f8e (patch)
tree50968fbedda38d56cfd6fa5b1a7c2a3ee037ddab /src/deploymentstatus.h
parenteccd736f3dc231ac0306ca763c3b72cf8247230a (diff)
downloadbitcoin-2b0d291da8f479739ff394dd92801da8c40b9f8e.tar.xz
[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.
Diffstat (limited to 'src/deploymentstatus.h')
-rw-r--r--src/deploymentstatus.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/deploymentstatus.h b/src/deploymentstatus.h
new file mode 100644
index 0000000000..32190e369d
--- /dev/null
+++ b/src/deploymentstatus.h
@@ -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