diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,6 +181,7 @@ chain.cpp checkpoints.cpp config.cpp + consensus/activation.cpp globals.cpp httprpc.cpp httpserver.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -111,6 +111,7 @@ compat/sanity.h \ compressor.h \ config.h \ + consensus/activation.h \ consensus/consensus.h \ core_io.h \ core_memusage.h \ @@ -211,6 +212,7 @@ chain.cpp \ checkpoints.cpp \ config.cpp \ + consensus/activation.cpp \ globals.cpp \ httprpc.cpp \ httpserver.cpp \ diff --git a/src/consensus/activation.h b/src/consensus/activation.h new file mode 100644 --- /dev/null +++ b/src/consensus/activation.h @@ -0,0 +1,28 @@ +// Copyright (c) 2018 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_CONSENSUS_ACTIVATION_H +#define BITCOIN_CONSENSUS_ACTIVATION_H + +#include + +class CBlockIndex; +class Config; + +/** Check if UAHF has activated. */ +bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev); + +/** Check if DAA HF has activated. */ +bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev); + +/** Check if Nov 15, 2018 HF has activated. */ +bool IsMagneticAnomalyEnabled(const Config &config, + const CBlockIndex *pindexPrev); +/** + * Also check if Nov 15, 2018 HF has activated, but with an API that isn't as + * safe. + */ +bool IsMagneticAnomalyEnabled(const Config &config, int64_t nMedianTimePast); + +#endif // BITCOIN_CONSENSUS_ACTIVATION_H diff --git a/src/consensus/activation.cpp b/src/consensus/activation.cpp new file mode 100644 --- /dev/null +++ b/src/consensus/activation.cpp @@ -0,0 +1,50 @@ +// Copyright (c) 2018 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "activation.h" + +#include "chain.h" +#include "chainparams.h" +#include "config.h" +#include "util.h" + +static bool IsUAHFenabled(const Config &config, int nHeight) { + return nHeight >= config.GetChainParams().GetConsensus().uahfHeight; +} + +bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev) { + if (pindexPrev == nullptr) { + return false; + } + + return IsUAHFenabled(config, pindexPrev->nHeight); +} + +static bool IsDAAEnabled(const Config &config, int nHeight) { + return nHeight >= config.GetChainParams().GetConsensus().daaHeight; +} + +bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev) { + if (pindexPrev == nullptr) { + return false; + } + + return IsDAAEnabled(config, pindexPrev->nHeight); +} + +bool IsMagneticAnomalyEnabled(const Config &config, int64_t nMedianTimePast) { + return nMedianTimePast >= gArgs.GetArg("-magneticanomalyactivationtime", + config.GetChainParams() + .GetConsensus() + .magneticAnomalyActivationTime); +} + +bool IsMagneticAnomalyEnabled(const Config &config, + const CBlockIndex *pindexPrev) { + if (pindexPrev == nullptr) { + return false; + } + + return IsMagneticAnomalyEnabled(config, pindexPrev->GetMedianTimePast()); +} diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -10,6 +10,7 @@ #include "chainparams.h" #include "coins.h" #include "config.h" +#include "consensus/activation.h" #include "consensus/consensus.h" #include "consensus/merkle.h" #include "consensus/validation.h" diff --git a/src/pow.cpp b/src/pow.cpp --- a/src/pow.cpp +++ b/src/pow.cpp @@ -10,11 +10,11 @@ #include "chain.h" #include "chainparams.h" #include "config.h" +#include "consensus/activation.h" #include "consensus/params.h" #include "primitives/block.h" #include "uint256.h" #include "util.h" -#include "validation.h" /** * Compute the next required proof of work using the legacy Bitcoin difficulty diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -437,16 +437,6 @@ /** Prune block files up to a given height */ void PruneBlockFilesManual(int nPruneUpToHeight); -/** Check if UAHF has activated. */ -bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev); - -/** Check if DAA HF has activated. */ -bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev); - -/** Check if Nov 15, 2018 HF has activated. */ -bool IsMagneticAnomalyEnabled(const Config &config, - const CBlockIndex *pindexPrev); - /** * (try to) add transaction to memory pool */ diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -13,6 +13,7 @@ #include "checkpoints.h" #include "checkqueue.h" #include "config.h" +#include "consensus/activation.h" #include "consensus/consensus.h" #include "consensus/merkle.h" #include "consensus/validation.h" @@ -540,47 +541,6 @@ return true; } -static bool IsUAHFenabled(const Config &config, int nHeight) { - return nHeight >= config.GetChainParams().GetConsensus().uahfHeight; -} - -bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev) { - if (pindexPrev == nullptr) { - return false; - } - - return IsUAHFenabled(config, pindexPrev->nHeight); -} - -static bool IsDAAEnabled(const Config &config, int nHeight) { - return nHeight >= config.GetChainParams().GetConsensus().daaHeight; -} - -bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev) { - if (pindexPrev == nullptr) { - return false; - } - - return IsDAAEnabled(config, pindexPrev->nHeight); -} - -static bool IsMagneticAnomalyEnabled(const Config &config, - int64_t nMedianTimePast) { - return nMedianTimePast >= gArgs.GetArg("-magneticanomalyactivationtime", - config.GetChainParams() - .GetConsensus() - .magneticAnomalyActivationTime); -} - -bool IsMagneticAnomalyEnabled(const Config &config, - const CBlockIndex *pindexPrev) { - if (pindexPrev == nullptr) { - return false; - } - - return IsMagneticAnomalyEnabled(config, pindexPrev->GetMedianTimePast()); -} - static bool IsMagneticAnomalyEnabledForCurrentBlock(const Config &config) { AssertLockHeld(cs_main); return IsMagneticAnomalyEnabled(config, chainActive.Tip());