diff --git a/src/deploymentstatus.h b/src/deploymentstatus.h index 84c5e54698..84ce46375e 100644 --- a/src/deploymentstatus.h +++ b/src/deploymentstatus.h @@ -52,4 +52,10 @@ inline bool DeploymentEnabled(const Consensus::Params& params, Consensus::Deploy return params.vDeployments[dep].nTimeout != 0; } +/** this function is convenient helper for DIP0003 because 'active' and 'enforced' are different statuses for DIP0003 */ +constexpr bool DeploymentDIP0003Enforced(const int nHeight, const Consensus::Params& params) +{ + return nHeight >= params.DIP0003EnforcementHeight; +} + #endif // BITCOIN_DEPLOYMENTSTATUS_H diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index ccef28e82c..73d72b2be6 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -1118,11 +1118,6 @@ bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, u return true; } -bool CDeterministicMNManager::IsDIP3Enforced(int nHeight) -{ - return nHeight >= Params().GetConsensus().DIP0003EnforcementHeight; -} - void CDeterministicMNManager::CleanupCache(int nHeight) { AssertLockHeld(cs); @@ -1612,7 +1607,7 @@ bool CheckProRegTx(const CTransaction& tx, gsl::not_null pin } } - if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) { + if (!DeploymentDIP0003Enforced(pindexPrev->nHeight, Params().GetConsensus())) { if (ptx.keyIDOwner != ptx.keyIDVoting) { return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same"); } @@ -1749,7 +1744,7 @@ bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null p } } - if (!deterministicMNManager->IsDIP3Enforced(pindexPrev->nHeight)) { + if (!DeploymentDIP0003Enforced(pindexPrev->nHeight, Params().GetConsensus())) { if (dmn->pdmnState->keyIDOwner != ptx.keyIDVoting) { return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-protx-key-not-same"); } diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 96241b463c..95bf68432f 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -622,8 +622,6 @@ public: // Test if given TX is a ProRegTx which also contains the collateral at index n static bool IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n); - bool IsDIP3Enforced(int nHeight); - bool MigrateDBIfNeeded(); bool MigrateDBIfNeeded2(); diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 7ad5cb32c9..e4ed643552 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1461,7 +1462,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co nCachedBlockHeight = pindex->nHeight; LogPrint(BCLog::GOBJECT, "CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight); - if (deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) { + if (DeploymentDIP0003Enforced(pindex->nHeight, Params().GetConsensus())) { RemoveInvalidVotes(); } diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 4f3ba6d65d..3acc3539e1 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -168,7 +169,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) { curSession = std::make_unique(params, blsWorker, dkgManager, dkgDebugManager, connman); - if (!deterministicMNManager->IsDIP3Enforced(pQuorumBaseBlockIndex->nHeight)) { + if (!DeploymentDIP0003Enforced(pQuorumBaseBlockIndex->nHeight, Params().GetConsensus())) { return false; } diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index fabf48b2f3..a4c9578037 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -7,10 +7,10 @@ #include #include -#include - #include #include +#include +#include #include #include #include @@ -162,7 +162,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni if (fInitialDownload) return; - if (!deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight)) + if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus())) return; if (!IsQuorumDKGEnabled(spork_manager)) return; diff --git a/src/masternode/node.cpp b/src/masternode/node.cpp index 84a2005293..055fa0430c 100644 --- a/src/masternode/node.cpp +++ b/src/masternode/node.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -68,7 +69,7 @@ void CActiveMasternodeManager::Init(const CBlockIndex* pindex) if (!fMasternodeMode) return; - if (!deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) return; + if (!DeploymentDIP0003Enforced(pindex->nHeight, Params().GetConsensus())) return; // Check that our local network configuration is correct if (!fListen && Params().RequireRoutableExternalIP()) { @@ -141,7 +142,7 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con if (!fMasternodeMode) return; - if (!deterministicMNManager->IsDIP3Enforced(pindexNew->nHeight)) return; + if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus())) return; if (state == MASTERNODE_READY) { auto oldMNList = deterministicMNManager->GetListForBlock(pindexNew->pprev); diff --git a/src/masternode/payments.cpp b/src/masternode/payments.cpp index 78d73b191d..2bf94d213d 100644 --- a/src/masternode/payments.cpp +++ b/src/masternode/payments.cpp @@ -98,7 +98,7 @@ [[nodiscard]] static bool IsTransactionValid(const CTransaction& txNew, const CBlockIndex* const pindexPrev, const CAmount blockSubsidy, const CAmount feeReward) { const int nBlockHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; - if (!deterministicMNManager->IsDIP3Enforced(nBlockHeight)) { + if (!DeploymentDIP0003Enforced(nBlockHeight, Params().GetConsensus())) { // can't verify historical blocks here return true; } diff --git a/src/test/block_reward_reallocation_tests.cpp b/src/test/block_reward_reallocation_tests.cpp index 95c7d47e73..3563a2d1aa 100644 --- a/src/test/block_reward_reallocation_tests.cpp +++ b/src/test/block_reward_reallocation_tests.cpp @@ -150,7 +150,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS CScript coinbasePubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; - BOOST_ASSERT(deterministicMNManager->IsDIP3Enforced(WITH_LOCK(cs_main, return m_node.chainman->ActiveChain().Height()))); + BOOST_ASSERT(DeploymentDIP0003Enforced(WITH_LOCK(cs_main, return m_node.chainman->ActiveChain().Height()), consensus_params)); // Register one MN CKey ownerKey;